Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 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 | |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 23 | const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] = |
| 24 | { |
| 25 | "memset", |
| 26 | "memcpy", |
| 27 | "memmove", |
| 28 | "memset_pattern16", |
| 29 | "iprintf", |
| 30 | "siprintf", |
| 31 | "fiprintf", |
| 32 | "fwrite", |
| 33 | "fputs" |
| 34 | }; |
| 35 | |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 36 | /// initialize - Initialize the set of available library functions based on the |
| 37 | /// specified target triple. This should be carefully written so that a missing |
| 38 | /// target triple gets a sane set of defaults. |
| 39 | static void initialize(TargetLibraryInfo &TLI, const Triple &T) { |
| 40 | initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry()); |
| 41 | |
| 42 | |
| 43 | // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later. |
Daniel Dunbar | 558692f | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 44 | if (T.isMacOSX()) { |
| 45 | if (T.isMacOSXVersionLT(10, 5)) |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 46 | TLI.setUnavailable(LibFunc::memset_pattern16); |
| 47 | } else if (T.getOS() == Triple::IOS) { |
| 48 | if (T.isOSVersionLT(3, 0)) |
| 49 | TLI.setUnavailable(LibFunc::memset_pattern16); |
| 50 | } else { |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 51 | TLI.setUnavailable(LibFunc::memset_pattern16); |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 52 | } |
Richard Osborne | 3649824 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 53 | |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 54 | if (T.isMacOSX() && T.getArch() == Triple::x86 && |
| 55 | !T.isMacOSXVersionLT(10, 7)) { |
| 56 | // x86-32 OSX has a scheme where fwrite and fputs (and some other functions |
| 57 | // we don't care about) have two versions; on recent OSX, the one we want |
| 58 | // has a $UNIX2003 suffix. The two implementations are identical except |
| 59 | // for the return value in some edge cases. However, we don't want to |
| 60 | // generate code that depends on the old symbols. |
| 61 | TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003"); |
| 62 | TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003"); |
| 63 | } |
| 64 | |
Duncan Sands | 9fe8897 | 2011-06-09 11:11:45 +0000 | [diff] [blame] | 65 | // iprintf and friends are only available on XCore and TCE. |
| 66 | if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { |
Richard Osborne | 3649824 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 67 | TLI.setUnavailable(LibFunc::iprintf); |
Richard Osborne | 419454a | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 68 | TLI.setUnavailable(LibFunc::siprintf); |
Richard Osborne | 022708f | 2011-03-03 14:20:22 +0000 | [diff] [blame] | 69 | TLI.setUnavailable(LibFunc::fiprintf); |
Richard Osborne | 419454a | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 70 | } |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
| 74 | TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) { |
| 75 | // Default to everything being available. |
| 76 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 77 | |
| 78 | initialize(*this, Triple()); |
| 79 | } |
| 80 | |
| 81 | TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) { |
| 82 | // Default to everything being available. |
| 83 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 84 | |
| 85 | initialize(*this, T); |
| 86 | } |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 88 | TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI) |
| 89 | : ImmutablePass(ID) { |
| 90 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 91 | CustomNames = TLI.CustomNames; |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 95 | /// disableAllFunctions - This disables all builtins, which is used for options |
| 96 | /// like -fno-builtin. |
| 97 | void TargetLibraryInfo::disableAllFunctions() { |
| 98 | memset(AvailableArray, 0, sizeof(AvailableArray)); |
| 99 | } |