TargetLibraryInfo: add strn?cat, strn?cpy, and strn?len
[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     "expm1f",
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     "round",
99     "roundf",
100     "roundl",
101     "sin",
102     "sinl",
103     "sinf",
104     "sinh",
105     "sinhl",
106     "sinhf",
107     "siprintf",
108     "sqrt",
109     "sqrtl",
110     "sqrtf",
111     "strcat",
112     "strcpy",
113     "strlen",
114     "strncat",
115     "strncpy",
116     "strnlen",
117     "tan",
118     "tanl",
119     "tanf",
120     "tanh",
121     "tanhl",
122     "tanhf",
123     "trunc",
124     "truncf",
125     "truncl",
126     "__cxa_atexit",
127     "__cxa_guard_abort",
128     "__cxa_guard_acquire",
129     "__cxa_guard_release"
130   };
131
132 /// initialize - Initialize the set of available library functions based on the
133 /// specified target triple.  This should be carefully written so that a missing
134 /// target triple gets a sane set of defaults.
135 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
136   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
137
138   
139   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
140   if (T.isMacOSX()) {
141     if (T.isMacOSXVersionLT(10, 5))
142       TLI.setUnavailable(LibFunc::memset_pattern16);
143   } else if (T.getOS() == Triple::IOS) {
144     if (T.isOSVersionLT(3, 0))
145       TLI.setUnavailable(LibFunc::memset_pattern16);
146   } else {
147     TLI.setUnavailable(LibFunc::memset_pattern16);
148   }
149
150   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
151       !T.isMacOSXVersionLT(10, 7)) {
152     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
153     // we don't care about) have two versions; on recent OSX, the one we want
154     // has a $UNIX2003 suffix. The two implementations are identical except
155     // for the return value in some edge cases.  However, we don't want to
156     // generate code that depends on the old symbols.
157     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
158     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
159   }
160
161   // iprintf and friends are only available on XCore and TCE.
162   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
163     TLI.setUnavailable(LibFunc::iprintf);
164     TLI.setUnavailable(LibFunc::siprintf);
165     TLI.setUnavailable(LibFunc::fiprintf);
166   }
167
168   if (T.getOS() == Triple::Win32) {
169     // Win32 does not support long double
170     TLI.setUnavailable(LibFunc::acosl);
171     TLI.setUnavailable(LibFunc::asinl);
172     TLI.setUnavailable(LibFunc::atanl);
173     TLI.setUnavailable(LibFunc::atan2l);
174     TLI.setUnavailable(LibFunc::ceill);
175     TLI.setUnavailable(LibFunc::copysignl);
176     TLI.setUnavailable(LibFunc::cosl);
177     TLI.setUnavailable(LibFunc::coshl);
178     TLI.setUnavailable(LibFunc::expl);
179     TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
180     TLI.setUnavailable(LibFunc::fabsl);
181     TLI.setUnavailable(LibFunc::floorl);
182     TLI.setUnavailable(LibFunc::fmodl);
183     TLI.setUnavailable(LibFunc::logl);
184     TLI.setUnavailable(LibFunc::powl);
185     TLI.setUnavailable(LibFunc::sinl);
186     TLI.setUnavailable(LibFunc::sinhl);
187     TLI.setUnavailable(LibFunc::sqrtl);
188     TLI.setUnavailable(LibFunc::tanl);
189     TLI.setUnavailable(LibFunc::tanhl);
190
191     // Win32 only has C89 math
192     TLI.setUnavailable(LibFunc::exp2);
193     TLI.setUnavailable(LibFunc::exp2f);
194     TLI.setUnavailable(LibFunc::exp2l);
195     TLI.setUnavailable(LibFunc::expm1);
196     TLI.setUnavailable(LibFunc::expm1f);
197     TLI.setUnavailable(LibFunc::expm1l);
198     TLI.setUnavailable(LibFunc::log2);
199     TLI.setUnavailable(LibFunc::log2f);
200     TLI.setUnavailable(LibFunc::log2l);
201     TLI.setUnavailable(LibFunc::log1p);
202     TLI.setUnavailable(LibFunc::log1pf);
203     TLI.setUnavailable(LibFunc::log1pl);
204     TLI.setUnavailable(LibFunc::nearbyint);
205     TLI.setUnavailable(LibFunc::nearbyintf);
206     TLI.setUnavailable(LibFunc::nearbyintl);
207     TLI.setUnavailable(LibFunc::rint);
208     TLI.setUnavailable(LibFunc::rintf);
209     TLI.setUnavailable(LibFunc::rintl);
210     TLI.setUnavailable(LibFunc::round);
211     TLI.setUnavailable(LibFunc::roundf);
212     TLI.setUnavailable(LibFunc::roundl);
213     TLI.setUnavailable(LibFunc::trunc);
214     TLI.setUnavailable(LibFunc::truncf);
215     TLI.setUnavailable(LibFunc::truncl);
216
217     // Win32 provides some C99 math with mangled names
218     TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
219
220     if (T.getArch() == Triple::x86) {
221       // Win32 on x86 implements single-precision math functions as macros
222       TLI.setUnavailable(LibFunc::acosf);
223       TLI.setUnavailable(LibFunc::asinf);
224       TLI.setUnavailable(LibFunc::atanf);
225       TLI.setUnavailable(LibFunc::atan2f);
226       TLI.setUnavailable(LibFunc::ceilf);
227       TLI.setUnavailable(LibFunc::copysignf);
228       TLI.setUnavailable(LibFunc::cosf);
229       TLI.setUnavailable(LibFunc::coshf);
230       TLI.setUnavailable(LibFunc::expf);
231       TLI.setUnavailable(LibFunc::floorf);
232       TLI.setUnavailable(LibFunc::fmodf);
233       TLI.setUnavailable(LibFunc::logf);
234       TLI.setUnavailable(LibFunc::powf);
235       TLI.setUnavailable(LibFunc::sinf);
236       TLI.setUnavailable(LibFunc::sinhf);
237       TLI.setUnavailable(LibFunc::sqrtf);
238       TLI.setUnavailable(LibFunc::tanf);
239       TLI.setUnavailable(LibFunc::tanhf);
240     }
241   }
242 }
243
244
245 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
246   // Default to everything being available.
247   memset(AvailableArray, -1, sizeof(AvailableArray));
248
249   initialize(*this, Triple());
250 }
251
252 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
253   // Default to everything being available.
254   memset(AvailableArray, -1, sizeof(AvailableArray));
255   
256   initialize(*this, T);
257 }
258
259 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
260   : ImmutablePass(ID) {
261   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
262   CustomNames = TLI.CustomNames;
263 }
264
265
266 /// disableAllFunctions - This disables all builtins, which is used for options
267 /// like -fno-builtin.
268 void TargetLibraryInfo::disableAllFunctions() {
269   memset(AvailableArray, 0, sizeof(AvailableArray));
270 }