1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the TargetLibraryInfo class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/Analysis/TargetLibraryInfo.h" 14 #include "llvm/ADT/Triple.h" 15 #include "llvm/IR/Constants.h" 16 #include "llvm/InitializePasses.h" 17 #include "llvm/Support/CommandLine.h" 18 using namespace llvm; 19 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"), 27 clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM, 28 "Darwin_libsystem_m", "Darwin libsystem_m"), 29 clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86", 30 "GLIBC Vector Math library"), 31 clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV", 32 "IBM MASS vector library"), 33 clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", 34 "Intel SVML library"))); 35 36 StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = 37 { 38 #define TLI_DEFINE_STRING 39 #include "llvm/Analysis/TargetLibraryInfo.def" 40 }; 41 42 static bool hasSinCosPiStret(const Triple &T) { 43 // Only Darwin variants have _stret versions of combined trig functions. 44 if (!T.isOSDarwin()) 45 return false; 46 47 // The ABI is rather complicated on x86, so don't do anything special there. 48 if (T.getArch() == Triple::x86) 49 return false; 50 51 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) 52 return false; 53 54 if (T.isiOS() && T.isOSVersionLT(7, 0)) 55 return false; 56 57 return true; 58 } 59 60 static bool hasBcmp(const Triple &TT) { 61 // Posix removed support from bcmp() in 2001, but the glibc and several 62 // implementations of the libc still have it. 63 if (TT.isOSLinux()) 64 return TT.isGNUEnvironment() || TT.isMusl(); 65 // Both NetBSD and OpenBSD are planning to remove the function. Windows does 66 // not have it. 67 return TT.isOSFreeBSD() || TT.isOSSolaris(); 68 } 69 70 static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT, 71 FunctionType *FuncTy) { 72 switch (CC) { 73 default: 74 return false; 75 case llvm::CallingConv::C: 76 return true; 77 case llvm::CallingConv::ARM_APCS: 78 case llvm::CallingConv::ARM_AAPCS: 79 case llvm::CallingConv::ARM_AAPCS_VFP: { 80 81 // The iOS ABI diverges from the standard in some cases, so for now don't 82 // try to simplify those calls. 83 if (Triple(TT).isiOS()) 84 return false; 85 86 if (!FuncTy->getReturnType()->isPointerTy() && 87 !FuncTy->getReturnType()->isIntegerTy() && 88 !FuncTy->getReturnType()->isVoidTy()) 89 return false; 90 91 for (auto *Param : FuncTy->params()) { 92 if (!Param->isPointerTy() && !Param->isIntegerTy()) 93 return false; 94 } 95 return true; 96 } 97 } 98 return false; 99 } 100 101 bool TargetLibraryInfoImpl::isCallingConvCCompatible(CallBase *CI) { 102 return ::isCallingConvCCompatible(CI->getCallingConv(), 103 CI->getModule()->getTargetTriple(), 104 CI->getFunctionType()); 105 } 106 107 bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) { 108 return ::isCallingConvCCompatible(F->getCallingConv(), 109 F->getParent()->getTargetTriple(), 110 F->getFunctionType()); 111 } 112 113 /// Initialize the set of available library functions based on the specified 114 /// target triple. This should be carefully written so that a missing target 115 /// triple gets a sane set of defaults. 116 static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, 117 ArrayRef<StringLiteral> StandardNames) { 118 // Verify that the StandardNames array is in alphabetical order. 119 assert( 120 llvm::is_sorted(StandardNames, 121 [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) && 122 "TargetLibraryInfoImpl function names must be sorted"); 123 124 // Set IO unlocked variants as unavailable 125 // Set them as available per system below 126 TLI.setUnavailable(LibFunc_getc_unlocked); 127 TLI.setUnavailable(LibFunc_getchar_unlocked); 128 TLI.setUnavailable(LibFunc_putc_unlocked); 129 TLI.setUnavailable(LibFunc_putchar_unlocked); 130 TLI.setUnavailable(LibFunc_fputc_unlocked); 131 TLI.setUnavailable(LibFunc_fgetc_unlocked); 132 TLI.setUnavailable(LibFunc_fread_unlocked); 133 TLI.setUnavailable(LibFunc_fwrite_unlocked); 134 TLI.setUnavailable(LibFunc_fputs_unlocked); 135 TLI.setUnavailable(LibFunc_fgets_unlocked); 136 137 bool ShouldExtI32Param = false, ShouldExtI32Return = false, 138 ShouldSignExtI32Param = false; 139 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 140 // returns corresponding to C-level ints and unsigned ints. 141 if (T.isPPC64() || T.getArch() == Triple::sparcv9 || 142 T.getArch() == Triple::systemz) { 143 ShouldExtI32Param = true; 144 ShouldExtI32Return = true; 145 } 146 // Mips, on the other hand, needs signext on i32 parameters corresponding 147 // to both signed and unsigned ints. 148 if (T.isMIPS()) { 149 ShouldSignExtI32Param = true; 150 } 151 TLI.setShouldExtI32Param(ShouldExtI32Param); 152 TLI.setShouldExtI32Return(ShouldExtI32Return); 153 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 154 155 // Let's assume by default that the size of int is 32 bits, unless the target 156 // is a 16-bit architecture because then it most likely is 16 bits. If that 157 // isn't true for a target those defaults should be overridden below. 158 TLI.setIntSize(T.isArch16Bit() ? 16 : 32); 159 160 // There is really no runtime library on AMDGPU, apart from 161 // __kmpc_alloc/free_shared. 162 if (T.isAMDGPU()) { 163 TLI.disableAllFunctions(); 164 TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared); 165 TLI.setAvailable(llvm::LibFunc___kmpc_free_shared); 166 return; 167 } 168 169 // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and 170 // later. All versions of watchOS support it. 171 if (T.isMacOSX()) { 172 // available IO unlocked variants on Mac OS X 173 TLI.setAvailable(LibFunc_getc_unlocked); 174 TLI.setAvailable(LibFunc_getchar_unlocked); 175 TLI.setAvailable(LibFunc_putc_unlocked); 176 TLI.setAvailable(LibFunc_putchar_unlocked); 177 178 if (T.isMacOSXVersionLT(10, 5)) { 179 TLI.setUnavailable(LibFunc_memset_pattern4); 180 TLI.setUnavailable(LibFunc_memset_pattern8); 181 TLI.setUnavailable(LibFunc_memset_pattern16); 182 } 183 } else if (T.isiOS()) { 184 if (T.isOSVersionLT(3, 0)) { 185 TLI.setUnavailable(LibFunc_memset_pattern4); 186 TLI.setUnavailable(LibFunc_memset_pattern8); 187 TLI.setUnavailable(LibFunc_memset_pattern16); 188 } 189 } else if (!T.isWatchOS()) { 190 TLI.setUnavailable(LibFunc_memset_pattern4); 191 TLI.setUnavailable(LibFunc_memset_pattern8); 192 TLI.setUnavailable(LibFunc_memset_pattern16); 193 } 194 195 if (!hasSinCosPiStret(T)) { 196 TLI.setUnavailable(LibFunc_sinpi); 197 TLI.setUnavailable(LibFunc_sinpif); 198 TLI.setUnavailable(LibFunc_cospi); 199 TLI.setUnavailable(LibFunc_cospif); 200 TLI.setUnavailable(LibFunc_sincospi_stret); 201 TLI.setUnavailable(LibFunc_sincospif_stret); 202 } 203 204 if (!hasBcmp(T)) 205 TLI.setUnavailable(LibFunc_bcmp); 206 207 if (T.isMacOSX() && T.getArch() == Triple::x86 && 208 !T.isMacOSXVersionLT(10, 7)) { 209 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 210 // we don't care about) have two versions; on recent OSX, the one we want 211 // has a $UNIX2003 suffix. The two implementations are identical except 212 // for the return value in some edge cases. However, we don't want to 213 // generate code that depends on the old symbols. 214 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); 215 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); 216 } 217 218 // iprintf and friends are only available on XCore, TCE, and Emscripten. 219 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce && 220 T.getOS() != Triple::Emscripten) { 221 TLI.setUnavailable(LibFunc_iprintf); 222 TLI.setUnavailable(LibFunc_siprintf); 223 TLI.setUnavailable(LibFunc_fiprintf); 224 } 225 226 // __small_printf and friends are only available on Emscripten. 227 if (T.getOS() != Triple::Emscripten) { 228 TLI.setUnavailable(LibFunc_small_printf); 229 TLI.setUnavailable(LibFunc_small_sprintf); 230 TLI.setUnavailable(LibFunc_small_fprintf); 231 } 232 233 if (T.isOSWindows() && !T.isOSCygMing()) { 234 // XXX: The earliest documentation available at the moment is for VS2015/VC19: 235 // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015 236 // XXX: In order to use an MSVCRT older than VC19, 237 // the specific library version must be explicit in the target triple, 238 // e.g., x86_64-pc-windows-msvc18. 239 bool hasPartialC99 = true; 240 if (T.isKnownWindowsMSVCEnvironment()) { 241 VersionTuple Version = T.getEnvironmentVersion(); 242 hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19); 243 } 244 245 // Latest targets support C89 math functions, in part. 246 bool isARM = (T.getArch() == Triple::aarch64 || 247 T.getArch() == Triple::arm); 248 bool hasPartialFloat = (isARM || 249 T.getArch() == Triple::x86_64); 250 251 // Win32 does not support float C89 math functions, in general. 252 if (!hasPartialFloat) { 253 TLI.setUnavailable(LibFunc_acosf); 254 TLI.setUnavailable(LibFunc_asinf); 255 TLI.setUnavailable(LibFunc_atan2f); 256 TLI.setUnavailable(LibFunc_atanf); 257 TLI.setUnavailable(LibFunc_ceilf); 258 TLI.setUnavailable(LibFunc_cosf); 259 TLI.setUnavailable(LibFunc_coshf); 260 TLI.setUnavailable(LibFunc_expf); 261 TLI.setUnavailable(LibFunc_floorf); 262 TLI.setUnavailable(LibFunc_fmodf); 263 TLI.setUnavailable(LibFunc_log10f); 264 TLI.setUnavailable(LibFunc_logf); 265 TLI.setUnavailable(LibFunc_modff); 266 TLI.setUnavailable(LibFunc_powf); 267 TLI.setUnavailable(LibFunc_remainderf); 268 TLI.setUnavailable(LibFunc_sinf); 269 TLI.setUnavailable(LibFunc_sinhf); 270 TLI.setUnavailable(LibFunc_sqrtf); 271 TLI.setUnavailable(LibFunc_tanf); 272 TLI.setUnavailable(LibFunc_tanhf); 273 } 274 if (!isARM) 275 TLI.setUnavailable(LibFunc_fabsf); 276 TLI.setUnavailable(LibFunc_frexpf); 277 TLI.setUnavailable(LibFunc_ldexpf); 278 279 // Win32 does not support long double C89 math functions. 280 TLI.setUnavailable(LibFunc_acosl); 281 TLI.setUnavailable(LibFunc_asinl); 282 TLI.setUnavailable(LibFunc_atan2l); 283 TLI.setUnavailable(LibFunc_atanl); 284 TLI.setUnavailable(LibFunc_ceill); 285 TLI.setUnavailable(LibFunc_cosl); 286 TLI.setUnavailable(LibFunc_coshl); 287 TLI.setUnavailable(LibFunc_expl); 288 TLI.setUnavailable(LibFunc_fabsl); 289 TLI.setUnavailable(LibFunc_floorl); 290 TLI.setUnavailable(LibFunc_fmodl); 291 TLI.setUnavailable(LibFunc_frexpl); 292 TLI.setUnavailable(LibFunc_ldexpl); 293 TLI.setUnavailable(LibFunc_log10l); 294 TLI.setUnavailable(LibFunc_logl); 295 TLI.setUnavailable(LibFunc_modfl); 296 TLI.setUnavailable(LibFunc_powl); 297 TLI.setUnavailable(LibFunc_remainderl); 298 TLI.setUnavailable(LibFunc_sinl); 299 TLI.setUnavailable(LibFunc_sinhl); 300 TLI.setUnavailable(LibFunc_sqrtl); 301 TLI.setUnavailable(LibFunc_tanl); 302 TLI.setUnavailable(LibFunc_tanhl); 303 304 // Win32 does not fully support C99 math functions. 305 if (!hasPartialC99) { 306 TLI.setUnavailable(LibFunc_acosh); 307 TLI.setUnavailable(LibFunc_acoshf); 308 TLI.setUnavailable(LibFunc_asinh); 309 TLI.setUnavailable(LibFunc_asinhf); 310 TLI.setUnavailable(LibFunc_atanh); 311 TLI.setUnavailable(LibFunc_atanhf); 312 TLI.setAvailableWithName(LibFunc_cabs, "_cabs"); 313 TLI.setUnavailable(LibFunc_cabsf); 314 TLI.setUnavailable(LibFunc_cbrt); 315 TLI.setUnavailable(LibFunc_cbrtf); 316 TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); 317 TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf"); 318 TLI.setUnavailable(LibFunc_exp2); 319 TLI.setUnavailable(LibFunc_exp2f); 320 TLI.setUnavailable(LibFunc_expm1); 321 TLI.setUnavailable(LibFunc_expm1f); 322 TLI.setUnavailable(LibFunc_fmax); 323 TLI.setUnavailable(LibFunc_fmaxf); 324 TLI.setUnavailable(LibFunc_fmin); 325 TLI.setUnavailable(LibFunc_fminf); 326 TLI.setUnavailable(LibFunc_log1p); 327 TLI.setUnavailable(LibFunc_log1pf); 328 TLI.setUnavailable(LibFunc_log2); 329 TLI.setUnavailable(LibFunc_log2f); 330 TLI.setAvailableWithName(LibFunc_logb, "_logb"); 331 if (hasPartialFloat) 332 TLI.setAvailableWithName(LibFunc_logbf, "_logbf"); 333 else 334 TLI.setUnavailable(LibFunc_logbf); 335 TLI.setUnavailable(LibFunc_rint); 336 TLI.setUnavailable(LibFunc_rintf); 337 TLI.setUnavailable(LibFunc_round); 338 TLI.setUnavailable(LibFunc_roundf); 339 TLI.setUnavailable(LibFunc_trunc); 340 TLI.setUnavailable(LibFunc_truncf); 341 } 342 343 // Win32 does not support long double C99 math functions. 344 TLI.setUnavailable(LibFunc_acoshl); 345 TLI.setUnavailable(LibFunc_asinhl); 346 TLI.setUnavailable(LibFunc_atanhl); 347 TLI.setUnavailable(LibFunc_cabsl); 348 TLI.setUnavailable(LibFunc_cbrtl); 349 TLI.setUnavailable(LibFunc_copysignl); 350 TLI.setUnavailable(LibFunc_exp2l); 351 TLI.setUnavailable(LibFunc_expm1l); 352 TLI.setUnavailable(LibFunc_fmaxl); 353 TLI.setUnavailable(LibFunc_fminl); 354 TLI.setUnavailable(LibFunc_log1pl); 355 TLI.setUnavailable(LibFunc_log2l); 356 TLI.setUnavailable(LibFunc_logbl); 357 TLI.setUnavailable(LibFunc_nearbyintl); 358 TLI.setUnavailable(LibFunc_rintl); 359 TLI.setUnavailable(LibFunc_roundl); 360 TLI.setUnavailable(LibFunc_truncl); 361 362 // Win32 does not support these functions, but 363 // they are generally available on POSIX-compliant systems. 364 TLI.setUnavailable(LibFunc_access); 365 TLI.setUnavailable(LibFunc_chmod); 366 TLI.setUnavailable(LibFunc_closedir); 367 TLI.setUnavailable(LibFunc_fdopen); 368 TLI.setUnavailable(LibFunc_fileno); 369 TLI.setUnavailable(LibFunc_fseeko); 370 TLI.setUnavailable(LibFunc_fstat); 371 TLI.setUnavailable(LibFunc_ftello); 372 TLI.setUnavailable(LibFunc_gettimeofday); 373 TLI.setUnavailable(LibFunc_memccpy); 374 TLI.setUnavailable(LibFunc_mkdir); 375 TLI.setUnavailable(LibFunc_open); 376 TLI.setUnavailable(LibFunc_opendir); 377 TLI.setUnavailable(LibFunc_pclose); 378 TLI.setUnavailable(LibFunc_popen); 379 TLI.setUnavailable(LibFunc_read); 380 TLI.setUnavailable(LibFunc_rmdir); 381 TLI.setUnavailable(LibFunc_stat); 382 TLI.setUnavailable(LibFunc_strcasecmp); 383 TLI.setUnavailable(LibFunc_strncasecmp); 384 TLI.setUnavailable(LibFunc_unlink); 385 TLI.setUnavailable(LibFunc_utime); 386 TLI.setUnavailable(LibFunc_write); 387 } 388 389 if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) { 390 // These functions aren't available in either MSVC or MinGW environments. 391 TLI.setUnavailable(LibFunc_bcmp); 392 TLI.setUnavailable(LibFunc_bcopy); 393 TLI.setUnavailable(LibFunc_bzero); 394 TLI.setUnavailable(LibFunc_chown); 395 TLI.setUnavailable(LibFunc_ctermid); 396 TLI.setUnavailable(LibFunc_ffs); 397 TLI.setUnavailable(LibFunc_flockfile); 398 TLI.setUnavailable(LibFunc_fstatvfs); 399 TLI.setUnavailable(LibFunc_ftrylockfile); 400 TLI.setUnavailable(LibFunc_funlockfile); 401 TLI.setUnavailable(LibFunc_getitimer); 402 TLI.setUnavailable(LibFunc_getlogin_r); 403 TLI.setUnavailable(LibFunc_getpwnam); 404 TLI.setUnavailable(LibFunc_htonl); 405 TLI.setUnavailable(LibFunc_htons); 406 TLI.setUnavailable(LibFunc_lchown); 407 TLI.setUnavailable(LibFunc_lstat); 408 TLI.setUnavailable(LibFunc_ntohl); 409 TLI.setUnavailable(LibFunc_ntohs); 410 TLI.setUnavailable(LibFunc_pread); 411 TLI.setUnavailable(LibFunc_pwrite); 412 TLI.setUnavailable(LibFunc_readlink); 413 TLI.setUnavailable(LibFunc_realpath); 414 TLI.setUnavailable(LibFunc_setitimer); 415 TLI.setUnavailable(LibFunc_statvfs); 416 TLI.setUnavailable(LibFunc_stpcpy); 417 TLI.setUnavailable(LibFunc_stpncpy); 418 TLI.setUnavailable(LibFunc_times); 419 TLI.setUnavailable(LibFunc_uname); 420 TLI.setUnavailable(LibFunc_unsetenv); 421 TLI.setUnavailable(LibFunc_utimes); 422 } 423 424 // Pick just one set of new/delete variants. 425 if (T.isOSMSVCRT()) { 426 // MSVC, doesn't have the Itanium new/delete. 427 TLI.setUnavailable(LibFunc_ZdaPv); 428 TLI.setUnavailable(LibFunc_ZdaPvRKSt9nothrow_t); 429 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_t); 430 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t); 431 TLI.setUnavailable(LibFunc_ZdaPvj); 432 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t); 433 TLI.setUnavailable(LibFunc_ZdaPvm); 434 TLI.setUnavailable(LibFunc_ZdaPvmSt11align_val_t); 435 TLI.setUnavailable(LibFunc_ZdlPv); 436 TLI.setUnavailable(LibFunc_ZdlPvRKSt9nothrow_t); 437 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_t); 438 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t); 439 TLI.setUnavailable(LibFunc_ZdlPvj); 440 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t); 441 TLI.setUnavailable(LibFunc_ZdlPvm); 442 TLI.setUnavailable(LibFunc_ZdlPvmSt11align_val_t); 443 TLI.setUnavailable(LibFunc_Znaj); 444 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t); 445 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t); 446 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t); 447 TLI.setUnavailable(LibFunc_Znam); 448 TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t); 449 TLI.setUnavailable(LibFunc_ZnamSt11align_val_t); 450 TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t); 451 TLI.setUnavailable(LibFunc_Znwj); 452 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t); 453 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t); 454 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t); 455 TLI.setUnavailable(LibFunc_Znwm); 456 TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t); 457 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t); 458 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t); 459 } else { 460 // Not MSVC, assume it's Itanium. 461 TLI.setUnavailable(LibFunc_msvc_new_int); 462 TLI.setUnavailable(LibFunc_msvc_new_int_nothrow); 463 TLI.setUnavailable(LibFunc_msvc_new_longlong); 464 TLI.setUnavailable(LibFunc_msvc_new_longlong_nothrow); 465 TLI.setUnavailable(LibFunc_msvc_delete_ptr32); 466 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_nothrow); 467 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_int); 468 TLI.setUnavailable(LibFunc_msvc_delete_ptr64); 469 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_nothrow); 470 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_longlong); 471 TLI.setUnavailable(LibFunc_msvc_new_array_int); 472 TLI.setUnavailable(LibFunc_msvc_new_array_int_nothrow); 473 TLI.setUnavailable(LibFunc_msvc_new_array_longlong); 474 TLI.setUnavailable(LibFunc_msvc_new_array_longlong_nothrow); 475 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32); 476 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_nothrow); 477 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_int); 478 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64); 479 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_nothrow); 480 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_longlong); 481 } 482 483 switch (T.getOS()) { 484 case Triple::MacOSX: 485 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 486 // and their names are __exp10 and __exp10f. exp10l is not available on 487 // OS X or iOS. 488 TLI.setUnavailable(LibFunc_exp10l); 489 if (T.isMacOSXVersionLT(10, 9)) { 490 TLI.setUnavailable(LibFunc_exp10); 491 TLI.setUnavailable(LibFunc_exp10f); 492 } else { 493 TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 494 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 495 } 496 break; 497 case Triple::IOS: 498 case Triple::TvOS: 499 case Triple::WatchOS: 500 TLI.setUnavailable(LibFunc_exp10l); 501 if (!T.isWatchOS() && 502 (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) { 503 TLI.setUnavailable(LibFunc_exp10); 504 TLI.setUnavailable(LibFunc_exp10f); 505 } else { 506 TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 507 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 508 } 509 break; 510 case Triple::Linux: 511 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 512 // buggy prior to glibc version 2.18. Until this version is widely deployed 513 // or we have a reasonable detection strategy, we cannot use exp10 reliably 514 // on Linux. 515 // 516 // Fall through to disable all of them. 517 LLVM_FALLTHROUGH; 518 default: 519 TLI.setUnavailable(LibFunc_exp10); 520 TLI.setUnavailable(LibFunc_exp10f); 521 TLI.setUnavailable(LibFunc_exp10l); 522 } 523 524 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 525 // Linux (GLIBC): 526 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 527 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 528 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 529 switch (T.getOS()) { 530 case Triple::Darwin: 531 case Triple::MacOSX: 532 case Triple::IOS: 533 case Triple::TvOS: 534 case Triple::WatchOS: 535 case Triple::FreeBSD: 536 case Triple::Linux: 537 break; 538 default: 539 TLI.setUnavailable(LibFunc_ffsl); 540 } 541 542 // ffsll is available on at least FreeBSD and Linux (GLIBC): 543 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 544 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 545 switch (T.getOS()) { 546 case Triple::Darwin: 547 case Triple::MacOSX: 548 case Triple::IOS: 549 case Triple::TvOS: 550 case Triple::WatchOS: 551 case Triple::FreeBSD: 552 case Triple::Linux: 553 break; 554 default: 555 TLI.setUnavailable(LibFunc_ffsll); 556 } 557 558 // The following functions are available on at least FreeBSD: 559 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 560 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 561 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 562 if (!T.isOSFreeBSD()) { 563 TLI.setUnavailable(LibFunc_fls); 564 TLI.setUnavailable(LibFunc_flsl); 565 TLI.setUnavailable(LibFunc_flsll); 566 } 567 568 // The following functions are only available on GNU/Linux (using glibc). 569 // Linux variants without glibc (eg: bionic, musl) may have some subset. 570 if (!T.isOSLinux() || !T.isGNUEnvironment()) { 571 TLI.setUnavailable(LibFunc_dunder_strdup); 572 TLI.setUnavailable(LibFunc_dunder_strtok_r); 573 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); 574 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); 575 TLI.setUnavailable(LibFunc_under_IO_getc); 576 TLI.setUnavailable(LibFunc_under_IO_putc); 577 // But, Android and musl have memalign. 578 if (!T.isAndroid() && !T.isMusl()) 579 TLI.setUnavailable(LibFunc_memalign); 580 TLI.setUnavailable(LibFunc_fopen64); 581 TLI.setUnavailable(LibFunc_fseeko64); 582 TLI.setUnavailable(LibFunc_fstat64); 583 TLI.setUnavailable(LibFunc_fstatvfs64); 584 TLI.setUnavailable(LibFunc_ftello64); 585 TLI.setUnavailable(LibFunc_lstat64); 586 TLI.setUnavailable(LibFunc_open64); 587 TLI.setUnavailable(LibFunc_stat64); 588 TLI.setUnavailable(LibFunc_statvfs64); 589 TLI.setUnavailable(LibFunc_tmpfile64); 590 591 // Relaxed math functions are included in math-finite.h on Linux (GLIBC). 592 // Note that math-finite.h is no longer supported by top-of-tree GLIBC, 593 // so we keep these functions around just so that they're recognized by 594 // the ConstantFolder. 595 TLI.setUnavailable(LibFunc_acos_finite); 596 TLI.setUnavailable(LibFunc_acosf_finite); 597 TLI.setUnavailable(LibFunc_acosl_finite); 598 TLI.setUnavailable(LibFunc_acosh_finite); 599 TLI.setUnavailable(LibFunc_acoshf_finite); 600 TLI.setUnavailable(LibFunc_acoshl_finite); 601 TLI.setUnavailable(LibFunc_asin_finite); 602 TLI.setUnavailable(LibFunc_asinf_finite); 603 TLI.setUnavailable(LibFunc_asinl_finite); 604 TLI.setUnavailable(LibFunc_atan2_finite); 605 TLI.setUnavailable(LibFunc_atan2f_finite); 606 TLI.setUnavailable(LibFunc_atan2l_finite); 607 TLI.setUnavailable(LibFunc_atanh_finite); 608 TLI.setUnavailable(LibFunc_atanhf_finite); 609 TLI.setUnavailable(LibFunc_atanhl_finite); 610 TLI.setUnavailable(LibFunc_cosh_finite); 611 TLI.setUnavailable(LibFunc_coshf_finite); 612 TLI.setUnavailable(LibFunc_coshl_finite); 613 TLI.setUnavailable(LibFunc_exp10_finite); 614 TLI.setUnavailable(LibFunc_exp10f_finite); 615 TLI.setUnavailable(LibFunc_exp10l_finite); 616 TLI.setUnavailable(LibFunc_exp2_finite); 617 TLI.setUnavailable(LibFunc_exp2f_finite); 618 TLI.setUnavailable(LibFunc_exp2l_finite); 619 TLI.setUnavailable(LibFunc_exp_finite); 620 TLI.setUnavailable(LibFunc_expf_finite); 621 TLI.setUnavailable(LibFunc_expl_finite); 622 TLI.setUnavailable(LibFunc_log10_finite); 623 TLI.setUnavailable(LibFunc_log10f_finite); 624 TLI.setUnavailable(LibFunc_log10l_finite); 625 TLI.setUnavailable(LibFunc_log2_finite); 626 TLI.setUnavailable(LibFunc_log2f_finite); 627 TLI.setUnavailable(LibFunc_log2l_finite); 628 TLI.setUnavailable(LibFunc_log_finite); 629 TLI.setUnavailable(LibFunc_logf_finite); 630 TLI.setUnavailable(LibFunc_logl_finite); 631 TLI.setUnavailable(LibFunc_pow_finite); 632 TLI.setUnavailable(LibFunc_powf_finite); 633 TLI.setUnavailable(LibFunc_powl_finite); 634 TLI.setUnavailable(LibFunc_sinh_finite); 635 TLI.setUnavailable(LibFunc_sinhf_finite); 636 TLI.setUnavailable(LibFunc_sinhl_finite); 637 TLI.setUnavailable(LibFunc_sqrt_finite); 638 TLI.setUnavailable(LibFunc_sqrtf_finite); 639 TLI.setUnavailable(LibFunc_sqrtl_finite); 640 } 641 642 if ((T.isOSLinux() && T.isGNUEnvironment()) || 643 (T.isAndroid() && !T.isAndroidVersionLT(28))) { 644 // available IO unlocked variants on GNU/Linux and Android P or later 645 TLI.setAvailable(LibFunc_getc_unlocked); 646 TLI.setAvailable(LibFunc_getchar_unlocked); 647 TLI.setAvailable(LibFunc_putc_unlocked); 648 TLI.setAvailable(LibFunc_putchar_unlocked); 649 TLI.setAvailable(LibFunc_fputc_unlocked); 650 TLI.setAvailable(LibFunc_fgetc_unlocked); 651 TLI.setAvailable(LibFunc_fread_unlocked); 652 TLI.setAvailable(LibFunc_fwrite_unlocked); 653 TLI.setAvailable(LibFunc_fputs_unlocked); 654 TLI.setAvailable(LibFunc_fgets_unlocked); 655 } 656 657 if (T.isAndroid() && T.isAndroidVersionLT(21)) { 658 TLI.setUnavailable(LibFunc_stpcpy); 659 TLI.setUnavailable(LibFunc_stpncpy); 660 } 661 662 if (T.isPS()) { 663 // PS4/PS5 do have memalign. 664 TLI.setAvailable(LibFunc_memalign); 665 666 // PS4/PS5 do not have new/delete with "unsigned int" size parameter; 667 // they only have the "unsigned long" versions. 668 TLI.setUnavailable(LibFunc_ZdaPvj); 669 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t); 670 TLI.setUnavailable(LibFunc_ZdlPvj); 671 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t); 672 TLI.setUnavailable(LibFunc_Znaj); 673 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t); 674 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t); 675 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t); 676 TLI.setUnavailable(LibFunc_Znwj); 677 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t); 678 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t); 679 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t); 680 681 // None of the *_chk functions. 682 TLI.setUnavailable(LibFunc_memccpy_chk); 683 TLI.setUnavailable(LibFunc_memcpy_chk); 684 TLI.setUnavailable(LibFunc_memmove_chk); 685 TLI.setUnavailable(LibFunc_mempcpy_chk); 686 TLI.setUnavailable(LibFunc_memset_chk); 687 TLI.setUnavailable(LibFunc_snprintf_chk); 688 TLI.setUnavailable(LibFunc_sprintf_chk); 689 TLI.setUnavailable(LibFunc_stpcpy_chk); 690 TLI.setUnavailable(LibFunc_stpncpy_chk); 691 TLI.setUnavailable(LibFunc_strcat_chk); 692 TLI.setUnavailable(LibFunc_strcpy_chk); 693 TLI.setUnavailable(LibFunc_strlcat_chk); 694 TLI.setUnavailable(LibFunc_strlcpy_chk); 695 TLI.setUnavailable(LibFunc_strlen_chk); 696 TLI.setUnavailable(LibFunc_strncat_chk); 697 TLI.setUnavailable(LibFunc_strncpy_chk); 698 TLI.setUnavailable(LibFunc_vsnprintf_chk); 699 TLI.setUnavailable(LibFunc_vsprintf_chk); 700 701 // Various Posix system functions. 702 TLI.setUnavailable(LibFunc_access); 703 TLI.setUnavailable(LibFunc_chmod); 704 TLI.setUnavailable(LibFunc_chown); 705 TLI.setUnavailable(LibFunc_closedir); 706 TLI.setUnavailable(LibFunc_ctermid); 707 TLI.setUnavailable(LibFunc_execl); 708 TLI.setUnavailable(LibFunc_execle); 709 TLI.setUnavailable(LibFunc_execlp); 710 TLI.setUnavailable(LibFunc_execv); 711 TLI.setUnavailable(LibFunc_execvP); 712 TLI.setUnavailable(LibFunc_execve); 713 TLI.setUnavailable(LibFunc_execvp); 714 TLI.setUnavailable(LibFunc_execvpe); 715 TLI.setUnavailable(LibFunc_fork); 716 TLI.setUnavailable(LibFunc_fstat); 717 TLI.setUnavailable(LibFunc_fstatvfs); 718 TLI.setUnavailable(LibFunc_getenv); 719 TLI.setUnavailable(LibFunc_getitimer); 720 TLI.setUnavailable(LibFunc_getlogin_r); 721 TLI.setUnavailable(LibFunc_getpwnam); 722 TLI.setUnavailable(LibFunc_gettimeofday); 723 TLI.setUnavailable(LibFunc_lchown); 724 TLI.setUnavailable(LibFunc_lstat); 725 TLI.setUnavailable(LibFunc_mkdir); 726 TLI.setUnavailable(LibFunc_open); 727 TLI.setUnavailable(LibFunc_opendir); 728 TLI.setUnavailable(LibFunc_pclose); 729 TLI.setUnavailable(LibFunc_popen); 730 TLI.setUnavailable(LibFunc_pread); 731 TLI.setUnavailable(LibFunc_pwrite); 732 TLI.setUnavailable(LibFunc_read); 733 TLI.setUnavailable(LibFunc_readlink); 734 TLI.setUnavailable(LibFunc_realpath); 735 TLI.setUnavailable(LibFunc_rename); 736 TLI.setUnavailable(LibFunc_rmdir); 737 TLI.setUnavailable(LibFunc_setitimer); 738 TLI.setUnavailable(LibFunc_stat); 739 TLI.setUnavailable(LibFunc_statvfs); 740 TLI.setUnavailable(LibFunc_system); 741 TLI.setUnavailable(LibFunc_times); 742 TLI.setUnavailable(LibFunc_tmpfile); 743 TLI.setUnavailable(LibFunc_unlink); 744 TLI.setUnavailable(LibFunc_uname); 745 TLI.setUnavailable(LibFunc_unsetenv); 746 TLI.setUnavailable(LibFunc_utime); 747 TLI.setUnavailable(LibFunc_utimes); 748 TLI.setUnavailable(LibFunc_valloc); 749 TLI.setUnavailable(LibFunc_write); 750 751 // Miscellaneous other functions not provided. 752 TLI.setUnavailable(LibFunc_atomic_load); 753 TLI.setUnavailable(LibFunc_atomic_store); 754 TLI.setUnavailable(LibFunc___kmpc_alloc_shared); 755 TLI.setUnavailable(LibFunc___kmpc_free_shared); 756 TLI.setUnavailable(LibFunc_dunder_strndup); 757 TLI.setUnavailable(LibFunc_bcmp); 758 TLI.setUnavailable(LibFunc_bcopy); 759 TLI.setUnavailable(LibFunc_bzero); 760 TLI.setUnavailable(LibFunc_cabs); 761 TLI.setUnavailable(LibFunc_cabsf); 762 TLI.setUnavailable(LibFunc_cabsl); 763 TLI.setUnavailable(LibFunc_ffs); 764 TLI.setUnavailable(LibFunc_flockfile); 765 TLI.setUnavailable(LibFunc_fseeko); 766 TLI.setUnavailable(LibFunc_ftello); 767 TLI.setUnavailable(LibFunc_ftrylockfile); 768 TLI.setUnavailable(LibFunc_funlockfile); 769 TLI.setUnavailable(LibFunc_htonl); 770 TLI.setUnavailable(LibFunc_htons); 771 TLI.setUnavailable(LibFunc_isascii); 772 TLI.setUnavailable(LibFunc_memccpy); 773 TLI.setUnavailable(LibFunc_mempcpy); 774 TLI.setUnavailable(LibFunc_memrchr); 775 TLI.setUnavailable(LibFunc_ntohl); 776 TLI.setUnavailable(LibFunc_ntohs); 777 TLI.setUnavailable(LibFunc_reallocf); 778 TLI.setUnavailable(LibFunc_roundeven); 779 TLI.setUnavailable(LibFunc_roundevenf); 780 TLI.setUnavailable(LibFunc_roundevenl); 781 TLI.setUnavailable(LibFunc_stpcpy); 782 TLI.setUnavailable(LibFunc_stpncpy); 783 TLI.setUnavailable(LibFunc_strlcat); 784 TLI.setUnavailable(LibFunc_strlcpy); 785 TLI.setUnavailable(LibFunc_strndup); 786 TLI.setUnavailable(LibFunc_strnlen); 787 TLI.setUnavailable(LibFunc_toascii); 788 } 789 790 // As currently implemented in clang, NVPTX code has no standard library to 791 // speak of. Headers provide a standard-ish library implementation, but many 792 // of the signatures are wrong -- for example, many libm functions are not 793 // extern "C". 794 // 795 // libdevice, an IR library provided by nvidia, is linked in by the front-end, 796 // but only used functions are provided to llvm. Moreover, most of the 797 // functions in libdevice don't map precisely to standard library functions. 798 // 799 // FIXME: Having no standard library prevents e.g. many fastmath 800 // optimizations, so this situation should be fixed. 801 if (T.isNVPTX()) { 802 TLI.disableAllFunctions(); 803 TLI.setAvailable(LibFunc_nvvm_reflect); 804 TLI.setAvailable(llvm::LibFunc_malloc); 805 TLI.setAvailable(llvm::LibFunc_free); 806 807 // TODO: We could enable the following two according to [0] but we haven't 808 // done an evaluation wrt. the performance implications. 809 // [0] 810 // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations 811 // 812 // TLI.setAvailable(llvm::LibFunc_memcpy); 813 // TLI.setAvailable(llvm::LibFunc_memset); 814 815 TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared); 816 TLI.setAvailable(llvm::LibFunc___kmpc_free_shared); 817 } else { 818 TLI.setUnavailable(LibFunc_nvvm_reflect); 819 } 820 821 // These vec_malloc/free routines are only available on AIX. 822 if (!T.isOSAIX()) { 823 TLI.setUnavailable(LibFunc_vec_calloc); 824 TLI.setUnavailable(LibFunc_vec_malloc); 825 TLI.setUnavailable(LibFunc_vec_realloc); 826 TLI.setUnavailable(LibFunc_vec_free); 827 } 828 829 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 830 } 831 832 TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 833 // Default to everything being available. 834 memset(AvailableArray, -1, sizeof(AvailableArray)); 835 836 initialize(*this, Triple(), StandardNames); 837 } 838 839 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 840 // Default to everything being available. 841 memset(AvailableArray, -1, sizeof(AvailableArray)); 842 843 initialize(*this, T, StandardNames); 844 } 845 846 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 847 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 848 ShouldExtI32Return(TLI.ShouldExtI32Return), 849 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param), 850 SizeOfInt(TLI.SizeOfInt) { 851 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 852 VectorDescs = TLI.VectorDescs; 853 ScalarDescs = TLI.ScalarDescs; 854 } 855 856 TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 857 : CustomNames(std::move(TLI.CustomNames)), 858 ShouldExtI32Param(TLI.ShouldExtI32Param), 859 ShouldExtI32Return(TLI.ShouldExtI32Return), 860 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param), 861 SizeOfInt(TLI.SizeOfInt) { 862 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 863 AvailableArray); 864 VectorDescs = TLI.VectorDescs; 865 ScalarDescs = TLI.ScalarDescs; 866 } 867 868 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 869 CustomNames = TLI.CustomNames; 870 ShouldExtI32Param = TLI.ShouldExtI32Param; 871 ShouldExtI32Return = TLI.ShouldExtI32Return; 872 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 873 SizeOfInt = TLI.SizeOfInt; 874 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 875 return *this; 876 } 877 878 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 879 CustomNames = std::move(TLI.CustomNames); 880 ShouldExtI32Param = TLI.ShouldExtI32Param; 881 ShouldExtI32Return = TLI.ShouldExtI32Return; 882 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 883 SizeOfInt = TLI.SizeOfInt; 884 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 885 AvailableArray); 886 return *this; 887 } 888 889 static StringRef sanitizeFunctionName(StringRef funcName) { 890 // Filter out empty names and names containing null bytes, those can't be in 891 // our table. 892 if (funcName.empty() || funcName.contains('\0')) 893 return StringRef(); 894 895 // Check for \01 prefix that is used to mangle __asm declarations and 896 // strip it if present. 897 return GlobalValue::dropLLVMManglingEscape(funcName); 898 } 899 900 bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const { 901 funcName = sanitizeFunctionName(funcName); 902 if (funcName.empty()) 903 return false; 904 905 const auto *Start = std::begin(StandardNames); 906 const auto *End = std::end(StandardNames); 907 const auto *I = std::lower_bound(Start, End, funcName); 908 if (I != End && *I == funcName) { 909 F = (LibFunc)(I - Start); 910 return true; 911 } 912 return false; 913 } 914 915 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 916 LibFunc F, 917 const Module &M) const { 918 // FIXME: There is really no guarantee that sizeof(size_t) is equal to 919 // sizeof(int*) for every target. So the assumption used here to derive the 920 // SizeTBits based on the size of an integer pointer in address space zero 921 // isn't always valid. 922 unsigned SizeTBits = M.getDataLayout().getPointerSizeInBits(/*AddrSpace=*/0); 923 unsigned NumParams = FTy.getNumParams(); 924 925 switch (F) { 926 case LibFunc_execl: 927 case LibFunc_execlp: 928 case LibFunc_execle: 929 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 930 FTy.getParamType(1)->isPointerTy() && 931 FTy.getReturnType()->isIntegerTy(32)); 932 case LibFunc_execv: 933 case LibFunc_execvp: 934 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 935 FTy.getParamType(1)->isPointerTy() && 936 FTy.getReturnType()->isIntegerTy(32)); 937 case LibFunc_execvP: 938 case LibFunc_execvpe: 939 case LibFunc_execve: 940 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 941 FTy.getParamType(1)->isPointerTy() && 942 FTy.getParamType(2)->isPointerTy() && 943 FTy.getReturnType()->isIntegerTy(32)); 944 case LibFunc_strlen_chk: 945 --NumParams; 946 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 947 return false; 948 LLVM_FALLTHROUGH; 949 case LibFunc_strlen: 950 return NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 951 FTy.getReturnType()->isIntegerTy(SizeTBits); 952 953 case LibFunc_strchr: 954 case LibFunc_strrchr: 955 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 956 FTy.getParamType(0) == FTy.getReturnType() && 957 FTy.getParamType(1)->isIntegerTy()); 958 959 case LibFunc_strtol: 960 case LibFunc_strtod: 961 case LibFunc_strtof: 962 case LibFunc_strtoul: 963 case LibFunc_strtoll: 964 case LibFunc_strtold: 965 case LibFunc_strtoull: 966 return ((NumParams == 2 || NumParams == 3) && 967 FTy.getParamType(0)->isPointerTy() && 968 FTy.getParamType(1)->isPointerTy()); 969 case LibFunc_strcat_chk: 970 --NumParams; 971 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 972 return false; 973 LLVM_FALLTHROUGH; 974 case LibFunc_strcat: 975 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 976 FTy.getParamType(0) == FTy.getReturnType() && 977 FTy.getParamType(1) == FTy.getReturnType()); 978 979 case LibFunc_strncat_chk: 980 --NumParams; 981 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 982 return false; 983 LLVM_FALLTHROUGH; 984 case LibFunc_strncat: 985 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 986 FTy.getParamType(0) == FTy.getReturnType() && 987 FTy.getParamType(1) == FTy.getReturnType() && 988 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 989 990 case LibFunc_strcpy_chk: 991 case LibFunc_stpcpy_chk: 992 --NumParams; 993 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 994 return false; 995 LLVM_FALLTHROUGH; 996 case LibFunc_strcpy: 997 case LibFunc_stpcpy: 998 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 999 FTy.getParamType(0) == FTy.getParamType(1) && 1000 FTy.getParamType(0)->isPointerTy()); 1001 1002 case LibFunc_strlcat_chk: 1003 case LibFunc_strlcpy_chk: 1004 --NumParams; 1005 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 1006 return false; 1007 LLVM_FALLTHROUGH; 1008 case LibFunc_strlcat: 1009 case LibFunc_strlcpy: 1010 return NumParams == 3 && FTy.getReturnType()->isIntegerTy(SizeTBits) && 1011 FTy.getParamType(0)->isPointerTy() && 1012 FTy.getParamType(1)->isPointerTy() && 1013 FTy.getParamType(2)->isIntegerTy(SizeTBits); 1014 1015 case LibFunc_strncpy_chk: 1016 case LibFunc_stpncpy_chk: 1017 --NumParams; 1018 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 1019 return false; 1020 LLVM_FALLTHROUGH; 1021 case LibFunc_strncpy: 1022 case LibFunc_stpncpy: 1023 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 1024 FTy.getParamType(0) == FTy.getParamType(1) && 1025 FTy.getParamType(0)->isPointerTy() && 1026 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1027 1028 case LibFunc_strxfrm: 1029 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1030 FTy.getParamType(1)->isPointerTy()); 1031 1032 case LibFunc_strcmp: 1033 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 1034 FTy.getParamType(0)->isPointerTy() && 1035 FTy.getParamType(0) == FTy.getParamType(1)); 1036 1037 case LibFunc_strncmp: 1038 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 1039 FTy.getParamType(0)->isPointerTy() && 1040 FTy.getParamType(0) == FTy.getParamType(1) && 1041 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1042 1043 case LibFunc_strspn: 1044 case LibFunc_strcspn: 1045 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1046 FTy.getParamType(0) == FTy.getParamType(1) && 1047 FTy.getReturnType()->isIntegerTy()); 1048 1049 case LibFunc_strcoll: 1050 case LibFunc_strcasecmp: 1051 case LibFunc_strncasecmp: 1052 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1053 FTy.getParamType(1)->isPointerTy()); 1054 1055 case LibFunc_strstr: 1056 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1057 FTy.getParamType(0)->isPointerTy() && 1058 FTy.getParamType(1)->isPointerTy()); 1059 1060 case LibFunc_strpbrk: 1061 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1062 FTy.getReturnType() == FTy.getParamType(0) && 1063 FTy.getParamType(0) == FTy.getParamType(1)); 1064 1065 case LibFunc_strtok: 1066 case LibFunc_strtok_r: 1067 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 1068 case LibFunc_scanf: 1069 case LibFunc_setbuf: 1070 case LibFunc_setvbuf: 1071 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 1072 case LibFunc_strdup: 1073 case LibFunc_strndup: 1074 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 1075 FTy.getParamType(0)->isPointerTy()); 1076 case LibFunc_sscanf: 1077 case LibFunc_stat: 1078 case LibFunc_statvfs: 1079 case LibFunc_siprintf: 1080 case LibFunc_small_sprintf: 1081 case LibFunc_sprintf: 1082 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1083 FTy.getParamType(1)->isPointerTy() && 1084 FTy.getReturnType()->isIntegerTy(32)); 1085 1086 case LibFunc_sprintf_chk: 1087 return NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1088 FTy.getParamType(1)->isIntegerTy(32) && 1089 FTy.getParamType(2)->isIntegerTy(SizeTBits) && 1090 FTy.getParamType(3)->isPointerTy() && 1091 FTy.getReturnType()->isIntegerTy(32); 1092 1093 case LibFunc_snprintf: 1094 return NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1095 FTy.getParamType(1)->isIntegerTy(SizeTBits) && 1096 FTy.getParamType(2)->isPointerTy() && 1097 FTy.getReturnType()->isIntegerTy(32); 1098 1099 case LibFunc_snprintf_chk: 1100 return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 1101 FTy.getParamType(1)->isIntegerTy(SizeTBits) && 1102 FTy.getParamType(2)->isIntegerTy(32) && 1103 FTy.getParamType(3)->isIntegerTy(SizeTBits) && 1104 FTy.getParamType(4)->isPointerTy() && 1105 FTy.getReturnType()->isIntegerTy(32); 1106 1107 case LibFunc_setitimer: 1108 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1109 FTy.getParamType(2)->isPointerTy()); 1110 case LibFunc_system: 1111 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1112 case LibFunc___kmpc_alloc_shared: 1113 return NumParams == 1 && FTy.getReturnType()->isPointerTy(); 1114 case LibFunc_malloc: 1115 case LibFunc_vec_malloc: 1116 return NumParams == 1 && FTy.getParamType(0)->isIntegerTy(SizeTBits) && 1117 FTy.getReturnType()->isPointerTy(); 1118 case LibFunc_memcmp: 1119 return NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 1120 FTy.getParamType(0)->isPointerTy() && 1121 FTy.getParamType(1)->isPointerTy() && 1122 FTy.getParamType(2)->isIntegerTy(SizeTBits); 1123 1124 case LibFunc_memchr: 1125 case LibFunc_memrchr: 1126 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 1127 FTy.getReturnType() == FTy.getParamType(0) && 1128 FTy.getParamType(1)->isIntegerTy(32) && 1129 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1130 case LibFunc_modf: 1131 case LibFunc_modff: 1132 case LibFunc_modfl: 1133 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 1134 1135 case LibFunc_memcpy_chk: 1136 case LibFunc_mempcpy_chk: 1137 case LibFunc_memmove_chk: 1138 --NumParams; 1139 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 1140 return false; 1141 LLVM_FALLTHROUGH; 1142 case LibFunc_memcpy: 1143 case LibFunc_mempcpy: 1144 case LibFunc_memmove: 1145 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 1146 FTy.getParamType(0)->isPointerTy() && 1147 FTy.getParamType(1)->isPointerTy() && 1148 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1149 1150 case LibFunc_memset_chk: 1151 --NumParams; 1152 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 1153 return false; 1154 LLVM_FALLTHROUGH; 1155 case LibFunc_memset: 1156 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 1157 FTy.getParamType(0)->isPointerTy() && 1158 FTy.getParamType(1)->isIntegerTy() && 1159 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1160 1161 case LibFunc_memccpy_chk: 1162 --NumParams; 1163 if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits)) 1164 return false; 1165 LLVM_FALLTHROUGH; 1166 case LibFunc_memccpy: 1167 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 1168 case LibFunc_memalign: 1169 return (FTy.getReturnType()->isPointerTy()); 1170 case LibFunc_realloc: 1171 case LibFunc_reallocf: 1172 case LibFunc_vec_realloc: 1173 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1174 FTy.getParamType(0) == FTy.getReturnType() && 1175 FTy.getParamType(1)->isIntegerTy(SizeTBits)); 1176 case LibFunc_read: 1177 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 1178 case LibFunc_rewind: 1179 case LibFunc_rmdir: 1180 case LibFunc_remove: 1181 case LibFunc_realpath: 1182 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 1183 case LibFunc_rename: 1184 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1185 FTy.getParamType(1)->isPointerTy()); 1186 case LibFunc_readlink: 1187 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1188 FTy.getParamType(1)->isPointerTy()); 1189 case LibFunc_write: 1190 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 1191 case LibFunc_aligned_alloc: 1192 return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 1193 case LibFunc_bcopy: 1194 case LibFunc_bcmp: 1195 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1196 FTy.getParamType(1)->isPointerTy()); 1197 case LibFunc_bzero: 1198 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1199 case LibFunc_calloc: 1200 case LibFunc_vec_calloc: 1201 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1202 FTy.getParamType(0) == FTy.getParamType(1)); 1203 1204 case LibFunc_atof: 1205 case LibFunc_atoi: 1206 case LibFunc_atol: 1207 case LibFunc_atoll: 1208 case LibFunc_ferror: 1209 case LibFunc_getenv: 1210 case LibFunc_getpwnam: 1211 case LibFunc_iprintf: 1212 case LibFunc_small_printf: 1213 case LibFunc_pclose: 1214 case LibFunc_perror: 1215 case LibFunc_printf: 1216 case LibFunc_puts: 1217 case LibFunc_uname: 1218 case LibFunc_under_IO_getc: 1219 case LibFunc_unlink: 1220 case LibFunc_unsetenv: 1221 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1222 1223 case LibFunc_access: 1224 case LibFunc_chmod: 1225 case LibFunc_chown: 1226 case LibFunc_clearerr: 1227 case LibFunc_closedir: 1228 case LibFunc_ctermid: 1229 case LibFunc_fclose: 1230 case LibFunc_feof: 1231 case LibFunc_fflush: 1232 case LibFunc_fgetc: 1233 case LibFunc_fgetc_unlocked: 1234 case LibFunc_fileno: 1235 case LibFunc_flockfile: 1236 case LibFunc_free: 1237 case LibFunc_fseek: 1238 case LibFunc_fseeko64: 1239 case LibFunc_fseeko: 1240 case LibFunc_fsetpos: 1241 case LibFunc_ftell: 1242 case LibFunc_ftello64: 1243 case LibFunc_ftello: 1244 case LibFunc_ftrylockfile: 1245 case LibFunc_funlockfile: 1246 case LibFunc_getc: 1247 case LibFunc_getc_unlocked: 1248 case LibFunc_getlogin_r: 1249 case LibFunc_mkdir: 1250 case LibFunc_mktime: 1251 case LibFunc_times: 1252 case LibFunc_vec_free: 1253 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 1254 case LibFunc___kmpc_free_shared: 1255 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1256 FTy.getParamType(1)->isIntegerTy(SizeTBits)); 1257 1258 case LibFunc_fopen: 1259 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1260 FTy.getParamType(0)->isPointerTy() && 1261 FTy.getParamType(1)->isPointerTy()); 1262 case LibFunc_fork: 1263 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32)); 1264 case LibFunc_fdopen: 1265 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1266 FTy.getParamType(1)->isPointerTy()); 1267 case LibFunc_fputc: 1268 case LibFunc_fputc_unlocked: 1269 case LibFunc_fstat: 1270 case LibFunc_frexp: 1271 case LibFunc_frexpf: 1272 case LibFunc_frexpl: 1273 case LibFunc_fstatvfs: 1274 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1275 case LibFunc_fgets: 1276 case LibFunc_fgets_unlocked: 1277 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1278 FTy.getParamType(2)->isPointerTy()); 1279 case LibFunc_fread: 1280 case LibFunc_fread_unlocked: 1281 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1282 FTy.getParamType(3)->isPointerTy()); 1283 case LibFunc_fwrite: 1284 case LibFunc_fwrite_unlocked: 1285 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 1286 FTy.getParamType(0)->isPointerTy() && 1287 FTy.getParamType(1)->isIntegerTy() && 1288 FTy.getParamType(2)->isIntegerTy() && 1289 FTy.getParamType(3)->isPointerTy()); 1290 case LibFunc_fputs: 1291 case LibFunc_fputs_unlocked: 1292 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1293 FTy.getParamType(1)->isPointerTy()); 1294 case LibFunc_fscanf: 1295 case LibFunc_fiprintf: 1296 case LibFunc_small_fprintf: 1297 case LibFunc_fprintf: 1298 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && 1299 FTy.getParamType(0)->isPointerTy() && 1300 FTy.getParamType(1)->isPointerTy()); 1301 case LibFunc_fgetpos: 1302 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1303 FTy.getParamType(1)->isPointerTy()); 1304 case LibFunc_getchar: 1305 case LibFunc_getchar_unlocked: 1306 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); 1307 case LibFunc_gets: 1308 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1309 case LibFunc_getitimer: 1310 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1311 case LibFunc_ungetc: 1312 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1313 case LibFunc_utime: 1314 case LibFunc_utimes: 1315 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1316 FTy.getParamType(1)->isPointerTy()); 1317 case LibFunc_putc: 1318 case LibFunc_putc_unlocked: 1319 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1320 case LibFunc_pread: 1321 case LibFunc_pwrite: 1322 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 1323 case LibFunc_popen: 1324 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1325 FTy.getParamType(0)->isPointerTy() && 1326 FTy.getParamType(1)->isPointerTy()); 1327 case LibFunc_vscanf: 1328 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1329 case LibFunc_vsscanf: 1330 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1331 FTy.getParamType(2)->isPointerTy()); 1332 case LibFunc_vfscanf: 1333 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1334 FTy.getParamType(2)->isPointerTy()); 1335 case LibFunc_valloc: 1336 return (FTy.getReturnType()->isPointerTy()); 1337 case LibFunc_vprintf: 1338 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1339 case LibFunc_vfprintf: 1340 case LibFunc_vsprintf: 1341 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1342 FTy.getParamType(1)->isPointerTy()); 1343 case LibFunc_vsprintf_chk: 1344 return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 1345 FTy.getParamType(1)->isIntegerTy(32) && 1346 FTy.getParamType(2)->isIntegerTy(SizeTBits) && FTy.getParamType(3)->isPointerTy(); 1347 case LibFunc_vsnprintf: 1348 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1349 FTy.getParamType(2)->isPointerTy()); 1350 case LibFunc_vsnprintf_chk: 1351 return NumParams == 6 && FTy.getParamType(0)->isPointerTy() && 1352 FTy.getParamType(2)->isIntegerTy(32) && 1353 FTy.getParamType(3)->isIntegerTy(SizeTBits) && FTy.getParamType(4)->isPointerTy(); 1354 case LibFunc_open: 1355 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1356 case LibFunc_opendir: 1357 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 1358 FTy.getParamType(0)->isPointerTy()); 1359 case LibFunc_tmpfile: 1360 return (FTy.getReturnType()->isPointerTy()); 1361 case LibFunc_htonl: 1362 case LibFunc_ntohl: 1363 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 1364 FTy.getReturnType() == FTy.getParamType(0)); 1365 case LibFunc_htons: 1366 case LibFunc_ntohs: 1367 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && 1368 FTy.getReturnType() == FTy.getParamType(0)); 1369 case LibFunc_lstat: 1370 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1371 FTy.getParamType(1)->isPointerTy()); 1372 case LibFunc_lchown: 1373 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 1374 case LibFunc_qsort: 1375 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 1376 case LibFunc_dunder_strdup: 1377 case LibFunc_dunder_strndup: 1378 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 1379 FTy.getParamType(0)->isPointerTy()); 1380 case LibFunc_dunder_strtok_r: 1381 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 1382 case LibFunc_under_IO_putc: 1383 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1384 case LibFunc_dunder_isoc99_scanf: 1385 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 1386 case LibFunc_stat64: 1387 case LibFunc_lstat64: 1388 case LibFunc_statvfs64: 1389 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1390 FTy.getParamType(1)->isPointerTy()); 1391 case LibFunc_dunder_isoc99_sscanf: 1392 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1393 FTy.getParamType(1)->isPointerTy()); 1394 case LibFunc_fopen64: 1395 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1396 FTy.getParamType(0)->isPointerTy() && 1397 FTy.getParamType(1)->isPointerTy()); 1398 case LibFunc_tmpfile64: 1399 return (FTy.getReturnType()->isPointerTy()); 1400 case LibFunc_fstat64: 1401 case LibFunc_fstatvfs64: 1402 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1403 case LibFunc_open64: 1404 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1405 case LibFunc_gettimeofday: 1406 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1407 FTy.getParamType(1)->isPointerTy()); 1408 1409 // new(unsigned int); 1410 case LibFunc_Znwj: 1411 // new(unsigned long); 1412 case LibFunc_Znwm: 1413 // new[](unsigned int); 1414 case LibFunc_Znaj: 1415 // new[](unsigned long); 1416 case LibFunc_Znam: 1417 // new(unsigned int); 1418 case LibFunc_msvc_new_int: 1419 // new(unsigned long long); 1420 case LibFunc_msvc_new_longlong: 1421 // new[](unsigned int); 1422 case LibFunc_msvc_new_array_int: 1423 // new[](unsigned long long); 1424 case LibFunc_msvc_new_array_longlong: 1425 return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 1426 1427 // new(unsigned int, nothrow); 1428 case LibFunc_ZnwjRKSt9nothrow_t: 1429 // new(unsigned long, nothrow); 1430 case LibFunc_ZnwmRKSt9nothrow_t: 1431 // new[](unsigned int, nothrow); 1432 case LibFunc_ZnajRKSt9nothrow_t: 1433 // new[](unsigned long, nothrow); 1434 case LibFunc_ZnamRKSt9nothrow_t: 1435 // new(unsigned int, nothrow); 1436 case LibFunc_msvc_new_int_nothrow: 1437 // new(unsigned long long, nothrow); 1438 case LibFunc_msvc_new_longlong_nothrow: 1439 // new[](unsigned int, nothrow); 1440 case LibFunc_msvc_new_array_int_nothrow: 1441 // new[](unsigned long long, nothrow); 1442 case LibFunc_msvc_new_array_longlong_nothrow: 1443 // new(unsigned int, align_val_t) 1444 case LibFunc_ZnwjSt11align_val_t: 1445 // new(unsigned long, align_val_t) 1446 case LibFunc_ZnwmSt11align_val_t: 1447 // new[](unsigned int, align_val_t) 1448 case LibFunc_ZnajSt11align_val_t: 1449 // new[](unsigned long, align_val_t) 1450 case LibFunc_ZnamSt11align_val_t: 1451 return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 1452 1453 // new(unsigned int, align_val_t, nothrow) 1454 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: 1455 // new(unsigned long, align_val_t, nothrow) 1456 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: 1457 // new[](unsigned int, align_val_t, nothrow) 1458 case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: 1459 // new[](unsigned long, align_val_t, nothrow) 1460 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: 1461 return (NumParams == 3 && FTy.getReturnType()->isPointerTy()); 1462 1463 // void operator delete[](void*); 1464 case LibFunc_ZdaPv: 1465 // void operator delete(void*); 1466 case LibFunc_ZdlPv: 1467 // void operator delete[](void*); 1468 case LibFunc_msvc_delete_array_ptr32: 1469 // void operator delete[](void*); 1470 case LibFunc_msvc_delete_array_ptr64: 1471 // void operator delete(void*); 1472 case LibFunc_msvc_delete_ptr32: 1473 // void operator delete(void*); 1474 case LibFunc_msvc_delete_ptr64: 1475 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1476 1477 // void operator delete[](void*, nothrow); 1478 case LibFunc_ZdaPvRKSt9nothrow_t: 1479 // void operator delete[](void*, unsigned int); 1480 case LibFunc_ZdaPvj: 1481 // void operator delete[](void*, unsigned long); 1482 case LibFunc_ZdaPvm: 1483 // void operator delete(void*, nothrow); 1484 case LibFunc_ZdlPvRKSt9nothrow_t: 1485 // void operator delete(void*, unsigned int); 1486 case LibFunc_ZdlPvj: 1487 // void operator delete(void*, unsigned long); 1488 case LibFunc_ZdlPvm: 1489 // void operator delete(void*, align_val_t) 1490 case LibFunc_ZdlPvSt11align_val_t: 1491 // void operator delete[](void*, align_val_t) 1492 case LibFunc_ZdaPvSt11align_val_t: 1493 // void operator delete[](void*, unsigned int); 1494 case LibFunc_msvc_delete_array_ptr32_int: 1495 // void operator delete[](void*, nothrow); 1496 case LibFunc_msvc_delete_array_ptr32_nothrow: 1497 // void operator delete[](void*, unsigned long long); 1498 case LibFunc_msvc_delete_array_ptr64_longlong: 1499 // void operator delete[](void*, nothrow); 1500 case LibFunc_msvc_delete_array_ptr64_nothrow: 1501 // void operator delete(void*, unsigned int); 1502 case LibFunc_msvc_delete_ptr32_int: 1503 // void operator delete(void*, nothrow); 1504 case LibFunc_msvc_delete_ptr32_nothrow: 1505 // void operator delete(void*, unsigned long long); 1506 case LibFunc_msvc_delete_ptr64_longlong: 1507 // void operator delete(void*, nothrow); 1508 case LibFunc_msvc_delete_ptr64_nothrow: 1509 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1510 1511 // void operator delete(void*, align_val_t, nothrow) 1512 case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: 1513 // void operator delete[](void*, align_val_t, nothrow) 1514 case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: 1515 // void operator delete(void*, unsigned int, align_val_t) 1516 case LibFunc_ZdlPvjSt11align_val_t: 1517 // void operator delete(void*, unsigned long, align_val_t) 1518 case LibFunc_ZdlPvmSt11align_val_t: 1519 // void operator delete[](void*, unsigned int, align_val_t); 1520 case LibFunc_ZdaPvjSt11align_val_t: 1521 // void operator delete[](void*, unsigned long, align_val_t); 1522 case LibFunc_ZdaPvmSt11align_val_t: 1523 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 1524 1525 // void __atomic_load(size_t, void *, void *, int) 1526 case LibFunc_atomic_load: 1527 // void __atomic_store(size_t, void *, void *, int) 1528 case LibFunc_atomic_store: 1529 return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() && 1530 FTy.getParamType(1)->isPointerTy() && 1531 FTy.getParamType(2)->isPointerTy() && 1532 FTy.getParamType(3)->isIntegerTy()); 1533 1534 case LibFunc_memset_pattern4: 1535 case LibFunc_memset_pattern8: 1536 case LibFunc_memset_pattern16: 1537 return (!FTy.isVarArg() && NumParams == 3 && 1538 FTy.getParamType(0)->isPointerTy() && 1539 FTy.getParamType(1)->isPointerTy() && 1540 FTy.getParamType(2)->isIntegerTy()); 1541 1542 case LibFunc_cxa_guard_abort: 1543 case LibFunc_cxa_guard_acquire: 1544 case LibFunc_cxa_guard_release: 1545 case LibFunc_nvvm_reflect: 1546 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1547 1548 case LibFunc_sincospi_stret: 1549 case LibFunc_sincospif_stret: 1550 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); 1551 1552 case LibFunc_acos: 1553 case LibFunc_acos_finite: 1554 case LibFunc_acosf: 1555 case LibFunc_acosf_finite: 1556 case LibFunc_acosh: 1557 case LibFunc_acosh_finite: 1558 case LibFunc_acoshf: 1559 case LibFunc_acoshf_finite: 1560 case LibFunc_acoshl: 1561 case LibFunc_acoshl_finite: 1562 case LibFunc_acosl: 1563 case LibFunc_acosl_finite: 1564 case LibFunc_asin: 1565 case LibFunc_asin_finite: 1566 case LibFunc_asinf: 1567 case LibFunc_asinf_finite: 1568 case LibFunc_asinh: 1569 case LibFunc_asinhf: 1570 case LibFunc_asinhl: 1571 case LibFunc_asinl: 1572 case LibFunc_asinl_finite: 1573 case LibFunc_atan: 1574 case LibFunc_atanf: 1575 case LibFunc_atanh: 1576 case LibFunc_atanh_finite: 1577 case LibFunc_atanhf: 1578 case LibFunc_atanhf_finite: 1579 case LibFunc_atanhl: 1580 case LibFunc_atanhl_finite: 1581 case LibFunc_atanl: 1582 case LibFunc_cbrt: 1583 case LibFunc_cbrtf: 1584 case LibFunc_cbrtl: 1585 case LibFunc_ceil: 1586 case LibFunc_ceilf: 1587 case LibFunc_ceill: 1588 case LibFunc_cos: 1589 case LibFunc_cosf: 1590 case LibFunc_cosh: 1591 case LibFunc_cosh_finite: 1592 case LibFunc_coshf: 1593 case LibFunc_coshf_finite: 1594 case LibFunc_coshl: 1595 case LibFunc_coshl_finite: 1596 case LibFunc_cosl: 1597 case LibFunc_exp10: 1598 case LibFunc_exp10_finite: 1599 case LibFunc_exp10f: 1600 case LibFunc_exp10f_finite: 1601 case LibFunc_exp10l: 1602 case LibFunc_exp10l_finite: 1603 case LibFunc_exp2: 1604 case LibFunc_exp2_finite: 1605 case LibFunc_exp2f: 1606 case LibFunc_exp2f_finite: 1607 case LibFunc_exp2l: 1608 case LibFunc_exp2l_finite: 1609 case LibFunc_exp: 1610 case LibFunc_exp_finite: 1611 case LibFunc_expf: 1612 case LibFunc_expf_finite: 1613 case LibFunc_expl: 1614 case LibFunc_expl_finite: 1615 case LibFunc_expm1: 1616 case LibFunc_expm1f: 1617 case LibFunc_expm1l: 1618 case LibFunc_fabs: 1619 case LibFunc_fabsf: 1620 case LibFunc_fabsl: 1621 case LibFunc_floor: 1622 case LibFunc_floorf: 1623 case LibFunc_floorl: 1624 case LibFunc_log10: 1625 case LibFunc_log10_finite: 1626 case LibFunc_log10f: 1627 case LibFunc_log10f_finite: 1628 case LibFunc_log10l: 1629 case LibFunc_log10l_finite: 1630 case LibFunc_log1p: 1631 case LibFunc_log1pf: 1632 case LibFunc_log1pl: 1633 case LibFunc_log2: 1634 case LibFunc_log2_finite: 1635 case LibFunc_log2f: 1636 case LibFunc_log2f_finite: 1637 case LibFunc_log2l: 1638 case LibFunc_log2l_finite: 1639 case LibFunc_log: 1640 case LibFunc_log_finite: 1641 case LibFunc_logb: 1642 case LibFunc_logbf: 1643 case LibFunc_logbl: 1644 case LibFunc_logf: 1645 case LibFunc_logf_finite: 1646 case LibFunc_logl: 1647 case LibFunc_logl_finite: 1648 case LibFunc_nearbyint: 1649 case LibFunc_nearbyintf: 1650 case LibFunc_nearbyintl: 1651 case LibFunc_rint: 1652 case LibFunc_rintf: 1653 case LibFunc_rintl: 1654 case LibFunc_round: 1655 case LibFunc_roundf: 1656 case LibFunc_roundl: 1657 case LibFunc_roundeven: 1658 case LibFunc_roundevenf: 1659 case LibFunc_roundevenl: 1660 case LibFunc_sin: 1661 case LibFunc_sinf: 1662 case LibFunc_sinh: 1663 case LibFunc_sinh_finite: 1664 case LibFunc_sinhf: 1665 case LibFunc_sinhf_finite: 1666 case LibFunc_sinhl: 1667 case LibFunc_sinhl_finite: 1668 case LibFunc_sinl: 1669 case LibFunc_sqrt: 1670 case LibFunc_sqrt_finite: 1671 case LibFunc_sqrtf: 1672 case LibFunc_sqrtf_finite: 1673 case LibFunc_sqrtl: 1674 case LibFunc_sqrtl_finite: 1675 case LibFunc_tan: 1676 case LibFunc_tanf: 1677 case LibFunc_tanh: 1678 case LibFunc_tanhf: 1679 case LibFunc_tanhl: 1680 case LibFunc_tanl: 1681 case LibFunc_trunc: 1682 case LibFunc_truncf: 1683 case LibFunc_truncl: 1684 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 1685 FTy.getReturnType() == FTy.getParamType(0)); 1686 1687 case LibFunc_atan2: 1688 case LibFunc_atan2_finite: 1689 case LibFunc_atan2f: 1690 case LibFunc_atan2f_finite: 1691 case LibFunc_atan2l: 1692 case LibFunc_atan2l_finite: 1693 case LibFunc_fmin: 1694 case LibFunc_fminf: 1695 case LibFunc_fminl: 1696 case LibFunc_fmax: 1697 case LibFunc_fmaxf: 1698 case LibFunc_fmaxl: 1699 case LibFunc_fmod: 1700 case LibFunc_fmodf: 1701 case LibFunc_fmodl: 1702 case LibFunc_remainder: 1703 case LibFunc_remainderf: 1704 case LibFunc_remainderl: 1705 case LibFunc_copysign: 1706 case LibFunc_copysignf: 1707 case LibFunc_copysignl: 1708 case LibFunc_pow: 1709 case LibFunc_pow_finite: 1710 case LibFunc_powf: 1711 case LibFunc_powf_finite: 1712 case LibFunc_powl: 1713 case LibFunc_powl_finite: 1714 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1715 FTy.getReturnType() == FTy.getParamType(0) && 1716 FTy.getReturnType() == FTy.getParamType(1)); 1717 1718 case LibFunc_ldexp: 1719 case LibFunc_ldexpf: 1720 case LibFunc_ldexpl: 1721 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1722 FTy.getReturnType() == FTy.getParamType(0) && 1723 FTy.getParamType(1)->isIntegerTy(getIntSize())); 1724 1725 case LibFunc_ffs: 1726 case LibFunc_ffsl: 1727 case LibFunc_ffsll: 1728 case LibFunc_fls: 1729 case LibFunc_flsl: 1730 case LibFunc_flsll: 1731 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 1732 FTy.getParamType(0)->isIntegerTy()); 1733 1734 case LibFunc_isdigit: 1735 case LibFunc_isascii: 1736 case LibFunc_toascii: 1737 case LibFunc_putchar: 1738 case LibFunc_putchar_unlocked: 1739 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 1740 FTy.getReturnType() == FTy.getParamType(0)); 1741 1742 case LibFunc_abs: 1743 case LibFunc_labs: 1744 case LibFunc_llabs: 1745 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1746 FTy.getReturnType() == FTy.getParamType(0)); 1747 1748 case LibFunc_cxa_atexit: 1749 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1750 FTy.getParamType(0)->isPointerTy() && 1751 FTy.getParamType(1)->isPointerTy() && 1752 FTy.getParamType(2)->isPointerTy()); 1753 1754 case LibFunc_sinpi: 1755 case LibFunc_cospi: 1756 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1757 FTy.getReturnType() == FTy.getParamType(0)); 1758 1759 case LibFunc_sinpif: 1760 case LibFunc_cospif: 1761 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1762 FTy.getReturnType() == FTy.getParamType(0)); 1763 1764 case LibFunc_strnlen: 1765 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && 1766 FTy.getParamType(0)->isPointerTy() && 1767 FTy.getParamType(1)->isIntegerTy(SizeTBits)); 1768 1769 case LibFunc_posix_memalign: 1770 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 1771 FTy.getParamType(0)->isPointerTy() && 1772 FTy.getParamType(1)->isIntegerTy(SizeTBits) && 1773 FTy.getParamType(2)->isIntegerTy(SizeTBits)); 1774 1775 case LibFunc_wcslen: 1776 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 1777 FTy.getReturnType()->isIntegerTy()); 1778 1779 case LibFunc_cabs: 1780 case LibFunc_cabsf: 1781 case LibFunc_cabsl: { 1782 Type* RetTy = FTy.getReturnType(); 1783 if (!RetTy->isFloatingPointTy()) 1784 return false; 1785 1786 // NOTE: These prototypes are target specific and currently support 1787 // "complex" passed as an array or discrete real & imaginary parameters. 1788 // Add other calling conventions to enable libcall optimizations. 1789 if (NumParams == 1) 1790 return (FTy.getParamType(0)->isArrayTy() && 1791 FTy.getParamType(0)->getArrayNumElements() == 2 && 1792 FTy.getParamType(0)->getArrayElementType() == RetTy); 1793 else if (NumParams == 2) 1794 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy); 1795 else 1796 return false; 1797 } 1798 case LibFunc::NumLibFuncs: 1799 case LibFunc::NotLibFunc: 1800 break; 1801 } 1802 1803 llvm_unreachable("Invalid libfunc"); 1804 } 1805 1806 bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1807 LibFunc &F) const { 1808 // Intrinsics don't overlap w/libcalls; if our module has a large number of 1809 // intrinsics, this ends up being an interesting compile time win since we 1810 // avoid string normalization and comparison. 1811 if (FDecl.isIntrinsic()) return false; 1812 1813 const Module *M = FDecl.getParent(); 1814 assert(M && "Expecting FDecl to be connected to a Module."); 1815 1816 return getLibFunc(FDecl.getName(), F) && 1817 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M); 1818 } 1819 1820 void TargetLibraryInfoImpl::disableAllFunctions() { 1821 memset(AvailableArray, 0, sizeof(AvailableArray)); 1822 } 1823 1824 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 1825 return LHS.ScalarFnName < RHS.ScalarFnName; 1826 } 1827 1828 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 1829 return LHS.VectorFnName < RHS.VectorFnName; 1830 } 1831 1832 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 1833 return LHS.ScalarFnName < S; 1834 } 1835 1836 void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1837 llvm::append_range(VectorDescs, Fns); 1838 llvm::sort(VectorDescs, compareByScalarFnName); 1839 1840 llvm::append_range(ScalarDescs, Fns); 1841 llvm::sort(ScalarDescs, compareByVectorFnName); 1842 } 1843 1844 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 1845 enum VectorLibrary VecLib) { 1846 switch (VecLib) { 1847 case Accelerate: { 1848 const VecDesc VecFuncs[] = { 1849 #define TLI_DEFINE_ACCELERATE_VECFUNCS 1850 #include "llvm/Analysis/VecFuncs.def" 1851 }; 1852 addVectorizableFunctions(VecFuncs); 1853 break; 1854 } 1855 case DarwinLibSystemM: { 1856 const VecDesc VecFuncs[] = { 1857 #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS 1858 #include "llvm/Analysis/VecFuncs.def" 1859 }; 1860 addVectorizableFunctions(VecFuncs); 1861 break; 1862 } 1863 case LIBMVEC_X86: { 1864 const VecDesc VecFuncs[] = { 1865 #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS 1866 #include "llvm/Analysis/VecFuncs.def" 1867 }; 1868 addVectorizableFunctions(VecFuncs); 1869 break; 1870 } 1871 case MASSV: { 1872 const VecDesc VecFuncs[] = { 1873 #define TLI_DEFINE_MASSV_VECFUNCS 1874 #include "llvm/Analysis/VecFuncs.def" 1875 }; 1876 addVectorizableFunctions(VecFuncs); 1877 break; 1878 } 1879 case SVML: { 1880 const VecDesc VecFuncs[] = { 1881 #define TLI_DEFINE_SVML_VECFUNCS 1882 #include "llvm/Analysis/VecFuncs.def" 1883 }; 1884 addVectorizableFunctions(VecFuncs); 1885 break; 1886 } 1887 case NoLibrary: 1888 break; 1889 } 1890 } 1891 1892 bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1893 funcName = sanitizeFunctionName(funcName); 1894 if (funcName.empty()) 1895 return false; 1896 1897 std::vector<VecDesc>::const_iterator I = 1898 llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName); 1899 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1900 } 1901 1902 StringRef 1903 TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 1904 const ElementCount &VF) const { 1905 F = sanitizeFunctionName(F); 1906 if (F.empty()) 1907 return F; 1908 std::vector<VecDesc>::const_iterator I = 1909 llvm::lower_bound(VectorDescs, F, compareWithScalarFnName); 1910 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1911 if (I->VectorizationFactor == VF) 1912 return I->VectorFnName; 1913 ++I; 1914 } 1915 return StringRef(); 1916 } 1917 1918 TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F, 1919 FunctionAnalysisManager &) { 1920 if (!BaselineInfoImpl) 1921 BaselineInfoImpl = 1922 TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple())); 1923 return TargetLibraryInfo(*BaselineInfoImpl, &F); 1924 } 1925 1926 unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { 1927 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>( 1928 M.getModuleFlag("wchar_size"))) 1929 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue(); 1930 return 0; 1931 } 1932 1933 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1934 : ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) { 1935 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1936 } 1937 1938 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1939 : ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) { 1940 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1941 } 1942 1943 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1944 const TargetLibraryInfoImpl &TLIImpl) 1945 : ImmutablePass(ID), TLA(TLIImpl) { 1946 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1947 } 1948 1949 AnalysisKey TargetLibraryAnalysis::Key; 1950 1951 // Register the basic pass. 1952 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1953 "Target Library Information", false, true) 1954 char TargetLibraryInfoWrapperPass::ID = 0; 1955 1956 void TargetLibraryInfoWrapperPass::anchor() {} 1957 1958 void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF, 1959 ElementCount &FixedVF, 1960 ElementCount &ScalableVF) const { 1961 ScalarF = sanitizeFunctionName(ScalarF); 1962 // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the 1963 // same as a scalar. 1964 ScalableVF = ElementCount::getScalable(0); 1965 FixedVF = ElementCount::getFixed(1); 1966 if (ScalarF.empty()) 1967 return; 1968 1969 std::vector<VecDesc>::const_iterator I = 1970 llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName); 1971 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) { 1972 ElementCount *VF = 1973 I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF; 1974 if (ElementCount::isKnownGT(I->VectorizationFactor, *VF)) 1975 *VF = I->VectorizationFactor; 1976 ++I; 1977 } 1978 } 1979