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 | |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 23 | void TargetLibraryInfo::anchor() { } |
| 24 | |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 25 | const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] = |
| 26 | { |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 27 | "__cxa_atexit", |
| 28 | "__cxa_guard_abort", |
| 29 | "__cxa_guard_acquire", |
| 30 | "__cxa_guard_release", |
| 31 | "__memcpy_chk", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 32 | "acos", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 33 | "acosf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 34 | "acosl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 35 | "asin", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 36 | "asinf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 37 | "asinl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 38 | "atan", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 39 | "atan2", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 40 | "atan2f", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 41 | "atan2l", |
| 42 | "atanf", |
| 43 | "atanl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 44 | "ceil", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 45 | "ceilf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 46 | "ceill", |
Owen Anderson | 243eb9e | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 47 | "copysign", |
| 48 | "copysignf", |
| 49 | "copysignl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 50 | "cos", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 51 | "cosf", |
| 52 | "cosh", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 53 | "coshf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 54 | "coshl", |
| 55 | "cosl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 56 | "exp", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 57 | "exp2", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 58 | "exp2f", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 59 | "exp2l", |
| 60 | "expf", |
| 61 | "expl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 62 | "expm1", |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 63 | "expm1f", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 64 | "expm1l", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 65 | "fabs", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 66 | "fabsf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 67 | "fabsl", |
Chad Rosier | 683e47b | 2011-11-30 01:51:49 +0000 | [diff] [blame] | 68 | "fiprintf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 69 | "floor", |
| 70 | "floorf", |
| 71 | "floorl", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 72 | "fmod", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 73 | "fmodf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 74 | "fmodl", |
Nuno Lopes | 8d32463 | 2012-07-24 21:00:36 +0000 | [diff] [blame] | 75 | "fputc", |
Chad Rosier | 683e47b | 2011-11-30 01:51:49 +0000 | [diff] [blame] | 76 | "fputs", |
| 77 | "fwrite", |
| 78 | "iprintf", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 79 | "log", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 80 | "log10", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 81 | "log10f", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 82 | "log10l", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 83 | "log1p", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 84 | "log1pf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 85 | "log1pl", |
| 86 | "log2", |
| 87 | "log2f", |
| 88 | "log2l", |
| 89 | "logf", |
| 90 | "logl", |
Nuno Lopes | 8d32463 | 2012-07-24 21:00:36 +0000 | [diff] [blame] | 91 | "memchr", |
| 92 | "memcmp", |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 93 | "memcpy", |
| 94 | "memmove", |
Chad Rosier | 683e47b | 2011-11-30 01:51:49 +0000 | [diff] [blame] | 95 | "memset", |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 96 | "memset_pattern16", |
Owen Anderson | 243eb9e | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 97 | "nearbyint", |
| 98 | "nearbyintf", |
| 99 | "nearbyintl", |
Chad Rosier | 8ff4115 | 2011-11-30 19:19:00 +0000 | [diff] [blame] | 100 | "pow", |
| 101 | "powf", |
| 102 | "powl", |
Nuno Lopes | 8d32463 | 2012-07-24 21:00:36 +0000 | [diff] [blame] | 103 | "putchar", |
| 104 | "puts", |
Owen Anderson | 243eb9e | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 105 | "rint", |
| 106 | "rintf", |
| 107 | "rintl", |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 108 | "round", |
| 109 | "roundf", |
| 110 | "roundl", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 111 | "sin", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 112 | "sinf", |
Chad Rosier | fbd828d | 2011-12-01 18:26:19 +0000 | [diff] [blame] | 113 | "sinh", |
Chad Rosier | fbd828d | 2011-12-01 18:26:19 +0000 | [diff] [blame] | 114 | "sinhf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 115 | "sinhl", |
| 116 | "sinl", |
Chad Rosier | fbd828d | 2011-12-01 18:26:19 +0000 | [diff] [blame] | 117 | "siprintf", |
Chad Rosier | 3d925d2 | 2011-11-29 23:57:10 +0000 | [diff] [blame] | 118 | "sqrt", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 119 | "sqrtf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 120 | "sqrtl", |
Nuno Lopes | 0841e63 | 2012-07-24 17:25:06 +0000 | [diff] [blame] | 121 | "strcat", |
Nuno Lopes | 8d32463 | 2012-07-24 21:00:36 +0000 | [diff] [blame] | 122 | "strchr", |
Nuno Lopes | 0841e63 | 2012-07-24 17:25:06 +0000 | [diff] [blame] | 123 | "strcpy", |
| 124 | "strlen", |
| 125 | "strncat", |
Nuno Lopes | 8d32463 | 2012-07-24 21:00:36 +0000 | [diff] [blame] | 126 | "strncmp", |
Nuno Lopes | 0841e63 | 2012-07-24 17:25:06 +0000 | [diff] [blame] | 127 | "strncpy", |
| 128 | "strnlen", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 129 | "tan", |
Chad Rosier | 32b6c59 | 2011-12-01 17:54:37 +0000 | [diff] [blame] | 130 | "tanf", |
| 131 | "tanh", |
Owen Anderson | 243eb9e | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 132 | "tanhf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 133 | "tanhl", |
| 134 | "tanl", |
Owen Anderson | 243eb9e | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 135 | "trunc", |
| 136 | "truncf", |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 137 | "truncl" |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 140 | /// initialize - Initialize the set of available library functions based on the |
| 141 | /// specified target triple. This should be carefully written so that a missing |
| 142 | /// target triple gets a sane set of defaults. |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 143 | static void initialize(TargetLibraryInfo &TLI, const Triple &T, |
| 144 | const char **StandardNames) { |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 145 | initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry()); |
| 146 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 147 | #ifndef NDEBUG |
| 148 | // Verify that the StandardNames array is in alphabetical order. |
| 149 | for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) { |
| 150 | if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0) |
| 151 | llvm_unreachable("TargetLibraryInfo function names must be sorted"); |
| 152 | } |
| 153 | #endif // !NDEBUG |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 154 | |
| 155 | // 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] | 156 | if (T.isMacOSX()) { |
| 157 | if (T.isMacOSXVersionLT(10, 5)) |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 158 | TLI.setUnavailable(LibFunc::memset_pattern16); |
| 159 | } else if (T.getOS() == Triple::IOS) { |
| 160 | if (T.isOSVersionLT(3, 0)) |
| 161 | TLI.setUnavailable(LibFunc::memset_pattern16); |
| 162 | } else { |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 163 | TLI.setUnavailable(LibFunc::memset_pattern16); |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 164 | } |
Richard Osborne | 3649824 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 165 | |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 166 | if (T.isMacOSX() && T.getArch() == Triple::x86 && |
| 167 | !T.isMacOSXVersionLT(10, 7)) { |
| 168 | // x86-32 OSX has a scheme where fwrite and fputs (and some other functions |
| 169 | // we don't care about) have two versions; on recent OSX, the one we want |
| 170 | // has a $UNIX2003 suffix. The two implementations are identical except |
| 171 | // for the return value in some edge cases. However, we don't want to |
| 172 | // generate code that depends on the old symbols. |
| 173 | TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003"); |
| 174 | TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003"); |
| 175 | } |
| 176 | |
Duncan Sands | 9fe8897 | 2011-06-09 11:11:45 +0000 | [diff] [blame] | 177 | // iprintf and friends are only available on XCore and TCE. |
| 178 | if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { |
Richard Osborne | 3649824 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 179 | TLI.setUnavailable(LibFunc::iprintf); |
Richard Osborne | 419454a | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 180 | TLI.setUnavailable(LibFunc::siprintf); |
Richard Osborne | 022708f | 2011-03-03 14:20:22 +0000 | [diff] [blame] | 181 | TLI.setUnavailable(LibFunc::fiprintf); |
Richard Osborne | 419454a | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 182 | } |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 183 | |
| 184 | if (T.getOS() == Triple::Win32) { |
| 185 | // Win32 does not support long double |
| 186 | TLI.setUnavailable(LibFunc::acosl); |
| 187 | TLI.setUnavailable(LibFunc::asinl); |
| 188 | TLI.setUnavailable(LibFunc::atanl); |
| 189 | TLI.setUnavailable(LibFunc::atan2l); |
| 190 | TLI.setUnavailable(LibFunc::ceill); |
| 191 | TLI.setUnavailable(LibFunc::copysignl); |
| 192 | TLI.setUnavailable(LibFunc::cosl); |
| 193 | TLI.setUnavailable(LibFunc::coshl); |
| 194 | TLI.setUnavailable(LibFunc::expl); |
| 195 | TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf |
| 196 | TLI.setUnavailable(LibFunc::fabsl); |
| 197 | TLI.setUnavailable(LibFunc::floorl); |
| 198 | TLI.setUnavailable(LibFunc::fmodl); |
| 199 | TLI.setUnavailable(LibFunc::logl); |
| 200 | TLI.setUnavailable(LibFunc::powl); |
| 201 | TLI.setUnavailable(LibFunc::sinl); |
| 202 | TLI.setUnavailable(LibFunc::sinhl); |
| 203 | TLI.setUnavailable(LibFunc::sqrtl); |
| 204 | TLI.setUnavailable(LibFunc::tanl); |
| 205 | TLI.setUnavailable(LibFunc::tanhl); |
| 206 | |
| 207 | // Win32 only has C89 math |
| 208 | TLI.setUnavailable(LibFunc::exp2); |
| 209 | TLI.setUnavailable(LibFunc::exp2f); |
| 210 | TLI.setUnavailable(LibFunc::exp2l); |
| 211 | TLI.setUnavailable(LibFunc::expm1); |
| 212 | TLI.setUnavailable(LibFunc::expm1f); |
| 213 | TLI.setUnavailable(LibFunc::expm1l); |
| 214 | TLI.setUnavailable(LibFunc::log2); |
| 215 | TLI.setUnavailable(LibFunc::log2f); |
| 216 | TLI.setUnavailable(LibFunc::log2l); |
| 217 | TLI.setUnavailable(LibFunc::log1p); |
| 218 | TLI.setUnavailable(LibFunc::log1pf); |
| 219 | TLI.setUnavailable(LibFunc::log1pl); |
| 220 | TLI.setUnavailable(LibFunc::nearbyint); |
| 221 | TLI.setUnavailable(LibFunc::nearbyintf); |
| 222 | TLI.setUnavailable(LibFunc::nearbyintl); |
| 223 | TLI.setUnavailable(LibFunc::rint); |
| 224 | TLI.setUnavailable(LibFunc::rintf); |
| 225 | TLI.setUnavailable(LibFunc::rintl); |
| 226 | TLI.setUnavailable(LibFunc::round); |
| 227 | TLI.setUnavailable(LibFunc::roundf); |
| 228 | TLI.setUnavailable(LibFunc::roundl); |
| 229 | TLI.setUnavailable(LibFunc::trunc); |
| 230 | TLI.setUnavailable(LibFunc::truncf); |
| 231 | TLI.setUnavailable(LibFunc::truncl); |
| 232 | |
| 233 | // Win32 provides some C99 math with mangled names |
| 234 | TLI.setAvailableWithName(LibFunc::copysign, "_copysign"); |
| 235 | |
| 236 | if (T.getArch() == Triple::x86) { |
| 237 | // Win32 on x86 implements single-precision math functions as macros |
| 238 | TLI.setUnavailable(LibFunc::acosf); |
| 239 | TLI.setUnavailable(LibFunc::asinf); |
| 240 | TLI.setUnavailable(LibFunc::atanf); |
| 241 | TLI.setUnavailable(LibFunc::atan2f); |
| 242 | TLI.setUnavailable(LibFunc::ceilf); |
| 243 | TLI.setUnavailable(LibFunc::copysignf); |
| 244 | TLI.setUnavailable(LibFunc::cosf); |
| 245 | TLI.setUnavailable(LibFunc::coshf); |
| 246 | TLI.setUnavailable(LibFunc::expf); |
| 247 | TLI.setUnavailable(LibFunc::floorf); |
| 248 | TLI.setUnavailable(LibFunc::fmodf); |
| 249 | TLI.setUnavailable(LibFunc::logf); |
| 250 | TLI.setUnavailable(LibFunc::powf); |
| 251 | TLI.setUnavailable(LibFunc::sinf); |
| 252 | TLI.setUnavailable(LibFunc::sinhf); |
| 253 | TLI.setUnavailable(LibFunc::sqrtf); |
| 254 | TLI.setUnavailable(LibFunc::tanf); |
| 255 | TLI.setUnavailable(LibFunc::tanhf); |
| 256 | } |
| 257 | } |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) { |
| 262 | // Default to everything being available. |
| 263 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 264 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 265 | initialize(*this, Triple(), StandardNames); |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) { |
| 269 | // Default to everything being available. |
| 270 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 271 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 272 | initialize(*this, T, StandardNames); |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 273 | } |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 274 | |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 275 | TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI) |
| 276 | : ImmutablePass(ID) { |
| 277 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 278 | CustomNames = TLI.CustomNames; |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame^] | 281 | bool TargetLibraryInfo::getLibFunc(StringRef funcName, |
| 282 | LibFunc::Func &F) const { |
| 283 | const char **Start = &StandardNames[0]; |
| 284 | const char **End = &StandardNames[LibFunc::NumLibFuncs]; |
| 285 | const char **I = std::lower_bound(Start, End, funcName); |
| 286 | if (I != End && *I == funcName) { |
| 287 | F = (LibFunc::Func)(I - Start); |
| 288 | return true; |
| 289 | } |
| 290 | return false; |
| 291 | } |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 292 | |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 293 | /// disableAllFunctions - This disables all builtins, which is used for options |
| 294 | /// like -fno-builtin. |
| 295 | void TargetLibraryInfo::disableAllFunctions() { |
| 296 | memset(AvailableArray, 0, sizeof(AvailableArray)); |
| 297 | } |