0ab0d3123bde05f78c67b88ae89863a888c03d0a
[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     "siprintf",
88     "sin",
89     "sinl",
90     "sinf",
91     "sqrt",
92     "sqrtl",
93     "sqrtf",
94     "tan",
95     "tanl",
96     "tanf",
97     "tanh",
98     "tanhl",
99     "tanhf"
100   };
101
102 /// initialize - Initialize the set of available library functions based on the
103 /// specified target triple.  This should be carefully written so that a missing
104 /// target triple gets a sane set of defaults.
105 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
106   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
107
108   
109   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
110   if (T.isMacOSX()) {
111     if (T.isMacOSXVersionLT(10, 5))
112       TLI.setUnavailable(LibFunc::memset_pattern16);
113   } else if (T.getOS() == Triple::IOS) {
114     if (T.isOSVersionLT(3, 0))
115       TLI.setUnavailable(LibFunc::memset_pattern16);
116   } else {
117     TLI.setUnavailable(LibFunc::memset_pattern16);
118   }
119
120   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
121       !T.isMacOSXVersionLT(10, 7)) {
122     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
123     // we don't care about) have two versions; on recent OSX, the one we want
124     // has a $UNIX2003 suffix. The two implementations are identical except
125     // for the return value in some edge cases.  However, we don't want to
126     // generate code that depends on the old symbols.
127     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
128     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
129   }
130
131   // iprintf and friends are only available on XCore and TCE.
132   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
133     TLI.setUnavailable(LibFunc::iprintf);
134     TLI.setUnavailable(LibFunc::siprintf);
135     TLI.setUnavailable(LibFunc::fiprintf);
136   }
137 }
138
139
140 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
141   // Default to everything being available.
142   memset(AvailableArray, -1, sizeof(AvailableArray));
143
144   initialize(*this, Triple());
145 }
146
147 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
148   // Default to everything being available.
149   memset(AvailableArray, -1, sizeof(AvailableArray));
150   
151   initialize(*this, T);
152 }
153
154 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
155   : ImmutablePass(ID) {
156   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
157   CustomNames = TLI.CustomNames;
158 }
159
160
161 /// disableAllFunctions - This disables all builtins, which is used for options
162 /// like -fno-builtin.
163 void TargetLibraryInfo::disableAllFunctions() {
164   memset(AvailableArray, 0, sizeof(AvailableArray));
165 }