Add missing functions.
[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 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
24   {
25     "acos",
26     "acosl",
27     "acosf",
28     "asin",
29     "asinl",
30     "asinf",
31     "atan",
32     "atanl",
33     "atanf",
34     "atan2",
35     "atan2l",
36     "atan2f",
37     "ceil",
38     "ceill",
39     "ceilf",
40     "cos",
41     "cosl",
42     "cosf",
43     "cosh",
44     "coshl",
45     "coshf",
46     "exp",
47     "expl",
48     "expf",
49     "exp2",
50     "exp2l",
51     "exp2f",
52     "expm1",
53     "expm1l",
54     "expl1f",
55     "fabs",
56     "fabsl",
57     "fabsf",
58     "floor",
59     "floorl",
60     "floorf",
61     "fiprintf",
62     "fmod",
63     "fmodl",
64     "fmodf",
65     "fputs",
66     "fwrite",
67     "iprintf",
68     "log",
69     "logl",
70     "logf",
71     "log2",
72     "log2l",
73     "log2f",
74     "log10",
75     "log10l",
76     "log10f",
77     "log1p",
78     "log1pl",
79     "log1pf",
80     "memcpy",
81     "memmove",
82     "memset",
83     "memset_pattern16",
84     "pow",
85     "powf",
86     "powl",
87     "sin",
88     "sinl",
89     "sinf",
90     "sinh",
91     "sinhl",
92     "sinhf",
93     "siprintf",
94     "sqrt",
95     "sqrtl",
96     "sqrtf",
97     "tan",
98     "tanl",
99     "tanf",
100     "tanh",
101     "tanhl",
102     "tanhf"
103   };
104
105 /// initialize - Initialize the set of available library functions based on the
106 /// specified target triple.  This should be carefully written so that a missing
107 /// target triple gets a sane set of defaults.
108 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
109   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
110
111   
112   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
113   if (T.isMacOSX()) {
114     if (T.isMacOSXVersionLT(10, 5))
115       TLI.setUnavailable(LibFunc::memset_pattern16);
116   } else if (T.getOS() == Triple::IOS) {
117     if (T.isOSVersionLT(3, 0))
118       TLI.setUnavailable(LibFunc::memset_pattern16);
119   } else {
120     TLI.setUnavailable(LibFunc::memset_pattern16);
121   }
122
123   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
124       !T.isMacOSXVersionLT(10, 7)) {
125     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
126     // we don't care about) have two versions; on recent OSX, the one we want
127     // has a $UNIX2003 suffix. The two implementations are identical except
128     // for the return value in some edge cases.  However, we don't want to
129     // generate code that depends on the old symbols.
130     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
131     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
132   }
133
134   // iprintf and friends are only available on XCore and TCE.
135   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
136     TLI.setUnavailable(LibFunc::iprintf);
137     TLI.setUnavailable(LibFunc::siprintf);
138     TLI.setUnavailable(LibFunc::fiprintf);
139   }
140 }
141
142
143 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
144   // Default to everything being available.
145   memset(AvailableArray, -1, sizeof(AvailableArray));
146
147   initialize(*this, Triple());
148 }
149
150 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
151   // Default to everything being available.
152   memset(AvailableArray, -1, sizeof(AvailableArray));
153   
154   initialize(*this, T);
155 }
156
157 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
158   : ImmutablePass(ID) {
159   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
160   CustomNames = TLI.CustomNames;
161 }
162
163
164 /// disableAllFunctions - This disables all builtins, which is used for options
165 /// like -fno-builtin.
166 void TargetLibraryInfo::disableAllFunctions() {
167   memset(AvailableArray, 0, sizeof(AvailableArray));
168 }