Chris Lattner | 0e125bb | 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 | |
Chandler Carruth | 62d4215 | 2015-01-15 02:16:27 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Triple.h" |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 16 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 17 | using namespace llvm; |
| 18 | |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 19 | static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary( |
| 20 | "vector-library", cl::Hidden, cl::desc("Vector functions library"), |
| 21 | cl::init(TargetLibraryInfoImpl::NoLibrary), |
| 22 | cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", |
| 23 | "No vector functions library"), |
| 24 | clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", |
| 25 | "Accelerate framework"), |
| 26 | clEnumValEnd)); |
| 27 | |
Benjamin Kramer | 57a3d08 | 2015-03-08 16:07:39 +0000 | [diff] [blame] | 28 | const char *const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { |
Jan Wen Voung | cd3d25a | 2015-03-03 23:41:58 +0000 | [diff] [blame] | 29 | #define TLI_DEFINE_STRING |
| 30 | #include "llvm/Analysis/TargetLibraryInfo.def" |
Benjamin Kramer | 57a3d08 | 2015-03-08 16:07:39 +0000 | [diff] [blame] | 31 | }; |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 32 | |
Bob Wilson | d8d92d9 | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 33 | static bool hasSinCosPiStret(const Triple &T) { |
| 34 | // Only Darwin variants have _stret versions of combined trig functions. |
Bob Wilson | 9868d71 | 2014-10-09 05:43:30 +0000 | [diff] [blame] | 35 | if (!T.isOSDarwin()) |
Bob Wilson | d8d92d9 | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 36 | return false; |
| 37 | |
| 38 | // The ABI is rather complicated on x86, so don't do anything special there. |
| 39 | if (T.getArch() == Triple::x86) |
| 40 | return false; |
| 41 | |
| 42 | if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) |
| 43 | return false; |
| 44 | |
Bob Wilson | 9868d71 | 2014-10-09 05:43:30 +0000 | [diff] [blame] | 45 | if (T.isiOS() && T.isOSVersionLT(7, 0)) |
Bob Wilson | d8d92d9 | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 46 | return false; |
| 47 | |
| 48 | return true; |
| 49 | } |
| 50 | |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 51 | /// initialize - Initialize the set of available library functions based on the |
| 52 | /// specified target triple. This should be carefully written so that a missing |
| 53 | /// target triple gets a sane set of defaults. |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 54 | static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, |
Craig Topper | e30b8ca | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 55 | ArrayRef<const char *> StandardNames) { |
Bob Wilson | c740e3f | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 56 | // Verify that the StandardNames array is in alphabetical order. |
Craig Topper | e30b8ca | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 57 | assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), |
| 58 | [](const char *LHS, const char *RHS) { |
| 59 | return strcmp(LHS, RHS) < 0; |
| 60 | }) && |
| 61 | "TargetLibraryInfoImpl function names must be sorted"); |
Tom Stellard | 36a0318 | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 62 | |
Nicolai Hahnle | 78fd4f0 | 2015-12-15 17:24:15 +0000 | [diff] [blame] | 63 | if (T.getArch() == Triple::r600 || |
| 64 | T.getArch() == Triple::amdgcn) { |
| 65 | TLI.setUnavailable(LibFunc::ldexp); |
| 66 | TLI.setUnavailable(LibFunc::ldexpf); |
| 67 | TLI.setUnavailable(LibFunc::ldexpl); |
| 68 | } |
| 69 | |
Tom Stellard | d00a923 | 2015-01-07 01:17:37 +0000 | [diff] [blame] | 70 | // There are no library implementations of mempcy and memset for AMD gpus and |
Tom Stellard | 36a0318 | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 71 | // these can be difficult to lower in the backend. |
Tom Stellard | d00a923 | 2015-01-07 01:17:37 +0000 | [diff] [blame] | 72 | if (T.getArch() == Triple::r600 || |
Dan Gohman | 0553299 | 2016-01-19 14:49:23 +0000 | [diff] [blame] | 73 | T.getArch() == Triple::amdgcn) { |
Tom Stellard | 36a0318 | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 74 | TLI.setUnavailable(LibFunc::memcpy); |
| 75 | TLI.setUnavailable(LibFunc::memset); |
| 76 | TLI.setUnavailable(LibFunc::memset_pattern16); |
| 77 | return; |
| 78 | } |
| 79 | |
Nico Weber | ad15692 | 2014-03-07 18:08:54 +0000 | [diff] [blame] | 80 | // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. |
Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 81 | // All versions of watchOS support it. |
Daniel Dunbar | cd01ed5 | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 82 | if (T.isMacOSX()) { |
| 83 | if (T.isMacOSXVersionLT(10, 5)) |
Daniel Dunbar | 9483bb6 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 84 | TLI.setUnavailable(LibFunc::memset_pattern16); |
Cameron Esfahani | 943908b | 2013-08-29 20:23:14 +0000 | [diff] [blame] | 85 | } else if (T.isiOS()) { |
Daniel Dunbar | 9483bb6 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 86 | if (T.isOSVersionLT(3, 0)) |
| 87 | TLI.setUnavailable(LibFunc::memset_pattern16); |
Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 88 | } else if (!T.isWatchOS()) { |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 89 | TLI.setUnavailable(LibFunc::memset_pattern16); |
Daniel Dunbar | 9483bb6 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 90 | } |
Richard Osborne | 815de53 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 91 | |
Bob Wilson | d8d92d9 | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 92 | if (!hasSinCosPiStret(T)) { |
| 93 | TLI.setUnavailable(LibFunc::sinpi); |
| 94 | TLI.setUnavailable(LibFunc::sinpif); |
| 95 | TLI.setUnavailable(LibFunc::cospi); |
| 96 | TLI.setUnavailable(LibFunc::cospif); |
| 97 | TLI.setUnavailable(LibFunc::sincospi_stret); |
Tim Northover | 103e648 | 2014-02-04 16:28:20 +0000 | [diff] [blame] | 98 | TLI.setUnavailable(LibFunc::sincospif_stret); |
Bob Wilson | d8d92d9 | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 101 | if (T.isMacOSX() && T.getArch() == Triple::x86 && |
| 102 | !T.isMacOSXVersionLT(10, 7)) { |
| 103 | // x86-32 OSX has a scheme where fwrite and fputs (and some other functions |
| 104 | // we don't care about) have two versions; on recent OSX, the one we want |
| 105 | // has a $UNIX2003 suffix. The two implementations are identical except |
| 106 | // for the return value in some edge cases. However, we don't want to |
| 107 | // generate code that depends on the old symbols. |
| 108 | TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003"); |
| 109 | TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003"); |
| 110 | } |
| 111 | |
Duncan Sands | eeb50c8 | 2011-06-09 11:11:45 +0000 | [diff] [blame] | 112 | // iprintf and friends are only available on XCore and TCE. |
| 113 | if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { |
Richard Osborne | 815de53 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 114 | TLI.setUnavailable(LibFunc::iprintf); |
Richard Osborne | 2dfb888 | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 115 | TLI.setUnavailable(LibFunc::siprintf); |
Richard Osborne | af52c52 | 2011-03-03 14:20:22 +0000 | [diff] [blame] | 116 | TLI.setUnavailable(LibFunc::fiprintf); |
Richard Osborne | 2dfb888 | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 117 | } |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 118 | |
Saleem Abdulrasool | 8dc8fb1 | 2014-07-24 22:09:06 +0000 | [diff] [blame] | 119 | if (T.isOSWindows() && !T.isOSCygMing()) { |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 120 | // Win32 does not support long double |
| 121 | TLI.setUnavailable(LibFunc::acosl); |
| 122 | TLI.setUnavailable(LibFunc::asinl); |
| 123 | TLI.setUnavailable(LibFunc::atanl); |
| 124 | TLI.setUnavailable(LibFunc::atan2l); |
| 125 | TLI.setUnavailable(LibFunc::ceill); |
| 126 | TLI.setUnavailable(LibFunc::copysignl); |
| 127 | TLI.setUnavailable(LibFunc::cosl); |
| 128 | TLI.setUnavailable(LibFunc::coshl); |
| 129 | TLI.setUnavailable(LibFunc::expl); |
| 130 | TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf |
| 131 | TLI.setUnavailable(LibFunc::fabsl); |
| 132 | TLI.setUnavailable(LibFunc::floorl); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 133 | TLI.setUnavailable(LibFunc::fmaxl); |
| 134 | TLI.setUnavailable(LibFunc::fminl); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 135 | TLI.setUnavailable(LibFunc::fmodl); |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 136 | TLI.setUnavailable(LibFunc::frexpl); |
Benjamin Kramer | 34f460e | 2014-02-04 20:27:23 +0000 | [diff] [blame] | 137 | TLI.setUnavailable(LibFunc::ldexpf); |
| 138 | TLI.setUnavailable(LibFunc::ldexpl); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 139 | TLI.setUnavailable(LibFunc::logl); |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 140 | TLI.setUnavailable(LibFunc::modfl); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 141 | TLI.setUnavailable(LibFunc::powl); |
| 142 | TLI.setUnavailable(LibFunc::sinl); |
| 143 | TLI.setUnavailable(LibFunc::sinhl); |
| 144 | TLI.setUnavailable(LibFunc::sqrtl); |
| 145 | TLI.setUnavailable(LibFunc::tanl); |
| 146 | TLI.setUnavailable(LibFunc::tanhl); |
| 147 | |
| 148 | // Win32 only has C89 math |
Chad Rosier | 7fb0cd2 | 2012-08-21 23:28:56 +0000 | [diff] [blame] | 149 | TLI.setUnavailable(LibFunc::acosh); |
| 150 | TLI.setUnavailable(LibFunc::acoshf); |
| 151 | TLI.setUnavailable(LibFunc::acoshl); |
| 152 | TLI.setUnavailable(LibFunc::asinh); |
| 153 | TLI.setUnavailable(LibFunc::asinhf); |
| 154 | TLI.setUnavailable(LibFunc::asinhl); |
| 155 | TLI.setUnavailable(LibFunc::atanh); |
| 156 | TLI.setUnavailable(LibFunc::atanhf); |
| 157 | TLI.setUnavailable(LibFunc::atanhl); |
| 158 | TLI.setUnavailable(LibFunc::cbrt); |
| 159 | TLI.setUnavailable(LibFunc::cbrtf); |
| 160 | TLI.setUnavailable(LibFunc::cbrtl); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 161 | TLI.setUnavailable(LibFunc::exp2); |
| 162 | TLI.setUnavailable(LibFunc::exp2f); |
| 163 | TLI.setUnavailable(LibFunc::exp2l); |
| 164 | TLI.setUnavailable(LibFunc::expm1); |
| 165 | TLI.setUnavailable(LibFunc::expm1f); |
| 166 | TLI.setUnavailable(LibFunc::expm1l); |
| 167 | TLI.setUnavailable(LibFunc::log2); |
| 168 | TLI.setUnavailable(LibFunc::log2f); |
| 169 | TLI.setUnavailable(LibFunc::log2l); |
| 170 | TLI.setUnavailable(LibFunc::log1p); |
| 171 | TLI.setUnavailable(LibFunc::log1pf); |
| 172 | TLI.setUnavailable(LibFunc::log1pl); |
Chad Rosier | 7fb0cd2 | 2012-08-21 23:28:56 +0000 | [diff] [blame] | 173 | TLI.setUnavailable(LibFunc::logb); |
| 174 | TLI.setUnavailable(LibFunc::logbf); |
| 175 | TLI.setUnavailable(LibFunc::logbl); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 176 | TLI.setUnavailable(LibFunc::nearbyint); |
| 177 | TLI.setUnavailable(LibFunc::nearbyintf); |
| 178 | TLI.setUnavailable(LibFunc::nearbyintl); |
| 179 | TLI.setUnavailable(LibFunc::rint); |
| 180 | TLI.setUnavailable(LibFunc::rintf); |
| 181 | TLI.setUnavailable(LibFunc::rintl); |
| 182 | TLI.setUnavailable(LibFunc::round); |
| 183 | TLI.setUnavailable(LibFunc::roundf); |
| 184 | TLI.setUnavailable(LibFunc::roundl); |
| 185 | TLI.setUnavailable(LibFunc::trunc); |
| 186 | TLI.setUnavailable(LibFunc::truncf); |
| 187 | TLI.setUnavailable(LibFunc::truncl); |
| 188 | |
| 189 | // Win32 provides some C99 math with mangled names |
| 190 | TLI.setAvailableWithName(LibFunc::copysign, "_copysign"); |
| 191 | |
| 192 | if (T.getArch() == Triple::x86) { |
| 193 | // Win32 on x86 implements single-precision math functions as macros |
| 194 | TLI.setUnavailable(LibFunc::acosf); |
| 195 | TLI.setUnavailable(LibFunc::asinf); |
| 196 | TLI.setUnavailable(LibFunc::atanf); |
| 197 | TLI.setUnavailable(LibFunc::atan2f); |
| 198 | TLI.setUnavailable(LibFunc::ceilf); |
| 199 | TLI.setUnavailable(LibFunc::copysignf); |
| 200 | TLI.setUnavailable(LibFunc::cosf); |
| 201 | TLI.setUnavailable(LibFunc::coshf); |
| 202 | TLI.setUnavailable(LibFunc::expf); |
| 203 | TLI.setUnavailable(LibFunc::floorf); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 204 | TLI.setUnavailable(LibFunc::fminf); |
| 205 | TLI.setUnavailable(LibFunc::fmaxf); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 206 | TLI.setUnavailable(LibFunc::fmodf); |
| 207 | TLI.setUnavailable(LibFunc::logf); |
David Majnemer | eac58d8 | 2016-05-08 08:15:50 +0000 | [diff] [blame^] | 208 | TLI.setUnavailable(LibFunc::log10f); |
| 209 | TLI.setUnavailable(LibFunc::modff); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 210 | TLI.setUnavailable(LibFunc::powf); |
| 211 | TLI.setUnavailable(LibFunc::sinf); |
| 212 | TLI.setUnavailable(LibFunc::sinhf); |
| 213 | TLI.setUnavailable(LibFunc::sqrtf); |
| 214 | TLI.setUnavailable(LibFunc::tanf); |
| 215 | TLI.setUnavailable(LibFunc::tanhf); |
| 216 | } |
Meador Inge | 2526a42 | 2012-11-10 03:11:06 +0000 | [diff] [blame] | 217 | |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 218 | // Win32 does *not* provide provide these functions, but they are |
| 219 | // generally available on POSIX-compliant systems: |
| 220 | TLI.setUnavailable(LibFunc::access); |
| 221 | TLI.setUnavailable(LibFunc::bcmp); |
| 222 | TLI.setUnavailable(LibFunc::bcopy); |
| 223 | TLI.setUnavailable(LibFunc::bzero); |
| 224 | TLI.setUnavailable(LibFunc::chmod); |
| 225 | TLI.setUnavailable(LibFunc::chown); |
| 226 | TLI.setUnavailable(LibFunc::closedir); |
| 227 | TLI.setUnavailable(LibFunc::ctermid); |
| 228 | TLI.setUnavailable(LibFunc::fdopen); |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 229 | TLI.setUnavailable(LibFunc::ffs); |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 230 | TLI.setUnavailable(LibFunc::fileno); |
| 231 | TLI.setUnavailable(LibFunc::flockfile); |
| 232 | TLI.setUnavailable(LibFunc::fseeko); |
| 233 | TLI.setUnavailable(LibFunc::fstat); |
| 234 | TLI.setUnavailable(LibFunc::fstatvfs); |
| 235 | TLI.setUnavailable(LibFunc::ftello); |
| 236 | TLI.setUnavailable(LibFunc::ftrylockfile); |
| 237 | TLI.setUnavailable(LibFunc::funlockfile); |
| 238 | TLI.setUnavailable(LibFunc::getc_unlocked); |
| 239 | TLI.setUnavailable(LibFunc::getitimer); |
| 240 | TLI.setUnavailable(LibFunc::getlogin_r); |
| 241 | TLI.setUnavailable(LibFunc::getpwnam); |
Michael Gottesman | f7459c7 | 2013-07-03 04:00:51 +0000 | [diff] [blame] | 242 | TLI.setUnavailable(LibFunc::gettimeofday); |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 243 | TLI.setUnavailable(LibFunc::htonl); |
| 244 | TLI.setUnavailable(LibFunc::htons); |
| 245 | TLI.setUnavailable(LibFunc::lchown); |
| 246 | TLI.setUnavailable(LibFunc::lstat); |
| 247 | TLI.setUnavailable(LibFunc::memccpy); |
| 248 | TLI.setUnavailable(LibFunc::mkdir); |
| 249 | TLI.setUnavailable(LibFunc::ntohl); |
| 250 | TLI.setUnavailable(LibFunc::ntohs); |
| 251 | TLI.setUnavailable(LibFunc::open); |
| 252 | TLI.setUnavailable(LibFunc::opendir); |
| 253 | TLI.setUnavailable(LibFunc::pclose); |
| 254 | TLI.setUnavailable(LibFunc::popen); |
| 255 | TLI.setUnavailable(LibFunc::pread); |
| 256 | TLI.setUnavailable(LibFunc::pwrite); |
| 257 | TLI.setUnavailable(LibFunc::read); |
| 258 | TLI.setUnavailable(LibFunc::readlink); |
| 259 | TLI.setUnavailable(LibFunc::realpath); |
| 260 | TLI.setUnavailable(LibFunc::rmdir); |
| 261 | TLI.setUnavailable(LibFunc::setitimer); |
| 262 | TLI.setUnavailable(LibFunc::stat); |
| 263 | TLI.setUnavailable(LibFunc::statvfs); |
| 264 | TLI.setUnavailable(LibFunc::stpcpy); |
| 265 | TLI.setUnavailable(LibFunc::stpncpy); |
| 266 | TLI.setUnavailable(LibFunc::strcasecmp); |
| 267 | TLI.setUnavailable(LibFunc::strncasecmp); |
| 268 | TLI.setUnavailable(LibFunc::times); |
| 269 | TLI.setUnavailable(LibFunc::uname); |
| 270 | TLI.setUnavailable(LibFunc::unlink); |
| 271 | TLI.setUnavailable(LibFunc::unsetenv); |
| 272 | TLI.setUnavailable(LibFunc::utime); |
| 273 | TLI.setUnavailable(LibFunc::utimes); |
| 274 | TLI.setUnavailable(LibFunc::write); |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 275 | |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 276 | // Win32 does *not* provide provide these functions, but they are |
| 277 | // specified by C99: |
| 278 | TLI.setUnavailable(LibFunc::atoll); |
| 279 | TLI.setUnavailable(LibFunc::frexpf); |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 280 | TLI.setUnavailable(LibFunc::llabs); |
| 281 | } |
| 282 | |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 283 | switch (T.getOS()) { |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 284 | case Triple::MacOSX: |
Chandler Carruth | f5689f8 | 2013-12-28 02:40:19 +0000 | [diff] [blame] | 285 | // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 |
| 286 | // and their names are __exp10 and __exp10f. exp10l is not available on |
| 287 | // OS X or iOS. |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 288 | TLI.setUnavailable(LibFunc::exp10l); |
| 289 | if (T.isMacOSXVersionLT(10, 9)) { |
| 290 | TLI.setUnavailable(LibFunc::exp10); |
| 291 | TLI.setUnavailable(LibFunc::exp10f); |
| 292 | } else { |
| 293 | TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); |
| 294 | TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); |
| 295 | } |
| 296 | break; |
| 297 | case Triple::IOS: |
Tim Northover | 89a6eef | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 298 | case Triple::TvOS: |
Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 299 | case Triple::WatchOS: |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 300 | TLI.setUnavailable(LibFunc::exp10l); |
Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 301 | if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || |
| 302 | (T.isOSVersionLT(9, 0) && |
| 303 | (T.getArch() == Triple::x86 || |
| 304 | T.getArch() == Triple::x86_64)))) { |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 305 | TLI.setUnavailable(LibFunc::exp10); |
| 306 | TLI.setUnavailable(LibFunc::exp10f); |
| 307 | } else { |
| 308 | TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); |
| 309 | TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); |
| 310 | } |
| 311 | break; |
Chandler Carruth | f5689f8 | 2013-12-28 02:40:19 +0000 | [diff] [blame] | 312 | case Triple::Linux: |
| 313 | // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely |
| 314 | // buggy prior to glibc version 2.18. Until this version is widely deployed |
| 315 | // or we have a reasonable detection strategy, we cannot use exp10 reliably |
| 316 | // on Linux. |
| 317 | // |
| 318 | // Fall through to disable all of them. |
Reid Kleckner | f4355ee | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 319 | default: |
| 320 | TLI.setUnavailable(LibFunc::exp10); |
| 321 | TLI.setUnavailable(LibFunc::exp10f); |
| 322 | TLI.setUnavailable(LibFunc::exp10l); |
| 323 | } |
| 324 | |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 325 | // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and |
| 326 | // Linux (GLIBC): |
| 327 | // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html |
Davide Italiano | 83b3481 | 2015-11-01 17:00:13 +0000 | [diff] [blame] | 328 | // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 329 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html |
| 330 | switch (T.getOS()) { |
| 331 | case Triple::Darwin: |
| 332 | case Triple::MacOSX: |
| 333 | case Triple::IOS: |
Tim Northover | 89a6eef | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 334 | case Triple::TvOS: |
Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 335 | case Triple::WatchOS: |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 336 | case Triple::FreeBSD: |
| 337 | case Triple::Linux: |
| 338 | break; |
| 339 | default: |
| 340 | TLI.setUnavailable(LibFunc::ffsl); |
| 341 | } |
| 342 | |
| 343 | // ffsll is available on at least FreeBSD and Linux (GLIBC): |
Davide Italiano | 83b3481 | 2015-11-01 17:00:13 +0000 | [diff] [blame] | 344 | // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 345 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html |
| 346 | switch (T.getOS()) { |
Tim Northover | 89a6eef | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 347 | case Triple::Darwin: |
| 348 | case Triple::MacOSX: |
| 349 | case Triple::IOS: |
| 350 | case Triple::TvOS: |
| 351 | case Triple::WatchOS: |
Meador Inge | 780a186 | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 352 | case Triple::FreeBSD: |
| 353 | case Triple::Linux: |
| 354 | break; |
| 355 | default: |
| 356 | TLI.setUnavailable(LibFunc::ffsll); |
Joe Groff | a81bcbb | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 357 | } |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 358 | |
Davide Italiano | bfd3082 | 2015-11-09 23:23:20 +0000 | [diff] [blame] | 359 | // The following functions are available on at least FreeBSD: |
| 360 | // http://svn.freebsd.org/base/head/lib/libc/string/fls.c |
| 361 | // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c |
| 362 | // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c |
| 363 | if (!T.isOSFreeBSD()) { |
| 364 | TLI.setUnavailable(LibFunc::fls); |
| 365 | TLI.setUnavailable(LibFunc::flsl); |
| 366 | TLI.setUnavailable(LibFunc::flsll); |
| 367 | } |
| 368 | |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 369 | // The following functions are available on at least Linux: |
Cameron Esfahani | 943908b | 2013-08-29 20:23:14 +0000 | [diff] [blame] | 370 | if (!T.isOSLinux()) { |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 371 | TLI.setUnavailable(LibFunc::dunder_strdup); |
| 372 | TLI.setUnavailable(LibFunc::dunder_strtok_r); |
| 373 | TLI.setUnavailable(LibFunc::dunder_isoc99_scanf); |
| 374 | TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf); |
| 375 | TLI.setUnavailable(LibFunc::under_IO_getc); |
| 376 | TLI.setUnavailable(LibFunc::under_IO_putc); |
| 377 | TLI.setUnavailable(LibFunc::memalign); |
| 378 | TLI.setUnavailable(LibFunc::fopen64); |
| 379 | TLI.setUnavailable(LibFunc::fseeko64); |
| 380 | TLI.setUnavailable(LibFunc::fstat64); |
| 381 | TLI.setUnavailable(LibFunc::fstatvfs64); |
| 382 | TLI.setUnavailable(LibFunc::ftello64); |
| 383 | TLI.setUnavailable(LibFunc::lstat64); |
| 384 | TLI.setUnavailable(LibFunc::open64); |
| 385 | TLI.setUnavailable(LibFunc::stat64); |
| 386 | TLI.setUnavailable(LibFunc::statvfs64); |
| 387 | TLI.setUnavailable(LibFunc::tmpfile64); |
| 388 | } |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 389 | |
Justin Lebar | 5113288 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 390 | // As currently implemented in clang, NVPTX code has no standard library to |
| 391 | // speak of. Headers provide a standard-ish library implementation, but many |
| 392 | // of the signatures are wrong -- for example, many libm functions are not |
| 393 | // extern "C". |
| 394 | // |
| 395 | // libdevice, an IR library provided by nvidia, is linked in by the front-end, |
| 396 | // but only used functions are provided to llvm. Moreover, most of the |
| 397 | // functions in libdevice don't map precisely to standard library functions. |
| 398 | // |
| 399 | // FIXME: Having no standard library prevents e.g. many fastmath |
| 400 | // optimizations, so this situation should be fixed. |
David Majnemer | ae272d7 | 2016-03-31 21:29:57 +0000 | [diff] [blame] | 401 | if (T.isNVPTX()) { |
Justin Lebar | 5113288 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 402 | TLI.disableAllFunctions(); |
David Majnemer | ae272d7 | 2016-03-31 21:29:57 +0000 | [diff] [blame] | 403 | TLI.setAvailable(LibFunc::nvvm_reflect); |
| 404 | } else { |
| 405 | TLI.setUnavailable(LibFunc::nvvm_reflect); |
| 406 | } |
Justin Lebar | 5113288 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 407 | |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 408 | TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 411 | TargetLibraryInfoImpl::TargetLibraryInfoImpl() { |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 412 | // Default to everything being available. |
| 413 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 414 | |
Bob Wilson | c740e3f | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 415 | initialize(*this, Triple(), StandardNames); |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 418 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 419 | // Default to everything being available. |
| 420 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 421 | |
Bob Wilson | c740e3f | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 422 | initialize(*this, T, StandardNames); |
Chris Lattner | 0e125bb | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 423 | } |
Chris Lattner | 1341df9 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 424 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 425 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 426 | : CustomNames(TLI.CustomNames) { |
Chris Lattner | 4c0d9e2 | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 427 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
Michael Zolotukhin | e8f2551 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 428 | VectorDescs = TLI.VectorDescs; |
| 429 | ScalarDescs = TLI.ScalarDescs; |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 432 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 433 | : CustomNames(std::move(TLI.CustomNames)) { |
| 434 | std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), |
| 435 | AvailableArray); |
Michael Zolotukhin | e8f2551 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 436 | VectorDescs = TLI.VectorDescs; |
| 437 | ScalarDescs = TLI.ScalarDescs; |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 440 | TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 441 | CustomNames = TLI.CustomNames; |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 442 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
| 443 | return *this; |
| 444 | } |
| 445 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 446 | TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 447 | CustomNames = std::move(TLI.CustomNames); |
| 448 | std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), |
| 449 | AvailableArray); |
| 450 | return *this; |
Chris Lattner | 4c0d9e2 | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Michael Zolotukhin | 21abdf9 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 453 | static StringRef sanitizeFunctionName(StringRef funcName) { |
Benjamin Kramer | 160f72d | 2013-03-09 13:48:23 +0000 | [diff] [blame] | 454 | // Filter out empty names and names containing null bytes, those can't be in |
| 455 | // our table. |
| 456 | if (funcName.empty() || funcName.find('\0') != StringRef::npos) |
Michael Zolotukhin | 21abdf9 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 457 | return StringRef(); |
Benjamin Kramer | 160f72d | 2013-03-09 13:48:23 +0000 | [diff] [blame] | 458 | |
Meador Inge | b904e6e | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 459 | // Check for \01 prefix that is used to mangle __asm declarations and |
| 460 | // strip it if present. |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 461 | return GlobalValue::getRealLinkageName(funcName); |
Michael Zolotukhin | 21abdf9 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, |
Ahmed Bougacha | 220c401 | 2016-04-27 19:04:29 +0000 | [diff] [blame] | 465 | LibFunc::Func &F) const { |
Benjamin Kramer | 57a3d08 | 2015-03-08 16:07:39 +0000 | [diff] [blame] | 466 | const char *const *Start = &StandardNames[0]; |
| 467 | const char *const *End = &StandardNames[LibFunc::NumLibFuncs]; |
Michael Zolotukhin | 21abdf9 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 468 | |
| 469 | funcName = sanitizeFunctionName(funcName); |
| 470 | if (funcName.empty()) |
| 471 | return false; |
| 472 | |
Benjamin Kramer | 57a3d08 | 2015-03-08 16:07:39 +0000 | [diff] [blame] | 473 | const char *const *I = std::lower_bound( |
Michael Zolotukhin | d3b76a3 | 2015-03-02 20:50:08 +0000 | [diff] [blame] | 474 | Start, End, funcName, [](const char *LHS, StringRef RHS) { |
| 475 | return std::strncmp(LHS, RHS.data(), RHS.size()) < 0; |
| 476 | }); |
Bob Wilson | c740e3f | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 477 | if (I != End && *I == funcName) { |
| 478 | F = (LibFunc::Func)(I - Start); |
| 479 | return true; |
| 480 | } |
| 481 | return false; |
| 482 | } |
Chris Lattner | 4c0d9e2 | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 483 | |
Ahmed Bougacha | d765a82 | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 484 | bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, |
| 485 | LibFunc::Func F, |
| 486 | const DataLayout *DL) const { |
| 487 | LLVMContext &Ctx = FTy.getContext(); |
| 488 | Type *PCharTy = Type::getInt8PtrTy(Ctx); |
| 489 | Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; |
| 490 | auto IsSizeTTy = [SizeTTy](Type *Ty) { |
| 491 | return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); |
| 492 | }; |
| 493 | unsigned NumParams = FTy.getNumParams(); |
| 494 | |
| 495 | switch (F) { |
| 496 | case LibFunc::strlen: |
| 497 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && |
| 498 | FTy.getReturnType()->isIntegerTy()); |
| 499 | |
| 500 | case LibFunc::strchr: |
| 501 | case LibFunc::strrchr: |
| 502 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 503 | FTy.getParamType(0) == FTy.getReturnType() && |
| 504 | FTy.getParamType(1)->isIntegerTy()); |
| 505 | |
| 506 | case LibFunc::strtol: |
| 507 | case LibFunc::strtod: |
| 508 | case LibFunc::strtof: |
| 509 | case LibFunc::strtoul: |
| 510 | case LibFunc::strtoll: |
| 511 | case LibFunc::strtold: |
| 512 | case LibFunc::strtoull: |
| 513 | return ((NumParams == 2 || NumParams == 3) && |
| 514 | FTy.getParamType(0)->isPointerTy() && |
| 515 | FTy.getParamType(1)->isPointerTy()); |
| 516 | case LibFunc::strcat: |
| 517 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 518 | FTy.getParamType(0) == FTy.getReturnType() && |
| 519 | FTy.getParamType(1) == FTy.getReturnType()); |
| 520 | |
| 521 | case LibFunc::strncat: |
| 522 | return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && |
| 523 | FTy.getParamType(0) == FTy.getReturnType() && |
| 524 | FTy.getParamType(1) == FTy.getReturnType() && |
| 525 | FTy.getParamType(2)->isIntegerTy()); |
| 526 | |
| 527 | case LibFunc::strcpy_chk: |
| 528 | case LibFunc::stpcpy_chk: |
| 529 | --NumParams; |
| 530 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 531 | return false; |
| 532 | // fallthrough |
| 533 | case LibFunc::strcpy: |
| 534 | case LibFunc::stpcpy: |
| 535 | return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && |
| 536 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 537 | FTy.getParamType(0) == PCharTy); |
| 538 | |
| 539 | case LibFunc::strncpy_chk: |
| 540 | case LibFunc::stpncpy_chk: |
| 541 | --NumParams; |
| 542 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 543 | return false; |
| 544 | // fallthrough |
| 545 | case LibFunc::strncpy: |
| 546 | case LibFunc::stpncpy: |
| 547 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 548 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 549 | FTy.getParamType(0) == PCharTy && |
| 550 | FTy.getParamType(2)->isIntegerTy()); |
| 551 | |
| 552 | case LibFunc::strxfrm: |
| 553 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 554 | FTy.getParamType(1)->isPointerTy()); |
| 555 | |
| 556 | case LibFunc::strcmp: |
| 557 | return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && |
| 558 | FTy.getParamType(0)->isPointerTy() && |
| 559 | FTy.getParamType(0) == FTy.getParamType(1)); |
| 560 | |
| 561 | case LibFunc::strncmp: |
| 562 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && |
| 563 | FTy.getParamType(0)->isPointerTy() && |
| 564 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 565 | FTy.getParamType(2)->isIntegerTy()); |
| 566 | |
| 567 | case LibFunc::strspn: |
| 568 | case LibFunc::strcspn: |
| 569 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 570 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 571 | FTy.getReturnType()->isIntegerTy()); |
| 572 | |
| 573 | case LibFunc::strcoll: |
| 574 | case LibFunc::strcasecmp: |
| 575 | case LibFunc::strncasecmp: |
| 576 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 577 | FTy.getParamType(1)->isPointerTy()); |
| 578 | |
| 579 | case LibFunc::strstr: |
| 580 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 581 | FTy.getParamType(0)->isPointerTy() && |
| 582 | FTy.getParamType(1)->isPointerTy()); |
| 583 | |
| 584 | case LibFunc::strpbrk: |
| 585 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 586 | FTy.getReturnType() == FTy.getParamType(0) && |
| 587 | FTy.getParamType(0) == FTy.getParamType(1)); |
| 588 | |
| 589 | case LibFunc::strtok: |
| 590 | case LibFunc::strtok_r: |
| 591 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
| 592 | case LibFunc::scanf: |
| 593 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
| 594 | case LibFunc::setbuf: |
| 595 | case LibFunc::setvbuf: |
| 596 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
| 597 | case LibFunc::strdup: |
| 598 | case LibFunc::strndup: |
| 599 | return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && |
| 600 | FTy.getParamType(0)->isPointerTy()); |
| 601 | case LibFunc::stat: |
| 602 | case LibFunc::statvfs: |
| 603 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 604 | FTy.getParamType(1)->isPointerTy()); |
| 605 | case LibFunc::sscanf: |
| 606 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 607 | FTy.getParamType(1)->isPointerTy()); |
| 608 | case LibFunc::sprintf: |
| 609 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 610 | FTy.getParamType(1)->isPointerTy()); |
| 611 | case LibFunc::snprintf: |
| 612 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 613 | FTy.getParamType(2)->isPointerTy()); |
| 614 | case LibFunc::setitimer: |
| 615 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 616 | FTy.getParamType(2)->isPointerTy()); |
| 617 | case LibFunc::system: |
| 618 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 619 | case LibFunc::malloc: |
| 620 | return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); |
| 621 | case LibFunc::memcmp: |
| 622 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 623 | FTy.getParamType(1)->isPointerTy() && |
| 624 | FTy.getReturnType()->isIntegerTy(32)); |
| 625 | |
| 626 | case LibFunc::memchr: |
| 627 | case LibFunc::memrchr: |
| 628 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 629 | FTy.getParamType(1)->isIntegerTy(32) && |
| 630 | FTy.getParamType(2)->isIntegerTy() && |
| 631 | FTy.getReturnType()->isPointerTy()); |
| 632 | case LibFunc::modf: |
| 633 | case LibFunc::modff: |
| 634 | case LibFunc::modfl: |
| 635 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
| 636 | |
| 637 | case LibFunc::memcpy_chk: |
| 638 | case LibFunc::memmove_chk: |
| 639 | --NumParams; |
| 640 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 641 | return false; |
| 642 | // fallthrough |
| 643 | case LibFunc::memcpy: |
| 644 | case LibFunc::memmove: |
| 645 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 646 | FTy.getParamType(0)->isPointerTy() && |
| 647 | FTy.getParamType(1)->isPointerTy() && |
| 648 | IsSizeTTy(FTy.getParamType(2))); |
| 649 | |
| 650 | case LibFunc::memset_chk: |
| 651 | --NumParams; |
| 652 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 653 | return false; |
| 654 | // fallthrough |
| 655 | case LibFunc::memset: |
| 656 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 657 | FTy.getParamType(0)->isPointerTy() && |
| 658 | FTy.getParamType(1)->isIntegerTy() && |
| 659 | IsSizeTTy(FTy.getParamType(2))); |
| 660 | |
| 661 | case LibFunc::memccpy: |
| 662 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
| 663 | case LibFunc::memalign: |
| 664 | return (FTy.getReturnType()->isPointerTy()); |
| 665 | case LibFunc::mkdir: |
| 666 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 667 | case LibFunc::mktime: |
| 668 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 669 | case LibFunc::realloc: |
| 670 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 671 | FTy.getReturnType()->isPointerTy()); |
| 672 | case LibFunc::read: |
| 673 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
| 674 | case LibFunc::rewind: |
| 675 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
| 676 | case LibFunc::rmdir: |
| 677 | case LibFunc::remove: |
| 678 | case LibFunc::realpath: |
| 679 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
| 680 | case LibFunc::rename: |
| 681 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 682 | FTy.getParamType(1)->isPointerTy()); |
| 683 | case LibFunc::readlink: |
| 684 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 685 | FTy.getParamType(1)->isPointerTy()); |
| 686 | case LibFunc::write: |
| 687 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
| 688 | case LibFunc::bcopy: |
| 689 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 690 | FTy.getParamType(1)->isPointerTy()); |
| 691 | case LibFunc::bcmp: |
| 692 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 693 | FTy.getParamType(1)->isPointerTy()); |
| 694 | case LibFunc::bzero: |
| 695 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
| 696 | case LibFunc::calloc: |
| 697 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); |
| 698 | case LibFunc::chmod: |
| 699 | case LibFunc::chown: |
| 700 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 701 | case LibFunc::ctermid: |
| 702 | case LibFunc::clearerr: |
| 703 | case LibFunc::closedir: |
| 704 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 705 | case LibFunc::atoi: |
| 706 | case LibFunc::atol: |
| 707 | case LibFunc::atof: |
| 708 | case LibFunc::atoll: |
| 709 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 710 | case LibFunc::access: |
| 711 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
| 712 | case LibFunc::fopen: |
| 713 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 714 | FTy.getParamType(0)->isPointerTy() && |
| 715 | FTy.getParamType(1)->isPointerTy()); |
| 716 | case LibFunc::fdopen: |
| 717 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 718 | FTy.getParamType(1)->isPointerTy()); |
| 719 | case LibFunc::feof: |
| 720 | case LibFunc::free: |
| 721 | case LibFunc::fseek: |
| 722 | case LibFunc::ftell: |
| 723 | case LibFunc::fgetc: |
| 724 | case LibFunc::fseeko: |
| 725 | case LibFunc::ftello: |
| 726 | case LibFunc::fileno: |
| 727 | case LibFunc::fflush: |
| 728 | case LibFunc::fclose: |
| 729 | case LibFunc::fsetpos: |
| 730 | case LibFunc::flockfile: |
| 731 | case LibFunc::funlockfile: |
| 732 | case LibFunc::ftrylockfile: |
| 733 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 734 | case LibFunc::ferror: |
| 735 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 736 | case LibFunc::fputc: |
| 737 | case LibFunc::fstat: |
| 738 | case LibFunc::frexp: |
| 739 | case LibFunc::frexpf: |
| 740 | case LibFunc::frexpl: |
| 741 | case LibFunc::fstatvfs: |
| 742 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 743 | case LibFunc::fgets: |
| 744 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 745 | FTy.getParamType(2)->isPointerTy()); |
| 746 | case LibFunc::fread: |
| 747 | return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && |
| 748 | FTy.getParamType(3)->isPointerTy()); |
| 749 | case LibFunc::fwrite: |
| 750 | return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && |
| 751 | FTy.getParamType(0)->isPointerTy() && |
| 752 | FTy.getParamType(1)->isIntegerTy() && |
| 753 | FTy.getParamType(2)->isIntegerTy() && |
| 754 | FTy.getParamType(3)->isPointerTy()); |
| 755 | case LibFunc::fputs: |
| 756 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 757 | FTy.getParamType(1)->isPointerTy()); |
| 758 | case LibFunc::fscanf: |
| 759 | case LibFunc::fprintf: |
| 760 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 761 | FTy.getParamType(1)->isPointerTy()); |
| 762 | case LibFunc::fgetpos: |
| 763 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 764 | FTy.getParamType(1)->isPointerTy()); |
| 765 | case LibFunc::getc: |
| 766 | case LibFunc::getlogin_r: |
| 767 | case LibFunc::getc_unlocked: |
| 768 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 769 | case LibFunc::getenv: |
| 770 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 771 | case LibFunc::gets: |
| 772 | case LibFunc::getchar: |
| 773 | case LibFunc::getitimer: |
| 774 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 775 | case LibFunc::getpwnam: |
| 776 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 777 | case LibFunc::ungetc: |
| 778 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 779 | case LibFunc::uname: |
| 780 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 781 | case LibFunc::unlink: |
| 782 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 783 | case LibFunc::unsetenv: |
| 784 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 785 | case LibFunc::utime: |
| 786 | case LibFunc::utimes: |
| 787 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 788 | FTy.getParamType(1)->isPointerTy()); |
| 789 | case LibFunc::putc: |
| 790 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 791 | case LibFunc::puts: |
| 792 | case LibFunc::printf: |
| 793 | case LibFunc::perror: |
| 794 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 795 | case LibFunc::pread: |
| 796 | case LibFunc::pwrite: |
| 797 | return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); |
| 798 | case LibFunc::putchar: |
| 799 | case LibFunc::popen: |
| 800 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 801 | FTy.getParamType(0)->isPointerTy() && |
| 802 | FTy.getParamType(1)->isPointerTy()); |
| 803 | case LibFunc::pclose: |
| 804 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 805 | case LibFunc::vscanf: |
| 806 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 807 | case LibFunc::vsscanf: |
| 808 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 809 | FTy.getParamType(2)->isPointerTy()); |
| 810 | case LibFunc::vfscanf: |
| 811 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 812 | FTy.getParamType(2)->isPointerTy()); |
| 813 | case LibFunc::valloc: |
| 814 | return (FTy.getReturnType()->isPointerTy()); |
| 815 | case LibFunc::vprintf: |
| 816 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
| 817 | case LibFunc::vfprintf: |
| 818 | case LibFunc::vsprintf: |
| 819 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 820 | FTy.getParamType(1)->isPointerTy()); |
| 821 | case LibFunc::vsnprintf: |
| 822 | return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && |
| 823 | FTy.getParamType(2)->isPointerTy()); |
| 824 | case LibFunc::open: |
| 825 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); |
| 826 | case LibFunc::opendir: |
| 827 | return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && |
| 828 | FTy.getParamType(0)->isPointerTy()); |
| 829 | case LibFunc::tmpfile: |
| 830 | return (FTy.getReturnType()->isPointerTy()); |
| 831 | case LibFunc::times: |
| 832 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 833 | case LibFunc::htonl: |
| 834 | case LibFunc::htons: |
| 835 | case LibFunc::ntohl: |
| 836 | case LibFunc::ntohs: |
| 837 | case LibFunc::lstat: |
| 838 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 839 | FTy.getParamType(1)->isPointerTy()); |
| 840 | case LibFunc::lchown: |
| 841 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); |
| 842 | case LibFunc::qsort: |
| 843 | return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); |
| 844 | case LibFunc::dunder_strdup: |
| 845 | case LibFunc::dunder_strndup: |
| 846 | return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && |
| 847 | FTy.getParamType(0)->isPointerTy()); |
| 848 | case LibFunc::dunder_strtok_r: |
| 849 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
| 850 | case LibFunc::under_IO_getc: |
| 851 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 852 | case LibFunc::under_IO_putc: |
| 853 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 854 | case LibFunc::dunder_isoc99_scanf: |
| 855 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
| 856 | case LibFunc::stat64: |
| 857 | case LibFunc::lstat64: |
| 858 | case LibFunc::statvfs64: |
| 859 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() && |
| 860 | FTy.getParamType(1)->isPointerTy()); |
| 861 | case LibFunc::dunder_isoc99_sscanf: |
| 862 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() && |
| 863 | FTy.getParamType(1)->isPointerTy()); |
| 864 | case LibFunc::fopen64: |
| 865 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 866 | FTy.getParamType(0)->isPointerTy() && |
| 867 | FTy.getParamType(1)->isPointerTy()); |
| 868 | case LibFunc::fseeko64: |
| 869 | case LibFunc::ftello64: |
| 870 | return (NumParams == 0 && FTy.getParamType(0)->isPointerTy()); |
| 871 | case LibFunc::tmpfile64: |
| 872 | return (FTy.getReturnType()->isPointerTy()); |
| 873 | case LibFunc::fstat64: |
| 874 | case LibFunc::fstatvfs64: |
| 875 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
| 876 | case LibFunc::open64: |
| 877 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); |
| 878 | case LibFunc::gettimeofday: |
| 879 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 880 | FTy.getParamType(1)->isPointerTy()); |
| 881 | |
| 882 | case LibFunc::Znwj: // new(unsigned int); |
| 883 | case LibFunc::Znwm: // new(unsigned long); |
| 884 | case LibFunc::Znaj: // new[](unsigned int); |
| 885 | case LibFunc::Znam: // new[](unsigned long); |
| 886 | case LibFunc::msvc_new_int: // new(unsigned int); |
| 887 | case LibFunc::msvc_new_longlong: // new(unsigned long long); |
| 888 | case LibFunc::msvc_new_array_int: // new[](unsigned int); |
| 889 | case LibFunc::msvc_new_array_longlong: // new[](unsigned long long); |
| 890 | return (NumParams == 1); |
| 891 | |
| 892 | case LibFunc::memset_pattern16: |
| 893 | return (!FTy.isVarArg() && NumParams == 3 && |
| 894 | isa<PointerType>(FTy.getParamType(0)) && |
| 895 | isa<PointerType>(FTy.getParamType(1)) && |
| 896 | isa<IntegerType>(FTy.getParamType(2))); |
| 897 | |
| 898 | // int __nvvm_reflect(const char *); |
| 899 | case LibFunc::nvvm_reflect: |
| 900 | return (NumParams == 1 && isa<PointerType>(FTy.getParamType(0))); |
| 901 | |
| 902 | case LibFunc::sin: |
| 903 | case LibFunc::sinf: |
| 904 | case LibFunc::sinl: |
| 905 | case LibFunc::cos: |
| 906 | case LibFunc::cosf: |
| 907 | case LibFunc::cosl: |
| 908 | case LibFunc::exp: |
| 909 | case LibFunc::expf: |
| 910 | case LibFunc::expl: |
| 911 | case LibFunc::exp2: |
| 912 | case LibFunc::exp2f: |
| 913 | case LibFunc::exp2l: |
| 914 | case LibFunc::log: |
| 915 | case LibFunc::logf: |
| 916 | case LibFunc::logl: |
| 917 | case LibFunc::log10: |
| 918 | case LibFunc::log10f: |
| 919 | case LibFunc::log10l: |
| 920 | case LibFunc::log2: |
| 921 | case LibFunc::log2f: |
| 922 | case LibFunc::log2l: |
| 923 | case LibFunc::fabs: |
| 924 | case LibFunc::fabsf: |
| 925 | case LibFunc::fabsl: |
| 926 | case LibFunc::floor: |
| 927 | case LibFunc::floorf: |
| 928 | case LibFunc::floorl: |
| 929 | case LibFunc::ceil: |
| 930 | case LibFunc::ceilf: |
| 931 | case LibFunc::ceill: |
| 932 | case LibFunc::trunc: |
| 933 | case LibFunc::truncf: |
| 934 | case LibFunc::truncl: |
| 935 | case LibFunc::rint: |
| 936 | case LibFunc::rintf: |
| 937 | case LibFunc::rintl: |
| 938 | case LibFunc::nearbyint: |
| 939 | case LibFunc::nearbyintf: |
| 940 | case LibFunc::nearbyintl: |
| 941 | case LibFunc::round: |
| 942 | case LibFunc::roundf: |
| 943 | case LibFunc::roundl: |
| 944 | case LibFunc::sqrt: |
| 945 | case LibFunc::sqrtf: |
| 946 | case LibFunc::sqrtl: |
| 947 | return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && |
| 948 | FTy.getReturnType() == FTy.getParamType(0)); |
| 949 | |
| 950 | case LibFunc::fmin: |
| 951 | case LibFunc::fminf: |
| 952 | case LibFunc::fminl: |
| 953 | case LibFunc::fmax: |
| 954 | case LibFunc::fmaxf: |
| 955 | case LibFunc::fmaxl: |
| 956 | case LibFunc::copysign: |
| 957 | case LibFunc::copysignf: |
| 958 | case LibFunc::copysignl: |
| 959 | case LibFunc::pow: |
| 960 | case LibFunc::powf: |
| 961 | case LibFunc::powl: |
| 962 | return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && |
| 963 | FTy.getReturnType() == FTy.getParamType(0) && |
| 964 | FTy.getReturnType() == FTy.getParamType(1)); |
| 965 | |
| 966 | case LibFunc::ffs: |
| 967 | case LibFunc::ffsl: |
| 968 | case LibFunc::ffsll: |
| 969 | case LibFunc::isdigit: |
| 970 | case LibFunc::isascii: |
| 971 | case LibFunc::toascii: |
| 972 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && |
| 973 | FTy.getParamType(0)->isIntegerTy()); |
| 974 | |
| 975 | case LibFunc::fls: |
| 976 | case LibFunc::flsl: |
| 977 | case LibFunc::flsll: |
| 978 | case LibFunc::abs: |
| 979 | case LibFunc::labs: |
| 980 | case LibFunc::llabs: |
| 981 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && |
| 982 | FTy.getReturnType() == FTy.getParamType(0)); |
| 983 | |
| 984 | case LibFunc::cxa_atexit: |
| 985 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && |
| 986 | FTy.getParamType(0)->isPointerTy() && |
| 987 | FTy.getParamType(1)->isPointerTy() && |
| 988 | FTy.getParamType(2)->isPointerTy()); |
| 989 | |
| 990 | case LibFunc::sinpi: |
| 991 | case LibFunc::cospi: |
| 992 | return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && |
| 993 | FTy.getReturnType() == FTy.getParamType(0)); |
| 994 | |
| 995 | case LibFunc::sinpif: |
| 996 | case LibFunc::cospif: |
| 997 | return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && |
| 998 | FTy.getReturnType() == FTy.getParamType(0)); |
| 999 | |
| 1000 | default: |
| 1001 | // Assume the other functions are correct. |
| 1002 | // FIXME: It'd be really nice to cover them all. |
| 1003 | return true; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, |
| 1008 | LibFunc::Func &F) const { |
| 1009 | const DataLayout *DL = |
| 1010 | FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; |
| 1011 | return getLibFunc(FDecl.getName(), F) && |
| 1012 | isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); |
| 1013 | } |
| 1014 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1015 | void TargetLibraryInfoImpl::disableAllFunctions() { |
Chris Lattner | 1341df9 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 1016 | memset(AvailableArray, 0, sizeof(AvailableArray)); |
| 1017 | } |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1018 | |
Michael Zolotukhin | e8f2551 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1019 | static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { |
| 1020 | return std::strncmp(LHS.ScalarFnName, RHS.ScalarFnName, |
| 1021 | std::strlen(RHS.ScalarFnName)) < 0; |
| 1022 | } |
| 1023 | |
| 1024 | static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { |
| 1025 | return std::strncmp(LHS.VectorFnName, RHS.VectorFnName, |
| 1026 | std::strlen(RHS.VectorFnName)) < 0; |
| 1027 | } |
| 1028 | |
| 1029 | static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { |
| 1030 | return std::strncmp(LHS.ScalarFnName, S.data(), S.size()) < 0; |
| 1031 | } |
| 1032 | |
| 1033 | static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { |
| 1034 | return std::strncmp(LHS.VectorFnName, S.data(), S.size()) < 0; |
| 1035 | } |
| 1036 | |
| 1037 | void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { |
| 1038 | VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); |
| 1039 | std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName); |
| 1040 | |
| 1041 | ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); |
| 1042 | std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName); |
| 1043 | } |
| 1044 | |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1045 | void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( |
| 1046 | enum VectorLibrary VecLib) { |
| 1047 | switch (VecLib) { |
| 1048 | case Accelerate: { |
| 1049 | const VecDesc VecFuncs[] = { |
Michael Zolotukhin | de63aac | 2015-05-07 17:11:51 +0000 | [diff] [blame] | 1050 | // Floating-Point Arithmetic and Auxiliary Functions |
| 1051 | {"ceilf", "vceilf", 4}, |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1052 | {"fabsf", "vfabsf", 4}, |
| 1053 | {"llvm.fabs.f32", "vfabsf", 4}, |
Michael Zolotukhin | de63aac | 2015-05-07 17:11:51 +0000 | [diff] [blame] | 1054 | {"floorf", "vfloorf", 4}, |
| 1055 | {"sqrtf", "vsqrtf", 4}, |
| 1056 | {"llvm.sqrt.f32", "vsqrtf", 4}, |
| 1057 | |
| 1058 | // Exponential and Logarithmic Functions |
| 1059 | {"expf", "vexpf", 4}, |
| 1060 | {"llvm.exp.f32", "vexpf", 4}, |
| 1061 | {"expm1f", "vexpm1f", 4}, |
| 1062 | {"logf", "vlogf", 4}, |
| 1063 | {"llvm.log.f32", "vlogf", 4}, |
| 1064 | {"log1pf", "vlog1pf", 4}, |
| 1065 | {"log10f", "vlog10f", 4}, |
| 1066 | {"llvm.log10.f32", "vlog10f", 4}, |
| 1067 | {"logbf", "vlogbf", 4}, |
| 1068 | |
| 1069 | // Trigonometric Functions |
| 1070 | {"sinf", "vsinf", 4}, |
| 1071 | {"llvm.sin.f32", "vsinf", 4}, |
| 1072 | {"cosf", "vcosf", 4}, |
| 1073 | {"llvm.cos.f32", "vcosf", 4}, |
| 1074 | {"tanf", "vtanf", 4}, |
| 1075 | {"asinf", "vasinf", 4}, |
| 1076 | {"acosf", "vacosf", 4}, |
| 1077 | {"atanf", "vatanf", 4}, |
| 1078 | |
| 1079 | // Hyperbolic Functions |
| 1080 | {"sinhf", "vsinhf", 4}, |
| 1081 | {"coshf", "vcoshf", 4}, |
| 1082 | {"tanhf", "vtanhf", 4}, |
| 1083 | {"asinhf", "vasinhf", 4}, |
| 1084 | {"acoshf", "vacoshf", 4}, |
| 1085 | {"atanhf", "vatanhf", 4}, |
Michael Zolotukhin | 6d8a2aa | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1086 | }; |
| 1087 | addVectorizableFunctions(VecFuncs); |
| 1088 | break; |
| 1089 | } |
| 1090 | case NoLibrary: |
| 1091 | break; |
| 1092 | } |
| 1093 | } |
| 1094 | |
Michael Zolotukhin | e8f2551 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1095 | bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { |
| 1096 | funcName = sanitizeFunctionName(funcName); |
| 1097 | if (funcName.empty()) |
| 1098 | return false; |
| 1099 | |
| 1100 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1101 | VectorDescs.begin(), VectorDescs.end(), funcName, |
| 1102 | compareWithScalarFnName); |
| 1103 | return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; |
| 1104 | } |
| 1105 | |
| 1106 | StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, |
| 1107 | unsigned VF) const { |
| 1108 | F = sanitizeFunctionName(F); |
| 1109 | if (F.empty()) |
| 1110 | return F; |
| 1111 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1112 | VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName); |
| 1113 | while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { |
| 1114 | if (I->VectorizationFactor == VF) |
| 1115 | return I->VectorFnName; |
| 1116 | ++I; |
| 1117 | } |
| 1118 | return StringRef(); |
| 1119 | } |
| 1120 | |
| 1121 | StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, |
| 1122 | unsigned &VF) const { |
| 1123 | F = sanitizeFunctionName(F); |
| 1124 | if (F.empty()) |
| 1125 | return F; |
| 1126 | |
| 1127 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1128 | ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName); |
| 1129 | if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) |
| 1130 | return StringRef(); |
| 1131 | VF = I->VectorizationFactor; |
| 1132 | return I->ScalarFnName; |
| 1133 | } |
| 1134 | |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1135 | TargetLibraryInfo TargetLibraryAnalysis::run(Module &M) { |
| 1136 | if (PresetInfoImpl) |
| 1137 | return TargetLibraryInfo(*PresetInfoImpl); |
| 1138 | |
| 1139 | return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple()))); |
| 1140 | } |
| 1141 | |
| 1142 | TargetLibraryInfo TargetLibraryAnalysis::run(Function &F) { |
| 1143 | if (PresetInfoImpl) |
| 1144 | return TargetLibraryInfo(*PresetInfoImpl); |
| 1145 | |
| 1146 | return TargetLibraryInfo( |
| 1147 | lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); |
| 1148 | } |
| 1149 | |
| 1150 | TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(Triple T) { |
| 1151 | std::unique_ptr<TargetLibraryInfoImpl> &Impl = |
| 1152 | Impls[T.normalize()]; |
| 1153 | if (!Impl) |
| 1154 | Impl.reset(new TargetLibraryInfoImpl(T)); |
| 1155 | |
| 1156 | return *Impl; |
| 1157 | } |
| 1158 | |
| 1159 | |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1160 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1161 | : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1162 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1163 | } |
| 1164 | |
| 1165 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1166 | : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1167 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1168 | } |
| 1169 | |
| 1170 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( |
Chandler Carruth | c029186 | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1171 | const TargetLibraryInfoImpl &TLIImpl) |
| 1172 | : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1173 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1174 | } |
| 1175 | |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 1176 | char TargetLibraryAnalysis::PassID; |
NAKAMURA Takumi | df0cd72 | 2016-02-28 17:17:00 +0000 | [diff] [blame] | 1177 | |
Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1178 | // Register the basic pass. |
| 1179 | INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", |
| 1180 | "Target Library Information", false, true) |
| 1181 | char TargetLibraryInfoWrapperPass::ID = 0; |
| 1182 | |
| 1183 | void TargetLibraryInfoWrapperPass::anchor() {} |