Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 1 | //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the TargetLibraryInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | bda1349 | 2015-01-15 02:16:27 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Triple.h" |
Matthias Braun | 708626d | 2017-05-19 22:37:09 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Constants.h" |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 20 | static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary( |
| 21 | "vector-library", cl::Hidden, cl::desc("Vector functions library"), |
| 22 | cl::init(TargetLibraryInfoImpl::NoLibrary), |
| 23 | cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", |
| 24 | "No vector functions library"), |
| 25 | clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", |
| 26 | "Accelerate framework"), |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 27 | clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", |
Joel Jones | 9951b07 | 2018-11-24 07:26:55 +0000 | [diff] [blame] | 28 | "Intel SVML library"))); |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 29 | |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 30 | StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { |
Jan Wen Voung | 87a61e9 | 2015-03-03 23:41:58 +0000 | [diff] [blame] | 31 | #define TLI_DEFINE_STRING |
| 32 | #include "llvm/Analysis/TargetLibraryInfo.def" |
Benjamin Kramer | c8a95a8 | 2015-03-08 16:07:39 +0000 | [diff] [blame] | 33 | }; |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 34 | |
Bob Wilson | 208130f | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 35 | static bool hasSinCosPiStret(const Triple &T) { |
| 36 | // Only Darwin variants have _stret versions of combined trig functions. |
Bob Wilson | 8e67357 | 2014-10-09 05:43:30 +0000 | [diff] [blame] | 37 | if (!T.isOSDarwin()) |
Bob Wilson | 208130f | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 38 | return false; |
| 39 | |
| 40 | // The ABI is rather complicated on x86, so don't do anything special there. |
| 41 | if (T.getArch() == Triple::x86) |
| 42 | return false; |
| 43 | |
| 44 | if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) |
| 45 | return false; |
| 46 | |
Bob Wilson | 8e67357 | 2014-10-09 05:43:30 +0000 | [diff] [blame] | 47 | if (T.isiOS() && T.isOSVersionLT(7, 0)) |
Bob Wilson | 208130f | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 48 | return false; |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
Sanjay Patel | 050e890 | 2017-12-15 18:54:29 +0000 | [diff] [blame] | 53 | /// Initialize the set of available library functions based on the specified |
| 54 | /// target triple. This should be carefully written so that a missing target |
| 55 | /// triple gets a sane set of defaults. |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 56 | static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 57 | ArrayRef<StringRef> StandardNames) { |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 58 | // Verify that the StandardNames array is in alphabetical order. |
Craig Topper | 2921ff9 | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 59 | assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 60 | [](StringRef LHS, StringRef RHS) { |
| 61 | return LHS < RHS; |
Craig Topper | 2921ff9 | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 62 | }) && |
| 63 | "TargetLibraryInfoImpl function names must be sorted"); |
Tom Stellard | adb852d | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 64 | |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 65 | // Set IO unlocked variants as unavailable |
| 66 | // Set them as available per system below |
| 67 | TLI.setUnavailable(LibFunc_getchar_unlocked); |
| 68 | TLI.setUnavailable(LibFunc_putc_unlocked); |
| 69 | TLI.setUnavailable(LibFunc_putchar_unlocked); |
| 70 | TLI.setUnavailable(LibFunc_fputc_unlocked); |
| 71 | TLI.setUnavailable(LibFunc_fgetc_unlocked); |
| 72 | TLI.setUnavailable(LibFunc_fread_unlocked); |
| 73 | TLI.setUnavailable(LibFunc_fwrite_unlocked); |
| 74 | TLI.setUnavailable(LibFunc_fputs_unlocked); |
| 75 | TLI.setUnavailable(LibFunc_fgets_unlocked); |
| 76 | |
Marcin Koscielnicki | b76c6d3 | 2016-11-21 20:20:39 +0000 | [diff] [blame] | 77 | bool ShouldExtI32Param = false, ShouldExtI32Return = false, |
| 78 | ShouldSignExtI32Param = false; |
| 79 | // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and |
| 80 | // returns corresponding to C-level ints and unsigned ints. |
| 81 | if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le || |
| 82 | T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) { |
| 83 | ShouldExtI32Param = true; |
| 84 | ShouldExtI32Return = true; |
| 85 | } |
| 86 | // Mips, on the other hand, needs signext on i32 parameters corresponding |
| 87 | // to both signed and unsigned ints. |
Alexander Richardson | e850836 | 2018-06-25 16:49:20 +0000 | [diff] [blame] | 88 | if (T.isMIPS()) { |
Marcin Koscielnicki | b76c6d3 | 2016-11-21 20:20:39 +0000 | [diff] [blame] | 89 | ShouldSignExtI32Param = true; |
| 90 | } |
| 91 | TLI.setShouldExtI32Param(ShouldExtI32Param); |
| 92 | TLI.setShouldExtI32Return(ShouldExtI32Return); |
| 93 | TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); |
| 94 | |
Nicolai Hahnle | 44c3e26 | 2015-12-15 17:24:15 +0000 | [diff] [blame] | 95 | if (T.getArch() == Triple::r600 || |
| 96 | T.getArch() == Triple::amdgcn) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 97 | TLI.setUnavailable(LibFunc_ldexp); |
| 98 | TLI.setUnavailable(LibFunc_ldexpf); |
| 99 | TLI.setUnavailable(LibFunc_ldexpl); |
| 100 | TLI.setUnavailable(LibFunc_exp10); |
| 101 | TLI.setUnavailable(LibFunc_exp10f); |
| 102 | TLI.setUnavailable(LibFunc_exp10l); |
| 103 | TLI.setUnavailable(LibFunc_log10); |
| 104 | TLI.setUnavailable(LibFunc_log10f); |
| 105 | TLI.setUnavailable(LibFunc_log10l); |
Nicolai Hahnle | 44c3e26 | 2015-12-15 17:24:15 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Tom Stellard | d83c595 | 2015-01-07 01:17:37 +0000 | [diff] [blame] | 108 | // There are no library implementations of mempcy and memset for AMD gpus and |
Tom Stellard | adb852d | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 109 | // these can be difficult to lower in the backend. |
Tom Stellard | d83c595 | 2015-01-07 01:17:37 +0000 | [diff] [blame] | 110 | if (T.getArch() == Triple::r600 || |
Dan Gohman | b2c08be | 2016-01-19 14:49:23 +0000 | [diff] [blame] | 111 | T.getArch() == Triple::amdgcn) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 112 | TLI.setUnavailable(LibFunc_memcpy); |
| 113 | TLI.setUnavailable(LibFunc_memset); |
| 114 | TLI.setUnavailable(LibFunc_memset_pattern16); |
Tom Stellard | adb852d | 2014-04-02 19:53:29 +0000 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
Nico Weber | f456d37 | 2014-03-07 18:08:54 +0000 | [diff] [blame] | 118 | // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. |
Tim Northover | 7b7ff9e | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 119 | // All versions of watchOS support it. |
Daniel Dunbar | 558692f | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 120 | if (T.isMacOSX()) { |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 121 | // available IO unlocked variants on Mac OS X |
| 122 | TLI.setAvailable(LibFunc_getc_unlocked); |
| 123 | TLI.setAvailable(LibFunc_getchar_unlocked); |
| 124 | TLI.setAvailable(LibFunc_putc_unlocked); |
| 125 | TLI.setAvailable(LibFunc_putchar_unlocked); |
| 126 | |
Daniel Dunbar | 558692f | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 127 | if (T.isMacOSXVersionLT(10, 5)) |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 128 | TLI.setUnavailable(LibFunc_memset_pattern16); |
Cameron Esfahani | 441c557 | 2013-08-29 20:23:14 +0000 | [diff] [blame] | 129 | } else if (T.isiOS()) { |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 130 | if (T.isOSVersionLT(3, 0)) |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 131 | TLI.setUnavailable(LibFunc_memset_pattern16); |
Tim Northover | 7b7ff9e | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 132 | } else if (!T.isWatchOS()) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 133 | TLI.setUnavailable(LibFunc_memset_pattern16); |
Daniel Dunbar | 13fb3b5 | 2011-04-19 20:44:08 +0000 | [diff] [blame] | 134 | } |
Richard Osborne | 3649824 | 2011-03-03 13:17:51 +0000 | [diff] [blame] | 135 | |
Bob Wilson | 208130f | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 136 | if (!hasSinCosPiStret(T)) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 137 | TLI.setUnavailable(LibFunc_sinpi); |
| 138 | TLI.setUnavailable(LibFunc_sinpif); |
| 139 | TLI.setUnavailable(LibFunc_cospi); |
| 140 | TLI.setUnavailable(LibFunc_cospif); |
| 141 | TLI.setUnavailable(LibFunc_sincospi_stret); |
| 142 | TLI.setUnavailable(LibFunc_sincospif_stret); |
Bob Wilson | 208130f | 2013-11-03 06:48:38 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 145 | if (T.isMacOSX() && T.getArch() == Triple::x86 && |
| 146 | !T.isMacOSXVersionLT(10, 7)) { |
| 147 | // x86-32 OSX has a scheme where fwrite and fputs (and some other functions |
| 148 | // we don't care about) have two versions; on recent OSX, the one we want |
| 149 | // has a $UNIX2003 suffix. The two implementations are identical except |
| 150 | // for the return value in some edge cases. However, we don't want to |
| 151 | // generate code that depends on the old symbols. |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 152 | TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); |
| 153 | TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Duncan Sands | 9fe8897 | 2011-06-09 11:11:45 +0000 | [diff] [blame] | 156 | // iprintf and friends are only available on XCore and TCE. |
| 157 | if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 158 | TLI.setUnavailable(LibFunc_iprintf); |
| 159 | TLI.setUnavailable(LibFunc_siprintf); |
| 160 | TLI.setUnavailable(LibFunc_fiprintf); |
Richard Osborne | 419454a | 2011-03-03 14:09:28 +0000 | [diff] [blame] | 161 | } |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 162 | |
Saleem Abdulrasool | 24ade3b | 2014-07-24 22:09:06 +0000 | [diff] [blame] | 163 | if (T.isOSWindows() && !T.isOSCygMing()) { |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 164 | // XXX: The earliest documentation available at the moment is for VS2015/VC19: |
| 165 | // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015 |
| 166 | // XXX: In order to use an MSVCRT older than VC19, |
| 167 | // the specific library version must be explicit in the target triple, |
| 168 | // e.g., x86_64-pc-windows-msvc18. |
| 169 | bool hasPartialC99 = true; |
| 170 | if (T.isKnownWindowsMSVCEnvironment()) { |
| 171 | unsigned Major, Minor, Micro; |
| 172 | T.getEnvironmentVersion(Major, Minor, Micro); |
| 173 | hasPartialC99 = (Major == 0 || Major >= 19); |
| 174 | } |
| 175 | |
| 176 | // Latest targets support C89 math functions, in part. |
| 177 | bool isARM = (T.getArch() == Triple::aarch64 || |
| 178 | T.getArch() == Triple::arm); |
| 179 | bool hasPartialFloat = (isARM || |
| 180 | T.getArch() == Triple::x86_64); |
| 181 | |
| 182 | // Win32 does not support float C89 math functions, in general. |
| 183 | if (!hasPartialFloat) { |
| 184 | TLI.setUnavailable(LibFunc_acosf); |
| 185 | TLI.setUnavailable(LibFunc_asinf); |
| 186 | TLI.setUnavailable(LibFunc_atan2f); |
| 187 | TLI.setUnavailable(LibFunc_atanf); |
| 188 | TLI.setUnavailable(LibFunc_ceilf); |
| 189 | TLI.setUnavailable(LibFunc_cosf); |
| 190 | TLI.setUnavailable(LibFunc_coshf); |
| 191 | TLI.setUnavailable(LibFunc_expf); |
| 192 | TLI.setUnavailable(LibFunc_floorf); |
| 193 | TLI.setUnavailable(LibFunc_fmodf); |
| 194 | TLI.setUnavailable(LibFunc_log10f); |
| 195 | TLI.setUnavailable(LibFunc_logf); |
| 196 | TLI.setUnavailable(LibFunc_modff); |
| 197 | TLI.setUnavailable(LibFunc_powf); |
| 198 | TLI.setUnavailable(LibFunc_sinf); |
| 199 | TLI.setUnavailable(LibFunc_sinhf); |
| 200 | TLI.setUnavailable(LibFunc_sqrtf); |
| 201 | TLI.setUnavailable(LibFunc_tanf); |
| 202 | TLI.setUnavailable(LibFunc_tanhf); |
| 203 | } |
| 204 | if (!isARM) |
| 205 | TLI.setUnavailable(LibFunc_fabsf); |
| 206 | TLI.setUnavailable(LibFunc_frexpf); |
| 207 | TLI.setUnavailable(LibFunc_ldexpf); |
| 208 | |
| 209 | // Win32 does not support long double C89 math functions. |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 210 | TLI.setUnavailable(LibFunc_acosl); |
| 211 | TLI.setUnavailable(LibFunc_asinl); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 212 | TLI.setUnavailable(LibFunc_atan2l); |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 213 | TLI.setUnavailable(LibFunc_atanl); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 214 | TLI.setUnavailable(LibFunc_ceill); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 215 | TLI.setUnavailable(LibFunc_cosl); |
| 216 | TLI.setUnavailable(LibFunc_coshl); |
| 217 | TLI.setUnavailable(LibFunc_expl); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 218 | TLI.setUnavailable(LibFunc_fabsl); |
| 219 | TLI.setUnavailable(LibFunc_floorl); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 220 | TLI.setUnavailable(LibFunc_fmodl); |
| 221 | TLI.setUnavailable(LibFunc_frexpl); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 222 | TLI.setUnavailable(LibFunc_ldexpl); |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 223 | TLI.setUnavailable(LibFunc_log10l); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 224 | TLI.setUnavailable(LibFunc_logl); |
| 225 | TLI.setUnavailable(LibFunc_modfl); |
| 226 | TLI.setUnavailable(LibFunc_powl); |
| 227 | TLI.setUnavailable(LibFunc_sinl); |
| 228 | TLI.setUnavailable(LibFunc_sinhl); |
| 229 | TLI.setUnavailable(LibFunc_sqrtl); |
| 230 | TLI.setUnavailable(LibFunc_tanl); |
| 231 | TLI.setUnavailable(LibFunc_tanhl); |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 232 | |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 233 | // Win32 does not fully support C99 math functions. |
| 234 | if (!hasPartialC99) { |
| 235 | TLI.setUnavailable(LibFunc_acosh); |
| 236 | TLI.setUnavailable(LibFunc_acoshf); |
| 237 | TLI.setUnavailable(LibFunc_asinh); |
| 238 | TLI.setUnavailable(LibFunc_asinhf); |
| 239 | TLI.setUnavailable(LibFunc_atanh); |
| 240 | TLI.setUnavailable(LibFunc_atanhf); |
| 241 | TLI.setAvailableWithName(LibFunc_cabs, "_cabs"); |
| 242 | TLI.setUnavailable(LibFunc_cabsf); |
| 243 | TLI.setUnavailable(LibFunc_cbrt); |
| 244 | TLI.setUnavailable(LibFunc_cbrtf); |
| 245 | TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); |
| 246 | TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf"); |
| 247 | TLI.setUnavailable(LibFunc_exp2); |
| 248 | TLI.setUnavailable(LibFunc_exp2f); |
| 249 | TLI.setUnavailable(LibFunc_expm1); |
| 250 | TLI.setUnavailable(LibFunc_expm1f); |
| 251 | TLI.setUnavailable(LibFunc_fmax); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 252 | TLI.setUnavailable(LibFunc_fmaxf); |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 253 | TLI.setUnavailable(LibFunc_fmin); |
| 254 | TLI.setUnavailable(LibFunc_fminf); |
| 255 | TLI.setUnavailable(LibFunc_log1p); |
| 256 | TLI.setUnavailable(LibFunc_log1pf); |
| 257 | TLI.setUnavailable(LibFunc_log2); |
| 258 | TLI.setUnavailable(LibFunc_log2f); |
| 259 | TLI.setAvailableWithName(LibFunc_logb, "_logb"); |
| 260 | if (hasPartialFloat) |
| 261 | TLI.setAvailableWithName(LibFunc_logbf, "_logbf"); |
| 262 | else |
| 263 | TLI.setUnavailable(LibFunc_logbf); |
| 264 | TLI.setUnavailable(LibFunc_rint); |
| 265 | TLI.setUnavailable(LibFunc_rintf); |
| 266 | TLI.setUnavailable(LibFunc_round); |
| 267 | TLI.setUnavailable(LibFunc_roundf); |
| 268 | TLI.setUnavailable(LibFunc_trunc); |
| 269 | TLI.setUnavailable(LibFunc_truncf); |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 270 | } |
Meador Inge | 939f500 | 2012-11-10 03:11:06 +0000 | [diff] [blame] | 271 | |
Hans Wennborg | 8e09c6e | 2019-02-13 10:30:16 +0000 | [diff] [blame] | 272 | // Win32 does not support long double C99 math functions. |
| 273 | TLI.setUnavailable(LibFunc_acoshl); |
| 274 | TLI.setUnavailable(LibFunc_asinhl); |
| 275 | TLI.setUnavailable(LibFunc_atanhl); |
| 276 | TLI.setUnavailable(LibFunc_cabsl); |
| 277 | TLI.setUnavailable(LibFunc_cbrtl); |
| 278 | TLI.setUnavailable(LibFunc_copysignl); |
| 279 | TLI.setUnavailable(LibFunc_exp2l); |
| 280 | TLI.setUnavailable(LibFunc_expm1l); |
| 281 | TLI.setUnavailable(LibFunc_fmaxl); |
| 282 | TLI.setUnavailable(LibFunc_fminl); |
| 283 | TLI.setUnavailable(LibFunc_log1pl); |
| 284 | TLI.setUnavailable(LibFunc_log2l); |
| 285 | TLI.setUnavailable(LibFunc_logbl); |
| 286 | TLI.setUnavailable(LibFunc_nearbyintl); |
| 287 | TLI.setUnavailable(LibFunc_rintl); |
| 288 | TLI.setUnavailable(LibFunc_roundl); |
| 289 | TLI.setUnavailable(LibFunc_truncl); |
| 290 | |
| 291 | // Win32 does not support these functions, but |
| 292 | // they are generally available on POSIX-compliant systems. |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 293 | TLI.setUnavailable(LibFunc_access); |
| 294 | TLI.setUnavailable(LibFunc_bcmp); |
| 295 | TLI.setUnavailable(LibFunc_bcopy); |
| 296 | TLI.setUnavailable(LibFunc_bzero); |
| 297 | TLI.setUnavailable(LibFunc_chmod); |
| 298 | TLI.setUnavailable(LibFunc_chown); |
| 299 | TLI.setUnavailable(LibFunc_closedir); |
| 300 | TLI.setUnavailable(LibFunc_ctermid); |
| 301 | TLI.setUnavailable(LibFunc_fdopen); |
| 302 | TLI.setUnavailable(LibFunc_ffs); |
| 303 | TLI.setUnavailable(LibFunc_fileno); |
| 304 | TLI.setUnavailable(LibFunc_flockfile); |
| 305 | TLI.setUnavailable(LibFunc_fseeko); |
| 306 | TLI.setUnavailable(LibFunc_fstat); |
| 307 | TLI.setUnavailable(LibFunc_fstatvfs); |
| 308 | TLI.setUnavailable(LibFunc_ftello); |
| 309 | TLI.setUnavailable(LibFunc_ftrylockfile); |
| 310 | TLI.setUnavailable(LibFunc_funlockfile); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 311 | TLI.setUnavailable(LibFunc_getitimer); |
| 312 | TLI.setUnavailable(LibFunc_getlogin_r); |
| 313 | TLI.setUnavailable(LibFunc_getpwnam); |
| 314 | TLI.setUnavailable(LibFunc_gettimeofday); |
| 315 | TLI.setUnavailable(LibFunc_htonl); |
| 316 | TLI.setUnavailable(LibFunc_htons); |
| 317 | TLI.setUnavailable(LibFunc_lchown); |
| 318 | TLI.setUnavailable(LibFunc_lstat); |
| 319 | TLI.setUnavailable(LibFunc_memccpy); |
| 320 | TLI.setUnavailable(LibFunc_mkdir); |
| 321 | TLI.setUnavailable(LibFunc_ntohl); |
| 322 | TLI.setUnavailable(LibFunc_ntohs); |
| 323 | TLI.setUnavailable(LibFunc_open); |
| 324 | TLI.setUnavailable(LibFunc_opendir); |
| 325 | TLI.setUnavailable(LibFunc_pclose); |
| 326 | TLI.setUnavailable(LibFunc_popen); |
| 327 | TLI.setUnavailable(LibFunc_pread); |
| 328 | TLI.setUnavailable(LibFunc_pwrite); |
| 329 | TLI.setUnavailable(LibFunc_read); |
| 330 | TLI.setUnavailable(LibFunc_readlink); |
| 331 | TLI.setUnavailable(LibFunc_realpath); |
| 332 | TLI.setUnavailable(LibFunc_rmdir); |
| 333 | TLI.setUnavailable(LibFunc_setitimer); |
| 334 | TLI.setUnavailable(LibFunc_stat); |
| 335 | TLI.setUnavailable(LibFunc_statvfs); |
| 336 | TLI.setUnavailable(LibFunc_stpcpy); |
| 337 | TLI.setUnavailable(LibFunc_stpncpy); |
| 338 | TLI.setUnavailable(LibFunc_strcasecmp); |
| 339 | TLI.setUnavailable(LibFunc_strncasecmp); |
| 340 | TLI.setUnavailable(LibFunc_times); |
| 341 | TLI.setUnavailable(LibFunc_uname); |
| 342 | TLI.setUnavailable(LibFunc_unlink); |
| 343 | TLI.setUnavailable(LibFunc_unsetenv); |
| 344 | TLI.setUnavailable(LibFunc_utime); |
| 345 | TLI.setUnavailable(LibFunc_utimes); |
| 346 | TLI.setUnavailable(LibFunc_write); |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 349 | switch (T.getOS()) { |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 350 | case Triple::MacOSX: |
Chandler Carruth | 92ffb67 | 2013-12-28 02:40:19 +0000 | [diff] [blame] | 351 | // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 |
| 352 | // and their names are __exp10 and __exp10f. exp10l is not available on |
| 353 | // OS X or iOS. |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 354 | TLI.setUnavailable(LibFunc_exp10l); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 355 | if (T.isMacOSXVersionLT(10, 9)) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 356 | TLI.setUnavailable(LibFunc_exp10); |
| 357 | TLI.setUnavailable(LibFunc_exp10f); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 358 | } else { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 359 | TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); |
| 360 | TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 361 | } |
| 362 | break; |
| 363 | case Triple::IOS: |
Tim Northover | 68eb8a5 | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 364 | case Triple::TvOS: |
Tim Northover | 7b7ff9e | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 365 | case Triple::WatchOS: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 366 | TLI.setUnavailable(LibFunc_exp10l); |
Tim Northover | 7b7ff9e | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 367 | if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || |
| 368 | (T.isOSVersionLT(9, 0) && |
| 369 | (T.getArch() == Triple::x86 || |
| 370 | T.getArch() == Triple::x86_64)))) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 371 | TLI.setUnavailable(LibFunc_exp10); |
| 372 | TLI.setUnavailable(LibFunc_exp10f); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 373 | } else { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 374 | TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); |
| 375 | TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 376 | } |
| 377 | break; |
Chandler Carruth | 92ffb67 | 2013-12-28 02:40:19 +0000 | [diff] [blame] | 378 | case Triple::Linux: |
| 379 | // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely |
| 380 | // buggy prior to glibc version 2.18. Until this version is widely deployed |
| 381 | // or we have a reasonable detection strategy, we cannot use exp10 reliably |
| 382 | // on Linux. |
| 383 | // |
| 384 | // Fall through to disable all of them. |
Justin Bogner | 7d7a23e | 2016-08-17 20:30:52 +0000 | [diff] [blame] | 385 | LLVM_FALLTHROUGH; |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 386 | default: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 387 | TLI.setUnavailable(LibFunc_exp10); |
| 388 | TLI.setUnavailable(LibFunc_exp10f); |
| 389 | TLI.setUnavailable(LibFunc_exp10l); |
Reid Kleckner | 52b1623 | 2013-12-26 19:17:04 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 392 | // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and |
| 393 | // Linux (GLIBC): |
| 394 | // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html |
Davide Italiano | 2511ece | 2015-11-01 17:00:13 +0000 | [diff] [blame] | 395 | // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 396 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html |
| 397 | switch (T.getOS()) { |
| 398 | case Triple::Darwin: |
| 399 | case Triple::MacOSX: |
| 400 | case Triple::IOS: |
Tim Northover | 68eb8a5 | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 401 | case Triple::TvOS: |
Tim Northover | 7b7ff9e | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 402 | case Triple::WatchOS: |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 403 | case Triple::FreeBSD: |
| 404 | case Triple::Linux: |
| 405 | break; |
| 406 | default: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 407 | TLI.setUnavailable(LibFunc_ffsl); |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | // ffsll is available on at least FreeBSD and Linux (GLIBC): |
Davide Italiano | 2511ece | 2015-11-01 17:00:13 +0000 | [diff] [blame] | 411 | // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 412 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html |
| 413 | switch (T.getOS()) { |
Tim Northover | 68eb8a5 | 2015-11-02 18:00:00 +0000 | [diff] [blame] | 414 | case Triple::Darwin: |
| 415 | case Triple::MacOSX: |
| 416 | case Triple::IOS: |
| 417 | case Triple::TvOS: |
| 418 | case Triple::WatchOS: |
Meador Inge | 6098c6b | 2012-11-22 15:36:42 +0000 | [diff] [blame] | 419 | case Triple::FreeBSD: |
| 420 | case Triple::Linux: |
| 421 | break; |
| 422 | default: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 423 | TLI.setUnavailable(LibFunc_ffsll); |
Joe Groff | d5bda5e | 2012-04-17 23:05:54 +0000 | [diff] [blame] | 424 | } |
Meador Inge | cf70590 | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 425 | |
Davide Italiano | 36ee8db | 2015-11-09 23:23:20 +0000 | [diff] [blame] | 426 | // The following functions are available on at least FreeBSD: |
| 427 | // http://svn.freebsd.org/base/head/lib/libc/string/fls.c |
| 428 | // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c |
| 429 | // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c |
| 430 | if (!T.isOSFreeBSD()) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 431 | TLI.setUnavailable(LibFunc_fls); |
| 432 | TLI.setUnavailable(LibFunc_flsl); |
| 433 | TLI.setUnavailable(LibFunc_flsll); |
Davide Italiano | 36ee8db | 2015-11-09 23:23:20 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Eli Friedman | d9f217d | 2018-11-06 18:23:32 +0000 | [diff] [blame] | 436 | // The following functions are only available on GNU/Linux (using glibc). |
| 437 | // Linux variants without glibc (eg: bionic, musl) may have some subset. |
| 438 | if (!T.isOSLinux() || !T.isGNUEnvironment()) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 439 | TLI.setUnavailable(LibFunc_dunder_strdup); |
| 440 | TLI.setUnavailable(LibFunc_dunder_strtok_r); |
| 441 | TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); |
| 442 | TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); |
| 443 | TLI.setUnavailable(LibFunc_under_IO_getc); |
| 444 | TLI.setUnavailable(LibFunc_under_IO_putc); |
Eli Friedman | d9f217d | 2018-11-06 18:23:32 +0000 | [diff] [blame] | 445 | // But, Android and musl have memalign. |
| 446 | if (!T.isAndroid() && !T.isMusl()) |
Chih-Hung Hsieh | a0ae1f8 | 2018-01-31 19:12:50 +0000 | [diff] [blame] | 447 | TLI.setUnavailable(LibFunc_memalign); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 448 | TLI.setUnavailable(LibFunc_fopen64); |
| 449 | TLI.setUnavailable(LibFunc_fseeko64); |
| 450 | TLI.setUnavailable(LibFunc_fstat64); |
| 451 | TLI.setUnavailable(LibFunc_fstatvfs64); |
| 452 | TLI.setUnavailable(LibFunc_ftello64); |
| 453 | TLI.setUnavailable(LibFunc_lstat64); |
| 454 | TLI.setUnavailable(LibFunc_open64); |
| 455 | TLI.setUnavailable(LibFunc_stat64); |
| 456 | TLI.setUnavailable(LibFunc_statvfs64); |
| 457 | TLI.setUnavailable(LibFunc_tmpfile64); |
Sanjay Patel | cc2e1c2 | 2018-01-08 17:38:09 +0000 | [diff] [blame] | 458 | |
| 459 | // Relaxed math functions are included in math-finite.h on Linux (GLIBC). |
| 460 | TLI.setUnavailable(LibFunc_acos_finite); |
| 461 | TLI.setUnavailable(LibFunc_acosf_finite); |
| 462 | TLI.setUnavailable(LibFunc_acosl_finite); |
| 463 | TLI.setUnavailable(LibFunc_acosh_finite); |
| 464 | TLI.setUnavailable(LibFunc_acoshf_finite); |
| 465 | TLI.setUnavailable(LibFunc_acoshl_finite); |
| 466 | TLI.setUnavailable(LibFunc_asin_finite); |
| 467 | TLI.setUnavailable(LibFunc_asinf_finite); |
| 468 | TLI.setUnavailable(LibFunc_asinl_finite); |
| 469 | TLI.setUnavailable(LibFunc_atan2_finite); |
| 470 | TLI.setUnavailable(LibFunc_atan2f_finite); |
| 471 | TLI.setUnavailable(LibFunc_atan2l_finite); |
| 472 | TLI.setUnavailable(LibFunc_atanh_finite); |
| 473 | TLI.setUnavailable(LibFunc_atanhf_finite); |
| 474 | TLI.setUnavailable(LibFunc_atanhl_finite); |
| 475 | TLI.setUnavailable(LibFunc_cosh_finite); |
| 476 | TLI.setUnavailable(LibFunc_coshf_finite); |
| 477 | TLI.setUnavailable(LibFunc_coshl_finite); |
| 478 | TLI.setUnavailable(LibFunc_exp10_finite); |
| 479 | TLI.setUnavailable(LibFunc_exp10f_finite); |
| 480 | TLI.setUnavailable(LibFunc_exp10l_finite); |
| 481 | TLI.setUnavailable(LibFunc_exp2_finite); |
| 482 | TLI.setUnavailable(LibFunc_exp2f_finite); |
| 483 | TLI.setUnavailable(LibFunc_exp2l_finite); |
| 484 | TLI.setUnavailable(LibFunc_exp_finite); |
| 485 | TLI.setUnavailable(LibFunc_expf_finite); |
| 486 | TLI.setUnavailable(LibFunc_expl_finite); |
| 487 | TLI.setUnavailable(LibFunc_log10_finite); |
| 488 | TLI.setUnavailable(LibFunc_log10f_finite); |
| 489 | TLI.setUnavailable(LibFunc_log10l_finite); |
| 490 | TLI.setUnavailable(LibFunc_log2_finite); |
| 491 | TLI.setUnavailable(LibFunc_log2f_finite); |
| 492 | TLI.setUnavailable(LibFunc_log2l_finite); |
| 493 | TLI.setUnavailable(LibFunc_log_finite); |
| 494 | TLI.setUnavailable(LibFunc_logf_finite); |
| 495 | TLI.setUnavailable(LibFunc_logl_finite); |
| 496 | TLI.setUnavailable(LibFunc_pow_finite); |
| 497 | TLI.setUnavailable(LibFunc_powf_finite); |
| 498 | TLI.setUnavailable(LibFunc_powl_finite); |
| 499 | TLI.setUnavailable(LibFunc_sinh_finite); |
| 500 | TLI.setUnavailable(LibFunc_sinhf_finite); |
| 501 | TLI.setUnavailable(LibFunc_sinhl_finite); |
Meador Inge | cf70590 | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 502 | } |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 503 | |
Martin Storsjo | a925a3b | 2018-05-17 08:16:08 +0000 | [diff] [blame] | 504 | if ((T.isOSLinux() && T.isGNUEnvironment()) || |
| 505 | (T.isAndroid() && !T.isAndroidVersionLT(28))) { |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 506 | // available IO unlocked variants on GNU/Linux and Android P or later |
| 507 | TLI.setAvailable(LibFunc_getc_unlocked); |
| 508 | TLI.setAvailable(LibFunc_getchar_unlocked); |
| 509 | TLI.setAvailable(LibFunc_putc_unlocked); |
| 510 | TLI.setAvailable(LibFunc_putchar_unlocked); |
| 511 | TLI.setAvailable(LibFunc_fputc_unlocked); |
| 512 | TLI.setAvailable(LibFunc_fgetc_unlocked); |
| 513 | TLI.setAvailable(LibFunc_fread_unlocked); |
| 514 | TLI.setAvailable(LibFunc_fwrite_unlocked); |
| 515 | TLI.setAvailable(LibFunc_fputs_unlocked); |
| 516 | TLI.setAvailable(LibFunc_fgets_unlocked); |
| 517 | } |
| 518 | |
Justin Lebar | da5ebe5 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 519 | // As currently implemented in clang, NVPTX code has no standard library to |
| 520 | // speak of. Headers provide a standard-ish library implementation, but many |
| 521 | // of the signatures are wrong -- for example, many libm functions are not |
| 522 | // extern "C". |
| 523 | // |
| 524 | // libdevice, an IR library provided by nvidia, is linked in by the front-end, |
| 525 | // but only used functions are provided to llvm. Moreover, most of the |
| 526 | // functions in libdevice don't map precisely to standard library functions. |
| 527 | // |
| 528 | // FIXME: Having no standard library prevents e.g. many fastmath |
| 529 | // optimizations, so this situation should be fixed. |
David Majnemer | 54136ef | 2016-03-31 21:29:57 +0000 | [diff] [blame] | 530 | if (T.isNVPTX()) { |
Justin Lebar | da5ebe5 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 531 | TLI.disableAllFunctions(); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 532 | TLI.setAvailable(LibFunc_nvvm_reflect); |
David Majnemer | 54136ef | 2016-03-31 21:29:57 +0000 | [diff] [blame] | 533 | } else { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 534 | TLI.setUnavailable(LibFunc_nvvm_reflect); |
David Majnemer | 54136ef | 2016-03-31 21:29:57 +0000 | [diff] [blame] | 535 | } |
Justin Lebar | da5ebe5 | 2016-01-26 23:51:06 +0000 | [diff] [blame] | 536 | |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 537 | TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 540 | TargetLibraryInfoImpl::TargetLibraryInfoImpl() { |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 541 | // Default to everything being available. |
| 542 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
| 543 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 544 | initialize(*this, Triple(), StandardNames); |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Joel Jones | 9951b07 | 2018-11-24 07:26:55 +0000 | [diff] [blame] | 547 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 548 | // Default to everything being available. |
| 549 | memset(AvailableArray, -1, sizeof(AvailableArray)); |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 550 | |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 551 | initialize(*this, T, StandardNames); |
Chris Lattner | ce99120 | 2011-02-18 21:50:34 +0000 | [diff] [blame] | 552 | } |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 553 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 554 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) |
Joel Jones | 9951b07 | 2018-11-24 07:26:55 +0000 | [diff] [blame] | 555 | : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), |
Marcin Koscielnicki | ac9341f | 2016-11-21 11:57:11 +0000 | [diff] [blame] | 556 | ShouldExtI32Return(TLI.ShouldExtI32Return), |
| 557 | ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 558 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 559 | VectorDescs = TLI.VectorDescs; |
| 560 | ScalarDescs = TLI.ScalarDescs; |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 563 | TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) |
Joel Jones | 9951b07 | 2018-11-24 07:26:55 +0000 | [diff] [blame] | 564 | : CustomNames(std::move(TLI.CustomNames)), |
Marcin Koscielnicki | ac9341f | 2016-11-21 11:57:11 +0000 | [diff] [blame] | 565 | ShouldExtI32Param(TLI.ShouldExtI32Param), |
| 566 | ShouldExtI32Return(TLI.ShouldExtI32Return), |
| 567 | ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 568 | std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), |
| 569 | AvailableArray); |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 570 | VectorDescs = TLI.VectorDescs; |
| 571 | ScalarDescs = TLI.ScalarDescs; |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 574 | TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { |
Eli Friedman | 9d434db | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 575 | CustomNames = TLI.CustomNames; |
Marcin Koscielnicki | ac9341f | 2016-11-21 11:57:11 +0000 | [diff] [blame] | 576 | ShouldExtI32Param = TLI.ShouldExtI32Param; |
| 577 | ShouldExtI32Return = TLI.ShouldExtI32Return; |
| 578 | ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 579 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); |
| 580 | return *this; |
| 581 | } |
| 582 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 583 | TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 584 | CustomNames = std::move(TLI.CustomNames); |
Marcin Koscielnicki | ac9341f | 2016-11-21 11:57:11 +0000 | [diff] [blame] | 585 | ShouldExtI32Param = TLI.ShouldExtI32Param; |
| 586 | ShouldExtI32Return = TLI.ShouldExtI32Return; |
| 587 | ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 588 | std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), |
| 589 | AvailableArray); |
| 590 | return *this; |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Michael Zolotukhin | a6f1fd6 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 593 | static StringRef sanitizeFunctionName(StringRef funcName) { |
Benjamin Kramer | 576f62c | 2013-03-09 13:48:23 +0000 | [diff] [blame] | 594 | // Filter out empty names and names containing null bytes, those can't be in |
| 595 | // our table. |
| 596 | if (funcName.empty() || funcName.find('\0') != StringRef::npos) |
Michael Zolotukhin | a6f1fd6 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 597 | return StringRef(); |
Benjamin Kramer | 576f62c | 2013-03-09 13:48:23 +0000 | [diff] [blame] | 598 | |
Meador Inge | cf70590 | 2013-03-05 21:47:40 +0000 | [diff] [blame] | 599 | // Check for \01 prefix that is used to mangle __asm declarations and |
| 600 | // strip it if present. |
Peter Collingbourne | 6ba81f2 | 2017-05-16 00:39:01 +0000 | [diff] [blame] | 601 | return GlobalValue::dropLLVMManglingEscape(funcName); |
Michael Zolotukhin | a6f1fd6 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 605 | LibFunc &F) const { |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 606 | StringRef const *Start = &StandardNames[0]; |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 607 | StringRef const *End = &StandardNames[NumLibFuncs]; |
Michael Zolotukhin | a6f1fd6 | 2015-03-02 23:24:40 +0000 | [diff] [blame] | 608 | |
| 609 | funcName = sanitizeFunctionName(funcName); |
| 610 | if (funcName.empty()) |
| 611 | return false; |
| 612 | |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 613 | StringRef const *I = std::lower_bound( |
| 614 | Start, End, funcName, [](StringRef LHS, StringRef RHS) { |
| 615 | return LHS < RHS; |
Michael Zolotukhin | f027454 | 2015-03-02 20:50:08 +0000 | [diff] [blame] | 616 | }); |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 617 | if (I != End && *I == funcName) { |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 618 | F = (LibFunc)(I - Start); |
Bob Wilson | d1e672e | 2012-08-03 04:06:22 +0000 | [diff] [blame] | 619 | return true; |
| 620 | } |
| 621 | return false; |
| 622 | } |
Chris Lattner | 40f5fbc | 2011-05-21 20:09:13 +0000 | [diff] [blame] | 623 | |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 624 | bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 625 | LibFunc F, |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 626 | const DataLayout *DL) const { |
| 627 | LLVMContext &Ctx = FTy.getContext(); |
| 628 | Type *PCharTy = Type::getInt8PtrTy(Ctx); |
| 629 | Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; |
| 630 | auto IsSizeTTy = [SizeTTy](Type *Ty) { |
| 631 | return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); |
| 632 | }; |
| 633 | unsigned NumParams = FTy.getNumParams(); |
| 634 | |
| 635 | switch (F) { |
Calixte Denizet | bb74632 | 2018-11-07 13:49:17 +0000 | [diff] [blame] | 636 | case LibFunc_execl: |
| 637 | case LibFunc_execlp: |
Calixte Denizet | 5cd01d9 | 2018-11-07 14:46:26 +0000 | [diff] [blame] | 638 | case LibFunc_execle: |
Calixte Denizet | bb74632 | 2018-11-07 13:49:17 +0000 | [diff] [blame] | 639 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 640 | FTy.getParamType(1)->isPointerTy() && |
| 641 | FTy.getReturnType()->isIntegerTy(32)); |
Calixte Denizet | bb74632 | 2018-11-07 13:49:17 +0000 | [diff] [blame] | 642 | case LibFunc_execv: |
| 643 | case LibFunc_execvp: |
| 644 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 645 | FTy.getParamType(1)->isPointerTy() && |
| 646 | FTy.getReturnType()->isIntegerTy(32)); |
| 647 | case LibFunc_execvP: |
| 648 | case LibFunc_execvpe: |
| 649 | case LibFunc_execve: |
| 650 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 651 | FTy.getParamType(1)->isPointerTy() && |
| 652 | FTy.getParamType(2)->isPointerTy() && |
| 653 | FTy.getReturnType()->isIntegerTy(32)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 654 | case LibFunc_strlen: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 655 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && |
| 656 | FTy.getReturnType()->isIntegerTy()); |
| 657 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 658 | case LibFunc_strchr: |
| 659 | case LibFunc_strrchr: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 660 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 661 | FTy.getParamType(0) == FTy.getReturnType() && |
| 662 | FTy.getParamType(1)->isIntegerTy()); |
| 663 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 664 | case LibFunc_strtol: |
| 665 | case LibFunc_strtod: |
| 666 | case LibFunc_strtof: |
| 667 | case LibFunc_strtoul: |
| 668 | case LibFunc_strtoll: |
| 669 | case LibFunc_strtold: |
| 670 | case LibFunc_strtoull: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 671 | return ((NumParams == 2 || NumParams == 3) && |
| 672 | FTy.getParamType(0)->isPointerTy() && |
| 673 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 674 | case LibFunc_strcat: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 675 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 676 | FTy.getParamType(0) == FTy.getReturnType() && |
| 677 | FTy.getParamType(1) == FTy.getReturnType()); |
| 678 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 679 | case LibFunc_strncat: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 680 | return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && |
| 681 | FTy.getParamType(0) == FTy.getReturnType() && |
| 682 | FTy.getParamType(1) == FTy.getReturnType() && |
Igor Laevsky | b887495 | 2017-12-18 10:31:58 +0000 | [diff] [blame] | 683 | IsSizeTTy(FTy.getParamType(2))); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 684 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 685 | case LibFunc_strcpy_chk: |
| 686 | case LibFunc_stpcpy_chk: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 687 | --NumParams; |
| 688 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 689 | return false; |
Justin Bogner | 6673ea8 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 690 | LLVM_FALLTHROUGH; |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 691 | case LibFunc_strcpy: |
| 692 | case LibFunc_stpcpy: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 693 | return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && |
| 694 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 695 | FTy.getParamType(0) == PCharTy); |
| 696 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 697 | case LibFunc_strncpy_chk: |
| 698 | case LibFunc_stpncpy_chk: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 699 | --NumParams; |
| 700 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 701 | return false; |
Justin Bogner | 6673ea8 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 702 | LLVM_FALLTHROUGH; |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 703 | case LibFunc_strncpy: |
| 704 | case LibFunc_stpncpy: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 705 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 706 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 707 | FTy.getParamType(0) == PCharTy && |
Igor Laevsky | b887495 | 2017-12-18 10:31:58 +0000 | [diff] [blame] | 708 | IsSizeTTy(FTy.getParamType(2))); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 709 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 710 | case LibFunc_strxfrm: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 711 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 712 | FTy.getParamType(1)->isPointerTy()); |
| 713 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 714 | case LibFunc_strcmp: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 715 | return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && |
| 716 | FTy.getParamType(0)->isPointerTy() && |
| 717 | FTy.getParamType(0) == FTy.getParamType(1)); |
| 718 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 719 | case LibFunc_strncmp: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 720 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && |
| 721 | FTy.getParamType(0)->isPointerTy() && |
| 722 | FTy.getParamType(0) == FTy.getParamType(1) && |
Igor Laevsky | b887495 | 2017-12-18 10:31:58 +0000 | [diff] [blame] | 723 | IsSizeTTy(FTy.getParamType(2))); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 724 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 725 | case LibFunc_strspn: |
| 726 | case LibFunc_strcspn: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 727 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 728 | FTy.getParamType(0) == FTy.getParamType(1) && |
| 729 | FTy.getReturnType()->isIntegerTy()); |
| 730 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 731 | case LibFunc_strcoll: |
| 732 | case LibFunc_strcasecmp: |
| 733 | case LibFunc_strncasecmp: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 734 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 735 | FTy.getParamType(1)->isPointerTy()); |
| 736 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 737 | case LibFunc_strstr: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 738 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 739 | FTy.getParamType(0)->isPointerTy() && |
| 740 | FTy.getParamType(1)->isPointerTy()); |
| 741 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 742 | case LibFunc_strpbrk: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 743 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 744 | FTy.getReturnType() == FTy.getParamType(0) && |
| 745 | FTy.getParamType(0) == FTy.getParamType(1)); |
| 746 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 747 | case LibFunc_strtok: |
| 748 | case LibFunc_strtok_r: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 749 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 750 | case LibFunc_scanf: |
| 751 | case LibFunc_setbuf: |
| 752 | case LibFunc_setvbuf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 753 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 754 | case LibFunc_strdup: |
| 755 | case LibFunc_strndup: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 756 | return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && |
| 757 | FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 758 | case LibFunc_sscanf: |
| 759 | case LibFunc_stat: |
| 760 | case LibFunc_statvfs: |
| 761 | case LibFunc_siprintf: |
| 762 | case LibFunc_sprintf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 763 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
Martin Storsjo | d2bdcd6 | 2018-05-11 16:53:56 +0000 | [diff] [blame] | 764 | FTy.getParamType(1)->isPointerTy() && |
| 765 | FTy.getReturnType()->isIntegerTy(32)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 766 | case LibFunc_snprintf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 767 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
Martin Storsjo | d2bdcd6 | 2018-05-11 16:53:56 +0000 | [diff] [blame] | 768 | FTy.getParamType(2)->isPointerTy() && |
| 769 | FTy.getReturnType()->isIntegerTy(32)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 770 | case LibFunc_setitimer: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 771 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 772 | FTy.getParamType(2)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 773 | case LibFunc_system: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 774 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 775 | case LibFunc_malloc: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 776 | return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 777 | case LibFunc_memcmp: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 778 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && |
| 779 | FTy.getParamType(0)->isPointerTy() && |
| 780 | FTy.getParamType(1)->isPointerTy()); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 781 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 782 | case LibFunc_memchr: |
| 783 | case LibFunc_memrchr: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 784 | return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && |
| 785 | FTy.getReturnType() == FTy.getParamType(0) && |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 786 | FTy.getParamType(1)->isIntegerTy(32) && |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 787 | IsSizeTTy(FTy.getParamType(2))); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 788 | case LibFunc_modf: |
| 789 | case LibFunc_modff: |
| 790 | case LibFunc_modfl: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 791 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
| 792 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 793 | case LibFunc_memcpy_chk: |
| 794 | case LibFunc_memmove_chk: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 795 | --NumParams; |
| 796 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 797 | return false; |
Justin Bogner | 6673ea8 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 798 | LLVM_FALLTHROUGH; |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 799 | case LibFunc_memcpy: |
| 800 | case LibFunc_mempcpy: |
| 801 | case LibFunc_memmove: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 802 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 803 | FTy.getParamType(0)->isPointerTy() && |
| 804 | FTy.getParamType(1)->isPointerTy() && |
| 805 | IsSizeTTy(FTy.getParamType(2))); |
| 806 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 807 | case LibFunc_memset_chk: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 808 | --NumParams; |
| 809 | if (!IsSizeTTy(FTy.getParamType(NumParams))) |
| 810 | return false; |
Justin Bogner | 6673ea8 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 811 | LLVM_FALLTHROUGH; |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 812 | case LibFunc_memset: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 813 | return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && |
| 814 | FTy.getParamType(0)->isPointerTy() && |
| 815 | FTy.getParamType(1)->isIntegerTy() && |
| 816 | IsSizeTTy(FTy.getParamType(2))); |
| 817 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 818 | case LibFunc_memccpy: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 819 | return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 820 | case LibFunc_memalign: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 821 | return (FTy.getReturnType()->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 822 | case LibFunc_realloc: |
| 823 | case LibFunc_reallocf: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 824 | return (NumParams == 2 && FTy.getReturnType() == PCharTy && |
| 825 | FTy.getParamType(0) == FTy.getReturnType() && |
| 826 | IsSizeTTy(FTy.getParamType(1))); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 827 | case LibFunc_read: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 828 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 829 | case LibFunc_rewind: |
| 830 | case LibFunc_rmdir: |
| 831 | case LibFunc_remove: |
| 832 | case LibFunc_realpath: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 833 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 834 | case LibFunc_rename: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 835 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 836 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 837 | case LibFunc_readlink: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 838 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 839 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 840 | case LibFunc_write: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 841 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 842 | case LibFunc_bcopy: |
| 843 | case LibFunc_bcmp: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 844 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 845 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 846 | case LibFunc_bzero: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 847 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 848 | case LibFunc_calloc: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 849 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); |
Ahmed Bougacha | c863f71 | 2016-05-25 20:22:45 +0000 | [diff] [blame] | 850 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 851 | case LibFunc_atof: |
| 852 | case LibFunc_atoi: |
| 853 | case LibFunc_atol: |
| 854 | case LibFunc_atoll: |
| 855 | case LibFunc_ferror: |
| 856 | case LibFunc_getenv: |
| 857 | case LibFunc_getpwnam: |
| 858 | case LibFunc_iprintf: |
| 859 | case LibFunc_pclose: |
| 860 | case LibFunc_perror: |
| 861 | case LibFunc_printf: |
| 862 | case LibFunc_puts: |
| 863 | case LibFunc_uname: |
| 864 | case LibFunc_under_IO_getc: |
| 865 | case LibFunc_unlink: |
| 866 | case LibFunc_unsetenv: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 867 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
Ahmed Bougacha | c863f71 | 2016-05-25 20:22:45 +0000 | [diff] [blame] | 868 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 869 | case LibFunc_access: |
| 870 | case LibFunc_chmod: |
| 871 | case LibFunc_chown: |
| 872 | case LibFunc_clearerr: |
| 873 | case LibFunc_closedir: |
| 874 | case LibFunc_ctermid: |
| 875 | case LibFunc_fclose: |
| 876 | case LibFunc_feof: |
| 877 | case LibFunc_fflush: |
| 878 | case LibFunc_fgetc: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 879 | case LibFunc_fgetc_unlocked: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 880 | case LibFunc_fileno: |
| 881 | case LibFunc_flockfile: |
| 882 | case LibFunc_free: |
| 883 | case LibFunc_fseek: |
| 884 | case LibFunc_fseeko64: |
| 885 | case LibFunc_fseeko: |
| 886 | case LibFunc_fsetpos: |
| 887 | case LibFunc_ftell: |
| 888 | case LibFunc_ftello64: |
| 889 | case LibFunc_ftello: |
| 890 | case LibFunc_ftrylockfile: |
| 891 | case LibFunc_funlockfile: |
| 892 | case LibFunc_getc: |
| 893 | case LibFunc_getc_unlocked: |
| 894 | case LibFunc_getlogin_r: |
| 895 | case LibFunc_mkdir: |
| 896 | case LibFunc_mktime: |
| 897 | case LibFunc_times: |
Ahmed Bougacha | c863f71 | 2016-05-25 20:22:45 +0000 | [diff] [blame] | 898 | return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); |
| 899 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 900 | case LibFunc_fopen: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 901 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 902 | FTy.getParamType(0)->isPointerTy() && |
| 903 | FTy.getParamType(1)->isPointerTy()); |
Calixte Denizet | bb74632 | 2018-11-07 13:49:17 +0000 | [diff] [blame] | 904 | case LibFunc_fork: |
| 905 | return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 906 | case LibFunc_fdopen: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 907 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 908 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 909 | case LibFunc_fputc: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 910 | case LibFunc_fputc_unlocked: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 911 | case LibFunc_fstat: |
| 912 | case LibFunc_frexp: |
| 913 | case LibFunc_frexpf: |
| 914 | case LibFunc_frexpl: |
| 915 | case LibFunc_fstatvfs: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 916 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 917 | case LibFunc_fgets: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 918 | case LibFunc_fgets_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 919 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 920 | FTy.getParamType(2)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 921 | case LibFunc_fread: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 922 | case LibFunc_fread_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 923 | return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && |
| 924 | FTy.getParamType(3)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 925 | case LibFunc_fwrite: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 926 | case LibFunc_fwrite_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 927 | return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && |
| 928 | FTy.getParamType(0)->isPointerTy() && |
| 929 | FTy.getParamType(1)->isIntegerTy() && |
| 930 | FTy.getParamType(2)->isIntegerTy() && |
| 931 | FTy.getParamType(3)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 932 | case LibFunc_fputs: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 933 | case LibFunc_fputs_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 934 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 935 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 936 | case LibFunc_fscanf: |
| 937 | case LibFunc_fiprintf: |
| 938 | case LibFunc_fprintf: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 939 | return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && |
| 940 | FTy.getParamType(0)->isPointerTy() && |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 941 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 942 | case LibFunc_fgetpos: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 943 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
| 944 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 945 | case LibFunc_getchar: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 946 | case LibFunc_getchar_unlocked: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 947 | return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 948 | case LibFunc_gets: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 949 | return (NumParams == 1 && FTy.getParamType(0) == PCharTy); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 950 | case LibFunc_getitimer: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 951 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 952 | case LibFunc_ungetc: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 953 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 954 | case LibFunc_utime: |
| 955 | case LibFunc_utimes: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 956 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 957 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 958 | case LibFunc_putc: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 959 | case LibFunc_putc_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 960 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 961 | case LibFunc_pread: |
| 962 | case LibFunc_pwrite: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 963 | return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 964 | case LibFunc_popen: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 965 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 966 | FTy.getParamType(0)->isPointerTy() && |
| 967 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 968 | case LibFunc_vscanf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 969 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 970 | case LibFunc_vsscanf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 971 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 972 | FTy.getParamType(2)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 973 | case LibFunc_vfscanf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 974 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && |
| 975 | FTy.getParamType(2)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 976 | case LibFunc_valloc: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 977 | return (FTy.getReturnType()->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 978 | case LibFunc_vprintf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 979 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 980 | case LibFunc_vfprintf: |
| 981 | case LibFunc_vsprintf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 982 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && |
| 983 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 984 | case LibFunc_vsnprintf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 985 | return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && |
| 986 | FTy.getParamType(2)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 987 | case LibFunc_open: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 988 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 989 | case LibFunc_opendir: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 990 | return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && |
| 991 | FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 992 | case LibFunc_tmpfile: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 993 | return (FTy.getReturnType()->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 994 | case LibFunc_htonl: |
| 995 | case LibFunc_ntohl: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 996 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && |
| 997 | FTy.getReturnType() == FTy.getParamType(0)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 998 | case LibFunc_htons: |
| 999 | case LibFunc_ntohs: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1000 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && |
| 1001 | FTy.getReturnType() == FTy.getParamType(0)); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1002 | case LibFunc_lstat: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1003 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 1004 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1005 | case LibFunc_lchown: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1006 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1007 | case LibFunc_qsort: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1008 | return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1009 | case LibFunc_dunder_strdup: |
| 1010 | case LibFunc_dunder_strndup: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1011 | return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && |
| 1012 | FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1013 | case LibFunc_dunder_strtok_r: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1014 | return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1015 | case LibFunc_under_IO_putc: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1016 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1017 | case LibFunc_dunder_isoc99_scanf: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1018 | return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1019 | case LibFunc_stat64: |
| 1020 | case LibFunc_lstat64: |
| 1021 | case LibFunc_statvfs64: |
Michael Kuperstein | 86978b7 | 2016-09-20 23:10:31 +0000 | [diff] [blame] | 1022 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1023 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1024 | case LibFunc_dunder_isoc99_sscanf: |
Michael Kuperstein | 86978b7 | 2016-09-20 23:10:31 +0000 | [diff] [blame] | 1025 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1026 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1027 | case LibFunc_fopen64: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1028 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && |
| 1029 | FTy.getParamType(0)->isPointerTy() && |
| 1030 | FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1031 | case LibFunc_tmpfile64: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1032 | return (FTy.getReturnType()->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1033 | case LibFunc_fstat64: |
| 1034 | case LibFunc_fstatvfs64: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1035 | return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1036 | case LibFunc_open64: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1037 | return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1038 | case LibFunc_gettimeofday: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1039 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && |
| 1040 | FTy.getParamType(1)->isPointerTy()); |
| 1041 | |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1042 | // new(unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1043 | case LibFunc_Znwj: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1044 | // new(unsigned long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1045 | case LibFunc_Znwm: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1046 | // new[](unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1047 | case LibFunc_Znaj: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1048 | // new[](unsigned long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1049 | case LibFunc_Znam: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1050 | // new(unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1051 | case LibFunc_msvc_new_int: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1052 | // new(unsigned long long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1053 | case LibFunc_msvc_new_longlong: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1054 | // new[](unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1055 | case LibFunc_msvc_new_array_int: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1056 | // new[](unsigned long long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1057 | case LibFunc_msvc_new_array_longlong: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1058 | return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); |
| 1059 | |
| 1060 | // new(unsigned int, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1061 | case LibFunc_ZnwjRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1062 | // new(unsigned long, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1063 | case LibFunc_ZnwmRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1064 | // new[](unsigned int, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1065 | case LibFunc_ZnajRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1066 | // new[](unsigned long, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1067 | case LibFunc_ZnamRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1068 | // new(unsigned int, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1069 | case LibFunc_msvc_new_int_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1070 | // new(unsigned long long, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1071 | case LibFunc_msvc_new_longlong_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1072 | // new[](unsigned int, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1073 | case LibFunc_msvc_new_array_int_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1074 | // new[](unsigned long long, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1075 | case LibFunc_msvc_new_array_longlong_nothrow: |
Eric Fiselier | 75627b1 | 2018-04-04 19:01:51 +0000 | [diff] [blame] | 1076 | // new(unsigned int, align_val_t) |
| 1077 | case LibFunc_ZnwjSt11align_val_t: |
| 1078 | // new(unsigned long, align_val_t) |
| 1079 | case LibFunc_ZnwmSt11align_val_t: |
| 1080 | // new[](unsigned int, align_val_t) |
| 1081 | case LibFunc_ZnajSt11align_val_t: |
| 1082 | // new[](unsigned long, align_val_t) |
| 1083 | case LibFunc_ZnamSt11align_val_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1084 | return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); |
| 1085 | |
Eric Fiselier | 75627b1 | 2018-04-04 19:01:51 +0000 | [diff] [blame] | 1086 | // new(unsigned int, align_val_t, nothrow) |
| 1087 | case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: |
| 1088 | // new(unsigned long, align_val_t, nothrow) |
| 1089 | case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: |
| 1090 | // new[](unsigned int, align_val_t, nothrow) |
| 1091 | case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: |
| 1092 | // new[](unsigned long, align_val_t, nothrow) |
| 1093 | case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: |
| 1094 | return (NumParams == 3 && FTy.getReturnType()->isPointerTy()); |
| 1095 | |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1096 | // void operator delete[](void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1097 | case LibFunc_ZdaPv: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1098 | // void operator delete(void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1099 | case LibFunc_ZdlPv: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1100 | // void operator delete[](void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1101 | case LibFunc_msvc_delete_array_ptr32: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1102 | // void operator delete[](void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1103 | case LibFunc_msvc_delete_array_ptr64: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1104 | // void operator delete(void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1105 | case LibFunc_msvc_delete_ptr32: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1106 | // void operator delete(void*); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1107 | case LibFunc_msvc_delete_ptr64: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1108 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
| 1109 | |
| 1110 | // void operator delete[](void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1111 | case LibFunc_ZdaPvRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1112 | // void operator delete[](void*, unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1113 | case LibFunc_ZdaPvj: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1114 | // void operator delete[](void*, unsigned long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1115 | case LibFunc_ZdaPvm: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1116 | // void operator delete(void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1117 | case LibFunc_ZdlPvRKSt9nothrow_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1118 | // void operator delete(void*, unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1119 | case LibFunc_ZdlPvj: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1120 | // void operator delete(void*, unsigned long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1121 | case LibFunc_ZdlPvm: |
Eric Fiselier | 75627b1 | 2018-04-04 19:01:51 +0000 | [diff] [blame] | 1122 | // void operator delete(void*, align_val_t) |
| 1123 | case LibFunc_ZdlPvSt11align_val_t: |
| 1124 | // void operator delete[](void*, align_val_t) |
| 1125 | case LibFunc_ZdaPvSt11align_val_t: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1126 | // void operator delete[](void*, unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1127 | case LibFunc_msvc_delete_array_ptr32_int: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1128 | // void operator delete[](void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1129 | case LibFunc_msvc_delete_array_ptr32_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1130 | // void operator delete[](void*, unsigned long long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1131 | case LibFunc_msvc_delete_array_ptr64_longlong: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1132 | // void operator delete[](void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1133 | case LibFunc_msvc_delete_array_ptr64_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1134 | // void operator delete(void*, unsigned int); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1135 | case LibFunc_msvc_delete_ptr32_int: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1136 | // void operator delete(void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1137 | case LibFunc_msvc_delete_ptr32_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1138 | // void operator delete(void*, unsigned long long); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1139 | case LibFunc_msvc_delete_ptr64_longlong: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1140 | // void operator delete(void*, nothrow); |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1141 | case LibFunc_msvc_delete_ptr64_nothrow: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1142 | return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1143 | |
Eric Fiselier | 75627b1 | 2018-04-04 19:01:51 +0000 | [diff] [blame] | 1144 | // void operator delete(void*, align_val_t, nothrow) |
| 1145 | case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: |
| 1146 | // void operator delete[](void*, align_val_t, nothrow) |
| 1147 | case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: |
| 1148 | return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); |
| 1149 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1150 | case LibFunc_memset_pattern16: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1151 | return (!FTy.isVarArg() && NumParams == 3 && |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1152 | FTy.getParamType(0)->isPointerTy() && |
| 1153 | FTy.getParamType(1)->isPointerTy() && |
| 1154 | FTy.getParamType(2)->isIntegerTy()); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1155 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1156 | case LibFunc_cxa_guard_abort: |
| 1157 | case LibFunc_cxa_guard_acquire: |
| 1158 | case LibFunc_cxa_guard_release: |
| 1159 | case LibFunc_nvvm_reflect: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1160 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1161 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1162 | case LibFunc_sincospi_stret: |
| 1163 | case LibFunc_sincospif_stret: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1164 | return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); |
| 1165 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1166 | case LibFunc_acos: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1167 | case LibFunc_acos_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1168 | case LibFunc_acosf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1169 | case LibFunc_acosf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1170 | case LibFunc_acosh: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1171 | case LibFunc_acosh_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1172 | case LibFunc_acoshf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1173 | case LibFunc_acoshf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1174 | case LibFunc_acoshl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1175 | case LibFunc_acoshl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1176 | case LibFunc_acosl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1177 | case LibFunc_acosl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1178 | case LibFunc_asin: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1179 | case LibFunc_asin_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1180 | case LibFunc_asinf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1181 | case LibFunc_asinf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1182 | case LibFunc_asinh: |
| 1183 | case LibFunc_asinhf: |
| 1184 | case LibFunc_asinhl: |
| 1185 | case LibFunc_asinl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1186 | case LibFunc_asinl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1187 | case LibFunc_atan: |
| 1188 | case LibFunc_atanf: |
| 1189 | case LibFunc_atanh: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1190 | case LibFunc_atanh_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1191 | case LibFunc_atanhf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1192 | case LibFunc_atanhf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1193 | case LibFunc_atanhl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1194 | case LibFunc_atanhl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1195 | case LibFunc_atanl: |
| 1196 | case LibFunc_cbrt: |
| 1197 | case LibFunc_cbrtf: |
| 1198 | case LibFunc_cbrtl: |
| 1199 | case LibFunc_ceil: |
| 1200 | case LibFunc_ceilf: |
| 1201 | case LibFunc_ceill: |
| 1202 | case LibFunc_cos: |
| 1203 | case LibFunc_cosf: |
| 1204 | case LibFunc_cosh: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1205 | case LibFunc_cosh_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1206 | case LibFunc_coshf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1207 | case LibFunc_coshf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1208 | case LibFunc_coshl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1209 | case LibFunc_coshl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1210 | case LibFunc_cosl: |
| 1211 | case LibFunc_exp10: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1212 | case LibFunc_exp10_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1213 | case LibFunc_exp10f: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1214 | case LibFunc_exp10f_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1215 | case LibFunc_exp10l: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1216 | case LibFunc_exp10l_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1217 | case LibFunc_exp2: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1218 | case LibFunc_exp2_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1219 | case LibFunc_exp2f: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1220 | case LibFunc_exp2f_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1221 | case LibFunc_exp2l: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1222 | case LibFunc_exp2l_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1223 | case LibFunc_exp: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1224 | case LibFunc_exp_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1225 | case LibFunc_expf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1226 | case LibFunc_expf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1227 | case LibFunc_expl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1228 | case LibFunc_expl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1229 | case LibFunc_expm1: |
| 1230 | case LibFunc_expm1f: |
| 1231 | case LibFunc_expm1l: |
| 1232 | case LibFunc_fabs: |
| 1233 | case LibFunc_fabsf: |
| 1234 | case LibFunc_fabsl: |
| 1235 | case LibFunc_floor: |
| 1236 | case LibFunc_floorf: |
| 1237 | case LibFunc_floorl: |
| 1238 | case LibFunc_log10: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1239 | case LibFunc_log10_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1240 | case LibFunc_log10f: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1241 | case LibFunc_log10f_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1242 | case LibFunc_log10l: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1243 | case LibFunc_log10l_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1244 | case LibFunc_log1p: |
| 1245 | case LibFunc_log1pf: |
| 1246 | case LibFunc_log1pl: |
| 1247 | case LibFunc_log2: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1248 | case LibFunc_log2_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1249 | case LibFunc_log2f: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1250 | case LibFunc_log2f_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1251 | case LibFunc_log2l: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1252 | case LibFunc_log2l_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1253 | case LibFunc_log: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1254 | case LibFunc_log_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1255 | case LibFunc_logb: |
| 1256 | case LibFunc_logbf: |
| 1257 | case LibFunc_logbl: |
| 1258 | case LibFunc_logf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1259 | case LibFunc_logf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1260 | case LibFunc_logl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1261 | case LibFunc_logl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1262 | case LibFunc_nearbyint: |
| 1263 | case LibFunc_nearbyintf: |
| 1264 | case LibFunc_nearbyintl: |
| 1265 | case LibFunc_rint: |
| 1266 | case LibFunc_rintf: |
| 1267 | case LibFunc_rintl: |
| 1268 | case LibFunc_round: |
| 1269 | case LibFunc_roundf: |
| 1270 | case LibFunc_roundl: |
| 1271 | case LibFunc_sin: |
| 1272 | case LibFunc_sinf: |
| 1273 | case LibFunc_sinh: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1274 | case LibFunc_sinh_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1275 | case LibFunc_sinhf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1276 | case LibFunc_sinhf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1277 | case LibFunc_sinhl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1278 | case LibFunc_sinhl_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1279 | case LibFunc_sinl: |
| 1280 | case LibFunc_sqrt: |
| 1281 | case LibFunc_sqrt_finite: |
| 1282 | case LibFunc_sqrtf: |
| 1283 | case LibFunc_sqrtf_finite: |
| 1284 | case LibFunc_sqrtl: |
| 1285 | case LibFunc_sqrtl_finite: |
| 1286 | case LibFunc_tan: |
| 1287 | case LibFunc_tanf: |
| 1288 | case LibFunc_tanh: |
| 1289 | case LibFunc_tanhf: |
| 1290 | case LibFunc_tanhl: |
| 1291 | case LibFunc_tanl: |
| 1292 | case LibFunc_trunc: |
| 1293 | case LibFunc_truncf: |
| 1294 | case LibFunc_truncl: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1295 | return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && |
| 1296 | FTy.getReturnType() == FTy.getParamType(0)); |
| 1297 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1298 | case LibFunc_atan2: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1299 | case LibFunc_atan2_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1300 | case LibFunc_atan2f: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1301 | case LibFunc_atan2f_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1302 | case LibFunc_atan2l: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1303 | case LibFunc_atan2l_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1304 | case LibFunc_fmin: |
| 1305 | case LibFunc_fminf: |
| 1306 | case LibFunc_fminl: |
| 1307 | case LibFunc_fmax: |
| 1308 | case LibFunc_fmaxf: |
| 1309 | case LibFunc_fmaxl: |
| 1310 | case LibFunc_fmod: |
| 1311 | case LibFunc_fmodf: |
| 1312 | case LibFunc_fmodl: |
| 1313 | case LibFunc_copysign: |
| 1314 | case LibFunc_copysignf: |
| 1315 | case LibFunc_copysignl: |
| 1316 | case LibFunc_pow: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1317 | case LibFunc_pow_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1318 | case LibFunc_powf: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1319 | case LibFunc_powf_finite: |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1320 | case LibFunc_powl: |
Andrew Kaylor | 8731f0c | 2017-05-12 22:11:12 +0000 | [diff] [blame] | 1321 | case LibFunc_powl_finite: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1322 | return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && |
| 1323 | FTy.getReturnType() == FTy.getParamType(0) && |
| 1324 | FTy.getReturnType() == FTy.getParamType(1)); |
| 1325 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1326 | case LibFunc_ldexp: |
| 1327 | case LibFunc_ldexpf: |
| 1328 | case LibFunc_ldexpl: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1329 | return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && |
| 1330 | FTy.getReturnType() == FTy.getParamType(0) && |
| 1331 | FTy.getParamType(1)->isIntegerTy(32)); |
| 1332 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1333 | case LibFunc_ffs: |
| 1334 | case LibFunc_ffsl: |
| 1335 | case LibFunc_ffsll: |
| 1336 | case LibFunc_fls: |
| 1337 | case LibFunc_flsl: |
| 1338 | case LibFunc_flsll: |
Sanjay Patel | c5ddf50 | 2016-09-23 18:44:09 +0000 | [diff] [blame] | 1339 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && |
| 1340 | FTy.getParamType(0)->isIntegerTy()); |
| 1341 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1342 | case LibFunc_isdigit: |
| 1343 | case LibFunc_isascii: |
| 1344 | case LibFunc_toascii: |
| 1345 | case LibFunc_putchar: |
David Bolvansky | cb037ef | 2018-05-16 11:39:52 +0000 | [diff] [blame] | 1346 | case LibFunc_putchar_unlocked: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1347 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && |
Sanjay Patel | c5ddf50 | 2016-09-23 18:44:09 +0000 | [diff] [blame] | 1348 | FTy.getReturnType() == FTy.getParamType(0)); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1349 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1350 | case LibFunc_abs: |
| 1351 | case LibFunc_labs: |
| 1352 | case LibFunc_llabs: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1353 | return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && |
| 1354 | FTy.getReturnType() == FTy.getParamType(0)); |
| 1355 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1356 | case LibFunc_cxa_atexit: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1357 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && |
| 1358 | FTy.getParamType(0)->isPointerTy() && |
| 1359 | FTy.getParamType(1)->isPointerTy() && |
| 1360 | FTy.getParamType(2)->isPointerTy()); |
| 1361 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1362 | case LibFunc_sinpi: |
| 1363 | case LibFunc_cospi: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1364 | return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && |
| 1365 | FTy.getReturnType() == FTy.getParamType(0)); |
| 1366 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1367 | case LibFunc_sinpif: |
| 1368 | case LibFunc_cospif: |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1369 | return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && |
| 1370 | FTy.getReturnType() == FTy.getParamType(0)); |
| 1371 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1372 | case LibFunc_strnlen: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1373 | return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && |
| 1374 | FTy.getParamType(0) == PCharTy && |
| 1375 | FTy.getParamType(1) == SizeTTy); |
| 1376 | |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1377 | case LibFunc_posix_memalign: |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1378 | return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && |
| 1379 | FTy.getParamType(0)->isPointerTy() && |
| 1380 | FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy); |
| 1381 | |
Matthias Braun | 738a26c | 2017-05-05 20:25:50 +0000 | [diff] [blame] | 1382 | case LibFunc_wcslen: |
| 1383 | return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && |
| 1384 | FTy.getReturnType()->isIntegerTy()); |
| 1385 | |
Hal Finkel | 1d4f2b0 | 2017-12-16 01:26:25 +0000 | [diff] [blame] | 1386 | case LibFunc_cabs: |
| 1387 | case LibFunc_cabsf: |
| 1388 | case LibFunc_cabsl: { |
| 1389 | Type* RetTy = FTy.getReturnType(); |
| 1390 | if (!RetTy->isFloatingPointTy()) |
| 1391 | return false; |
| 1392 | |
| 1393 | // NOTE: These prototypes are target specific and currently support |
| 1394 | // "complex" passed as an array or discrete real & imaginary parameters. |
| 1395 | // Add other calling conventions to enable libcall optimizations. |
| 1396 | if (NumParams == 1) |
| 1397 | return (FTy.getParamType(0)->isArrayTy() && |
| 1398 | FTy.getParamType(0)->getArrayNumElements() == 2 && |
| 1399 | FTy.getParamType(0)->getArrayElementType() == RetTy); |
| 1400 | else if (NumParams == 2) |
| 1401 | return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy); |
| 1402 | else |
| 1403 | return false; |
| 1404 | } |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1405 | case LibFunc::NumLibFuncs: |
Ahmed Bougacha | bf5fc97 | 2017-01-17 19:54:18 +0000 | [diff] [blame] | 1406 | break; |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1407 | } |
Ahmed Bougacha | be550d0 | 2017-01-17 03:10:02 +0000 | [diff] [blame] | 1408 | |
Ahmed Bougacha | bf5fc97 | 2017-01-17 19:54:18 +0000 | [diff] [blame] | 1409 | llvm_unreachable("Invalid libfunc"); |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, |
David L. Jones | 32028c8 | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1413 | LibFunc &F) const { |
Ahmed Bougacha | 8a8efec | 2016-04-27 19:04:35 +0000 | [diff] [blame] | 1414 | const DataLayout *DL = |
| 1415 | FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; |
| 1416 | return getLibFunc(FDecl.getName(), F) && |
| 1417 | isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); |
| 1418 | } |
| 1419 | |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1420 | void TargetLibraryInfoImpl::disableAllFunctions() { |
Chris Lattner | 188a7e0 | 2011-02-18 22:34:03 +0000 | [diff] [blame] | 1421 | memset(AvailableArray, 0, sizeof(AvailableArray)); |
| 1422 | } |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1423 | |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1424 | static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 1425 | return LHS.ScalarFnName < RHS.ScalarFnName; |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 1429 | return LHS.VectorFnName < RHS.VectorFnName; |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 1433 | return LHS.ScalarFnName < S; |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { |
Mehdi Amini | 5e07fb3 | 2016-10-01 03:10:48 +0000 | [diff] [blame] | 1437 | return LHS.VectorFnName < S; |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { |
| 1441 | VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); |
Fangrui Song | 3b35e17 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1442 | llvm::sort(VectorDescs, compareByScalarFnName); |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1443 | |
| 1444 | ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); |
Fangrui Song | 3b35e17 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1445 | llvm::sort(ScalarDescs, compareByVectorFnName); |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1448 | void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( |
| 1449 | enum VectorLibrary VecLib) { |
| 1450 | switch (VecLib) { |
| 1451 | case Accelerate: { |
| 1452 | const VecDesc VecFuncs[] = { |
Michael Zolotukhin | d7b5144 | 2015-05-07 17:11:51 +0000 | [diff] [blame] | 1453 | // Floating-Point Arithmetic and Auxiliary Functions |
| 1454 | {"ceilf", "vceilf", 4}, |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1455 | {"fabsf", "vfabsf", 4}, |
| 1456 | {"llvm.fabs.f32", "vfabsf", 4}, |
Michael Zolotukhin | d7b5144 | 2015-05-07 17:11:51 +0000 | [diff] [blame] | 1457 | {"floorf", "vfloorf", 4}, |
| 1458 | {"sqrtf", "vsqrtf", 4}, |
| 1459 | {"llvm.sqrt.f32", "vsqrtf", 4}, |
| 1460 | |
| 1461 | // Exponential and Logarithmic Functions |
| 1462 | {"expf", "vexpf", 4}, |
| 1463 | {"llvm.exp.f32", "vexpf", 4}, |
| 1464 | {"expm1f", "vexpm1f", 4}, |
| 1465 | {"logf", "vlogf", 4}, |
| 1466 | {"llvm.log.f32", "vlogf", 4}, |
| 1467 | {"log1pf", "vlog1pf", 4}, |
| 1468 | {"log10f", "vlog10f", 4}, |
| 1469 | {"llvm.log10.f32", "vlog10f", 4}, |
| 1470 | {"logbf", "vlogbf", 4}, |
| 1471 | |
| 1472 | // Trigonometric Functions |
| 1473 | {"sinf", "vsinf", 4}, |
| 1474 | {"llvm.sin.f32", "vsinf", 4}, |
| 1475 | {"cosf", "vcosf", 4}, |
| 1476 | {"llvm.cos.f32", "vcosf", 4}, |
| 1477 | {"tanf", "vtanf", 4}, |
| 1478 | {"asinf", "vasinf", 4}, |
| 1479 | {"acosf", "vacosf", 4}, |
| 1480 | {"atanf", "vatanf", 4}, |
| 1481 | |
| 1482 | // Hyperbolic Functions |
| 1483 | {"sinhf", "vsinhf", 4}, |
| 1484 | {"coshf", "vcoshf", 4}, |
| 1485 | {"tanhf", "vtanhf", 4}, |
| 1486 | {"asinhf", "vasinhf", 4}, |
| 1487 | {"acoshf", "vacoshf", 4}, |
| 1488 | {"atanhf", "vatanhf", 4}, |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1489 | }; |
| 1490 | addVectorizableFunctions(VecFuncs); |
| 1491 | break; |
| 1492 | } |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1493 | case SVML: { |
| 1494 | const VecDesc VecFuncs[] = { |
| 1495 | {"sin", "__svml_sin2", 2}, |
| 1496 | {"sin", "__svml_sin4", 4}, |
| 1497 | {"sin", "__svml_sin8", 8}, |
| 1498 | |
| 1499 | {"sinf", "__svml_sinf4", 4}, |
| 1500 | {"sinf", "__svml_sinf8", 8}, |
| 1501 | {"sinf", "__svml_sinf16", 16}, |
| 1502 | |
Sanjay Patel | bd9be7a | 2018-06-07 18:21:24 +0000 | [diff] [blame] | 1503 | {"llvm.sin.f64", "__svml_sin2", 2}, |
| 1504 | {"llvm.sin.f64", "__svml_sin4", 4}, |
| 1505 | {"llvm.sin.f64", "__svml_sin8", 8}, |
| 1506 | |
| 1507 | {"llvm.sin.f32", "__svml_sinf4", 4}, |
| 1508 | {"llvm.sin.f32", "__svml_sinf8", 8}, |
| 1509 | {"llvm.sin.f32", "__svml_sinf16", 16}, |
| 1510 | |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1511 | {"cos", "__svml_cos2", 2}, |
| 1512 | {"cos", "__svml_cos4", 4}, |
| 1513 | {"cos", "__svml_cos8", 8}, |
| 1514 | |
| 1515 | {"cosf", "__svml_cosf4", 4}, |
| 1516 | {"cosf", "__svml_cosf8", 8}, |
| 1517 | {"cosf", "__svml_cosf16", 16}, |
| 1518 | |
Sanjay Patel | bd9be7a | 2018-06-07 18:21:24 +0000 | [diff] [blame] | 1519 | {"llvm.cos.f64", "__svml_cos2", 2}, |
| 1520 | {"llvm.cos.f64", "__svml_cos4", 4}, |
| 1521 | {"llvm.cos.f64", "__svml_cos8", 8}, |
| 1522 | |
| 1523 | {"llvm.cos.f32", "__svml_cosf4", 4}, |
| 1524 | {"llvm.cos.f32", "__svml_cosf8", 8}, |
| 1525 | {"llvm.cos.f32", "__svml_cosf16", 16}, |
| 1526 | |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1527 | {"pow", "__svml_pow2", 2}, |
| 1528 | {"pow", "__svml_pow4", 4}, |
| 1529 | {"pow", "__svml_pow8", 8}, |
| 1530 | |
| 1531 | {"powf", "__svml_powf4", 4}, |
| 1532 | {"powf", "__svml_powf8", 8}, |
| 1533 | {"powf", "__svml_powf16", 16}, |
| 1534 | |
Andrew Kaylor | a0e10ad | 2017-05-12 22:11:26 +0000 | [diff] [blame] | 1535 | { "__pow_finite", "__svml_pow2", 2 }, |
| 1536 | { "__pow_finite", "__svml_pow4", 4 }, |
| 1537 | { "__pow_finite", "__svml_pow8", 8 }, |
| 1538 | |
| 1539 | { "__powf_finite", "__svml_powf4", 4 }, |
| 1540 | { "__powf_finite", "__svml_powf8", 8 }, |
| 1541 | { "__powf_finite", "__svml_powf16", 16 }, |
| 1542 | |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1543 | {"llvm.pow.f64", "__svml_pow2", 2}, |
| 1544 | {"llvm.pow.f64", "__svml_pow4", 4}, |
| 1545 | {"llvm.pow.f64", "__svml_pow8", 8}, |
| 1546 | |
| 1547 | {"llvm.pow.f32", "__svml_powf4", 4}, |
| 1548 | {"llvm.pow.f32", "__svml_powf8", 8}, |
| 1549 | {"llvm.pow.f32", "__svml_powf16", 16}, |
| 1550 | |
| 1551 | {"exp", "__svml_exp2", 2}, |
| 1552 | {"exp", "__svml_exp4", 4}, |
| 1553 | {"exp", "__svml_exp8", 8}, |
| 1554 | |
| 1555 | {"expf", "__svml_expf4", 4}, |
| 1556 | {"expf", "__svml_expf8", 8}, |
| 1557 | {"expf", "__svml_expf16", 16}, |
| 1558 | |
Andrew Kaylor | a0e10ad | 2017-05-12 22:11:26 +0000 | [diff] [blame] | 1559 | { "__exp_finite", "__svml_exp2", 2 }, |
| 1560 | { "__exp_finite", "__svml_exp4", 4 }, |
| 1561 | { "__exp_finite", "__svml_exp8", 8 }, |
| 1562 | |
| 1563 | { "__expf_finite", "__svml_expf4", 4 }, |
| 1564 | { "__expf_finite", "__svml_expf8", 8 }, |
| 1565 | { "__expf_finite", "__svml_expf16", 16 }, |
| 1566 | |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1567 | {"llvm.exp.f64", "__svml_exp2", 2}, |
| 1568 | {"llvm.exp.f64", "__svml_exp4", 4}, |
| 1569 | {"llvm.exp.f64", "__svml_exp8", 8}, |
| 1570 | |
| 1571 | {"llvm.exp.f32", "__svml_expf4", 4}, |
| 1572 | {"llvm.exp.f32", "__svml_expf8", 8}, |
| 1573 | {"llvm.exp.f32", "__svml_expf16", 16}, |
| 1574 | |
| 1575 | {"log", "__svml_log2", 2}, |
| 1576 | {"log", "__svml_log4", 4}, |
| 1577 | {"log", "__svml_log8", 8}, |
| 1578 | |
| 1579 | {"logf", "__svml_logf4", 4}, |
| 1580 | {"logf", "__svml_logf8", 8}, |
| 1581 | {"logf", "__svml_logf16", 16}, |
| 1582 | |
Andrew Kaylor | a0e10ad | 2017-05-12 22:11:26 +0000 | [diff] [blame] | 1583 | { "__log_finite", "__svml_log2", 2 }, |
| 1584 | { "__log_finite", "__svml_log4", 4 }, |
| 1585 | { "__log_finite", "__svml_log8", 8 }, |
| 1586 | |
| 1587 | { "__logf_finite", "__svml_logf4", 4 }, |
| 1588 | { "__logf_finite", "__svml_logf8", 8 }, |
| 1589 | { "__logf_finite", "__svml_logf16", 16 }, |
| 1590 | |
Matt Masten | bbbcccb | 2016-07-29 16:42:44 +0000 | [diff] [blame] | 1591 | {"llvm.log.f64", "__svml_log2", 2}, |
| 1592 | {"llvm.log.f64", "__svml_log4", 4}, |
| 1593 | {"llvm.log.f64", "__svml_log8", 8}, |
| 1594 | |
| 1595 | {"llvm.log.f32", "__svml_logf4", 4}, |
| 1596 | {"llvm.log.f32", "__svml_logf8", 8}, |
| 1597 | {"llvm.log.f32", "__svml_logf16", 16}, |
| 1598 | }; |
| 1599 | addVectorizableFunctions(VecFuncs); |
| 1600 | break; |
| 1601 | } |
Michael Zolotukhin | 5850602 | 2015-03-17 19:50:55 +0000 | [diff] [blame] | 1602 | case NoLibrary: |
| 1603 | break; |
| 1604 | } |
| 1605 | } |
| 1606 | |
Michael Zolotukhin | 06aab08 | 2015-03-17 19:22:30 +0000 | [diff] [blame] | 1607 | bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { |
| 1608 | funcName = sanitizeFunctionName(funcName); |
| 1609 | if (funcName.empty()) |
| 1610 | return false; |
| 1611 | |
| 1612 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1613 | VectorDescs.begin(), VectorDescs.end(), funcName, |
| 1614 | compareWithScalarFnName); |
| 1615 | return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; |
| 1616 | } |
| 1617 | |
| 1618 | StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, |
| 1619 | unsigned VF) const { |
| 1620 | F = sanitizeFunctionName(F); |
| 1621 | if (F.empty()) |
| 1622 | return F; |
| 1623 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1624 | VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName); |
| 1625 | while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { |
| 1626 | if (I->VectorizationFactor == VF) |
| 1627 | return I->VectorFnName; |
| 1628 | ++I; |
| 1629 | } |
| 1630 | return StringRef(); |
| 1631 | } |
| 1632 | |
| 1633 | StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, |
| 1634 | unsigned &VF) const { |
| 1635 | F = sanitizeFunctionName(F); |
| 1636 | if (F.empty()) |
| 1637 | return F; |
| 1638 | |
| 1639 | std::vector<VecDesc>::const_iterator I = std::lower_bound( |
| 1640 | ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName); |
| 1641 | if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) |
| 1642 | return StringRef(); |
| 1643 | VF = I->VectorizationFactor; |
| 1644 | return I->ScalarFnName; |
| 1645 | } |
| 1646 | |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 1647 | TargetLibraryInfo TargetLibraryAnalysis::run(Module &M, |
| 1648 | ModuleAnalysisManager &) { |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1649 | if (PresetInfoImpl) |
| 1650 | return TargetLibraryInfo(*PresetInfoImpl); |
| 1651 | |
| 1652 | return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple()))); |
| 1653 | } |
| 1654 | |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 1655 | TargetLibraryInfo TargetLibraryAnalysis::run(Function &F, |
| 1656 | FunctionAnalysisManager &) { |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1657 | if (PresetInfoImpl) |
| 1658 | return TargetLibraryInfo(*PresetInfoImpl); |
| 1659 | |
| 1660 | return TargetLibraryInfo( |
| 1661 | lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); |
| 1662 | } |
| 1663 | |
Benjamin Kramer | 36538ff | 2016-06-08 19:09:22 +0000 | [diff] [blame] | 1664 | TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) { |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1665 | std::unique_ptr<TargetLibraryInfoImpl> &Impl = |
| 1666 | Impls[T.normalize()]; |
| 1667 | if (!Impl) |
| 1668 | Impl.reset(new TargetLibraryInfoImpl(T)); |
| 1669 | |
| 1670 | return *Impl; |
| 1671 | } |
| 1672 | |
Matthias Braun | 708626d | 2017-05-19 22:37:09 +0000 | [diff] [blame] | 1673 | unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { |
| 1674 | if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>( |
| 1675 | M.getModuleFlag("wchar_size"))) |
| 1676 | return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue(); |
Matthias Braun | 77cad59 | 2017-09-26 02:36:57 +0000 | [diff] [blame] | 1677 | return 0; |
Matthias Braun | 708626d | 2017-05-19 22:37:09 +0000 | [diff] [blame] | 1678 | } |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1679 | |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1680 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1681 | : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1682 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1683 | } |
| 1684 | |
| 1685 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1686 | : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1687 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1688 | } |
| 1689 | |
| 1690 | TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( |
Chandler Carruth | 6f409cb | 2015-01-24 02:06:09 +0000 | [diff] [blame] | 1691 | const TargetLibraryInfoImpl &TLIImpl) |
| 1692 | : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1693 | initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1694 | } |
| 1695 | |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 1696 | AnalysisKey TargetLibraryAnalysis::Key; |
NAKAMURA Takumi | d9b6afb | 2016-02-28 17:17:00 +0000 | [diff] [blame] | 1697 | |
Chandler Carruth | eeeec3c | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 1698 | // Register the basic pass. |
| 1699 | INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", |
| 1700 | "Target Library Information", false, true) |
| 1701 | char TargetLibraryInfoWrapperPass::ID = 0; |
| 1702 | |
| 1703 | void TargetLibraryInfoWrapperPass::anchor() {} |