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