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