Fix a crash in AVX2 when trying to broadcast a double into a 128-bit vector. There...
[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   };
118
119 /// initialize - Initialize the set of available library functions based on the
120 /// specified target triple.  This should be carefully written so that a missing
121 /// target triple gets a sane set of defaults.
122 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
123   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
124
125   
126   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
127   if (T.isMacOSX()) {
128     if (T.isMacOSXVersionLT(10, 5))
129       TLI.setUnavailable(LibFunc::memset_pattern16);
130   } else if (T.getOS() == Triple::IOS) {
131     if (T.isOSVersionLT(3, 0))
132       TLI.setUnavailable(LibFunc::memset_pattern16);
133   } else {
134     TLI.setUnavailable(LibFunc::memset_pattern16);
135   }
136
137   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
138       !T.isMacOSXVersionLT(10, 7)) {
139     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
140     // we don't care about) have two versions; on recent OSX, the one we want
141     // has a $UNIX2003 suffix. The two implementations are identical except
142     // for the return value in some edge cases.  However, we don't want to
143     // generate code that depends on the old symbols.
144     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
145     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
146   }
147
148   // iprintf and friends are only available on XCore and TCE.
149   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
150     TLI.setUnavailable(LibFunc::iprintf);
151     TLI.setUnavailable(LibFunc::siprintf);
152     TLI.setUnavailable(LibFunc::fiprintf);
153   }
154 }
155
156
157 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
158   // Default to everything being available.
159   memset(AvailableArray, -1, sizeof(AvailableArray));
160
161   initialize(*this, Triple());
162 }
163
164 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
165   // Default to everything being available.
166   memset(AvailableArray, -1, sizeof(AvailableArray));
167   
168   initialize(*this, T);
169 }
170
171 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
172   : ImmutablePass(ID) {
173   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
174   CustomNames = TLI.CustomNames;
175 }
176
177
178 /// disableAllFunctions - This disables all builtins, which is used for options
179 /// like -fno-builtin.
180 void TargetLibraryInfo::disableAllFunctions() {
181   memset(AvailableArray, 0, sizeof(AvailableArray));
182 }