Fix undefined behavior in the Mips backend.
[oota-llvm.git] / lib / Target / TargetLibraryInfo.cpp
1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the TargetLibraryInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetLibraryInfo.h"
15 #include "llvm/ADT/Triple.h"
16 using namespace llvm;
17
18 // Register the default implementation.
19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20                 "Target Library Information", false, true)
21 char TargetLibraryInfo::ID = 0;
22
23 void TargetLibraryInfo::anchor() { }
24
25 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
26   {
27     "acos",
28     "acosl",
29     "acosf",
30     "asin",
31     "asinl",
32     "asinf",
33     "atan",
34     "atanl",
35     "atanf",
36     "atan2",
37     "atan2l",
38     "atan2f",
39     "ceil",
40     "ceill",
41     "ceilf",
42     "copysign",
43     "copysignf",
44     "copysignl",
45     "cos",
46     "cosl",
47     "cosf",
48     "cosh",
49     "coshl",
50     "coshf",
51     "exp",
52     "expl",
53     "expf",
54     "exp2",
55     "exp2l",
56     "exp2f",
57     "expm1",
58     "expm1l",
59     "expl1f",
60     "fabs",
61     "fabsl",
62     "fabsf",
63     "floor",
64     "floorl",
65     "floorf",
66     "fiprintf",
67     "fmod",
68     "fmodl",
69     "fmodf",
70     "fputs",
71     "fwrite",
72     "iprintf",
73     "log",
74     "logl",
75     "logf",
76     "log2",
77     "log2l",
78     "log2f",
79     "log10",
80     "log10l",
81     "log10f",
82     "log1p",
83     "log1pl",
84     "log1pf",
85     "memcpy",
86     "memmove",
87     "memset",
88     "memset_pattern16",
89     "nearbyint",
90     "nearbyintf",
91     "nearbyintl",
92     "pow",
93     "powf",
94     "powl",
95     "rint",
96     "rintf",
97     "rintl",
98     "sin",
99     "sinl",
100     "sinf",
101     "sinh",
102     "sinhl",
103     "sinhf",
104     "siprintf",
105     "sqrt",
106     "sqrtl",
107     "sqrtf",
108     "tan",
109     "tanl",
110     "tanf",
111     "tanh",
112     "tanhl",
113     "tanhf",
114     "trunc",
115     "truncf",
116     "truncl",
117     "__cxa_atexit",
118     "__cxa_guard_abort",
119     "__cxa_guard_acquire",
120     "__cxa_guard_release"
121   };
122
123 /// initialize - Initialize the set of available library functions based on the
124 /// specified target triple.  This should be carefully written so that a missing
125 /// target triple gets a sane set of defaults.
126 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
127   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
128
129   
130   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
131   if (T.isMacOSX()) {
132     if (T.isMacOSXVersionLT(10, 5))
133       TLI.setUnavailable(LibFunc::memset_pattern16);
134   } else if (T.getOS() == Triple::IOS) {
135     if (T.isOSVersionLT(3, 0))
136       TLI.setUnavailable(LibFunc::memset_pattern16);
137   } else {
138     TLI.setUnavailable(LibFunc::memset_pattern16);
139   }
140
141   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
142       !T.isMacOSXVersionLT(10, 7)) {
143     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
144     // we don't care about) have two versions; on recent OSX, the one we want
145     // has a $UNIX2003 suffix. The two implementations are identical except
146     // for the return value in some edge cases.  However, we don't want to
147     // generate code that depends on the old symbols.
148     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
149     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
150   }
151
152   // iprintf and friends are only available on XCore and TCE.
153   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
154     TLI.setUnavailable(LibFunc::iprintf);
155     TLI.setUnavailable(LibFunc::siprintf);
156     TLI.setUnavailable(LibFunc::fiprintf);
157   }
158 }
159
160
161 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
162   // Default to everything being available.
163   memset(AvailableArray, -1, sizeof(AvailableArray));
164
165   initialize(*this, Triple());
166 }
167
168 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
169   // Default to everything being available.
170   memset(AvailableArray, -1, sizeof(AvailableArray));
171   
172   initialize(*this, T);
173 }
174
175 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
176   : ImmutablePass(ID) {
177   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
178   CustomNames = TLI.CustomNames;
179 }
180
181
182 /// disableAllFunctions - This disables all builtins, which is used for options
183 /// like -fno-builtin.
184 void TargetLibraryInfo::disableAllFunctions() {
185   memset(AvailableArray, 0, sizeof(AvailableArray));
186 }