1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetLibraryInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetLibraryInfo.h"
15 #include "llvm/ADT/Triple.h"
18 // Register the default implementation.
19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20 "Target Library Information", false, true)
21 char TargetLibraryInfo::ID = 0;
23 void TargetLibraryInfo::anchor() { }
25 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
128 "__cxa_guard_acquire",
129 "__cxa_guard_release"
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());
139 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
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);
147 TLI.setUnavailable(LibFunc::memset_pattern16);
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");
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);
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);
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);
217 // Win32 provides some C99 math with mangled names
218 TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
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);
245 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
246 // Default to everything being available.
247 memset(AvailableArray, -1, sizeof(AvailableArray));
249 initialize(*this, Triple());
252 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
253 // Default to everything being available.
254 memset(AvailableArray, -1, sizeof(AvailableArray));
256 initialize(*this, T);
259 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
260 : ImmutablePass(ID) {
261 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
262 CustomNames = TLI.CustomNames;
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));