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] =
29 "__cxa_guard_acquire",
30 "__cxa_guard_release",
158 /// initialize - Initialize the set of available library functions based on the
159 /// specified target triple. This should be carefully written so that a missing
160 /// target triple gets a sane set of defaults.
161 static void initialize(TargetLibraryInfo &TLI, const Triple &T,
162 const char **StandardNames) {
163 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
166 // Verify that the StandardNames array is in alphabetical order.
167 for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) {
168 if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0)
169 llvm_unreachable("TargetLibraryInfo function names must be sorted");
173 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
175 if (T.isMacOSXVersionLT(10, 5))
176 TLI.setUnavailable(LibFunc::memset_pattern16);
177 } else if (T.getOS() == Triple::IOS) {
178 if (T.isOSVersionLT(3, 0))
179 TLI.setUnavailable(LibFunc::memset_pattern16);
181 TLI.setUnavailable(LibFunc::memset_pattern16);
184 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
185 !T.isMacOSXVersionLT(10, 7)) {
186 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
187 // we don't care about) have two versions; on recent OSX, the one we want
188 // has a $UNIX2003 suffix. The two implementations are identical except
189 // for the return value in some edge cases. However, we don't want to
190 // generate code that depends on the old symbols.
191 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
192 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
195 // iprintf and friends are only available on XCore and TCE.
196 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
197 TLI.setUnavailable(LibFunc::iprintf);
198 TLI.setUnavailable(LibFunc::siprintf);
199 TLI.setUnavailable(LibFunc::fiprintf);
202 if (T.getOS() == Triple::Win32) {
203 // Win32 does not support long double
204 TLI.setUnavailable(LibFunc::acosl);
205 TLI.setUnavailable(LibFunc::asinl);
206 TLI.setUnavailable(LibFunc::atanl);
207 TLI.setUnavailable(LibFunc::atan2l);
208 TLI.setUnavailable(LibFunc::ceill);
209 TLI.setUnavailable(LibFunc::copysignl);
210 TLI.setUnavailable(LibFunc::cosl);
211 TLI.setUnavailable(LibFunc::coshl);
212 TLI.setUnavailable(LibFunc::expl);
213 TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
214 TLI.setUnavailable(LibFunc::fabsl);
215 TLI.setUnavailable(LibFunc::floorl);
216 TLI.setUnavailable(LibFunc::fmodl);
217 TLI.setUnavailable(LibFunc::logl);
218 TLI.setUnavailable(LibFunc::powl);
219 TLI.setUnavailable(LibFunc::sinl);
220 TLI.setUnavailable(LibFunc::sinhl);
221 TLI.setUnavailable(LibFunc::sqrtl);
222 TLI.setUnavailable(LibFunc::tanl);
223 TLI.setUnavailable(LibFunc::tanhl);
225 // Win32 only has C89 math
226 TLI.setUnavailable(LibFunc::acosh);
227 TLI.setUnavailable(LibFunc::acoshf);
228 TLI.setUnavailable(LibFunc::acoshl);
229 TLI.setUnavailable(LibFunc::asinh);
230 TLI.setUnavailable(LibFunc::asinhf);
231 TLI.setUnavailable(LibFunc::asinhl);
232 TLI.setUnavailable(LibFunc::atanh);
233 TLI.setUnavailable(LibFunc::atanhf);
234 TLI.setUnavailable(LibFunc::atanhl);
235 TLI.setUnavailable(LibFunc::cbrt);
236 TLI.setUnavailable(LibFunc::cbrtf);
237 TLI.setUnavailable(LibFunc::cbrtl);
238 TLI.setUnavailable(LibFunc::exp10);
239 TLI.setUnavailable(LibFunc::exp10f);
240 TLI.setUnavailable(LibFunc::exp10l);
241 TLI.setUnavailable(LibFunc::exp2);
242 TLI.setUnavailable(LibFunc::exp2f);
243 TLI.setUnavailable(LibFunc::exp2l);
244 TLI.setUnavailable(LibFunc::expm1);
245 TLI.setUnavailable(LibFunc::expm1f);
246 TLI.setUnavailable(LibFunc::expm1l);
247 TLI.setUnavailable(LibFunc::log2);
248 TLI.setUnavailable(LibFunc::log2f);
249 TLI.setUnavailable(LibFunc::log2l);
250 TLI.setUnavailable(LibFunc::log1p);
251 TLI.setUnavailable(LibFunc::log1pf);
252 TLI.setUnavailable(LibFunc::log1pl);
253 TLI.setUnavailable(LibFunc::logb);
254 TLI.setUnavailable(LibFunc::logbf);
255 TLI.setUnavailable(LibFunc::logbl);
256 TLI.setUnavailable(LibFunc::nearbyint);
257 TLI.setUnavailable(LibFunc::nearbyintf);
258 TLI.setUnavailable(LibFunc::nearbyintl);
259 TLI.setUnavailable(LibFunc::rint);
260 TLI.setUnavailable(LibFunc::rintf);
261 TLI.setUnavailable(LibFunc::rintl);
262 TLI.setUnavailable(LibFunc::round);
263 TLI.setUnavailable(LibFunc::roundf);
264 TLI.setUnavailable(LibFunc::roundl);
265 TLI.setUnavailable(LibFunc::trunc);
266 TLI.setUnavailable(LibFunc::truncf);
267 TLI.setUnavailable(LibFunc::truncl);
269 // Win32 provides some C99 math with mangled names
270 TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
272 if (T.getArch() == Triple::x86) {
273 // Win32 on x86 implements single-precision math functions as macros
274 TLI.setUnavailable(LibFunc::acosf);
275 TLI.setUnavailable(LibFunc::asinf);
276 TLI.setUnavailable(LibFunc::atanf);
277 TLI.setUnavailable(LibFunc::atan2f);
278 TLI.setUnavailable(LibFunc::ceilf);
279 TLI.setUnavailable(LibFunc::copysignf);
280 TLI.setUnavailable(LibFunc::cosf);
281 TLI.setUnavailable(LibFunc::coshf);
282 TLI.setUnavailable(LibFunc::expf);
283 TLI.setUnavailable(LibFunc::floorf);
284 TLI.setUnavailable(LibFunc::fmodf);
285 TLI.setUnavailable(LibFunc::logf);
286 TLI.setUnavailable(LibFunc::powf);
287 TLI.setUnavailable(LibFunc::sinf);
288 TLI.setUnavailable(LibFunc::sinhf);
289 TLI.setUnavailable(LibFunc::sqrtf);
290 TLI.setUnavailable(LibFunc::tanf);
291 TLI.setUnavailable(LibFunc::tanhf);
297 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
298 // Default to everything being available.
299 memset(AvailableArray, -1, sizeof(AvailableArray));
301 initialize(*this, Triple(), StandardNames);
304 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
305 // Default to everything being available.
306 memset(AvailableArray, -1, sizeof(AvailableArray));
308 initialize(*this, T, StandardNames);
311 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
312 : ImmutablePass(ID) {
313 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
314 CustomNames = TLI.CustomNames;
317 bool TargetLibraryInfo::getLibFunc(StringRef funcName,
318 LibFunc::Func &F) const {
319 const char **Start = &StandardNames[0];
320 const char **End = &StandardNames[LibFunc::NumLibFuncs];
321 const char **I = std::lower_bound(Start, End, funcName);
322 if (I != End && *I == funcName) {
323 F = (LibFunc::Func)(I - Start);
329 /// disableAllFunctions - This disables all builtins, which is used for options
330 /// like -fno-builtin.
331 void TargetLibraryInfo::disableAllFunctions() {
332 memset(AvailableArray, 0, sizeof(AvailableArray));