12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976 |
- //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- //
- // This file implements the TargetLibraryInfo class.
- //
- //===----------------------------------------------------------------------===//
- #include "llvm/Analysis/TargetLibraryInfo.h"
- #include "llvm/ADT/Triple.h"
- #include "llvm/IR/Constants.h"
- #include "llvm/InitializePasses.h"
- #include "llvm/Support/CommandLine.h"
- using namespace llvm;
- static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
- "vector-library", cl::Hidden, cl::desc("Vector functions library"),
- cl::init(TargetLibraryInfoImpl::NoLibrary),
- cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
- "No vector functions library"),
- clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
- "Accelerate framework"),
- clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM,
- "Darwin_libsystem_m", "Darwin libsystem_m"),
- clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86",
- "GLIBC Vector Math library"),
- clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
- "IBM MASS vector library"),
- clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
- "Intel SVML library")));
- StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
- {
- #define TLI_DEFINE_STRING
- #include "llvm/Analysis/TargetLibraryInfo.def"
- };
- static bool hasSinCosPiStret(const Triple &T) {
- // Only Darwin variants have _stret versions of combined trig functions.
- if (!T.isOSDarwin())
- return false;
- // The ABI is rather complicated on x86, so don't do anything special there.
- if (T.getArch() == Triple::x86)
- return false;
- if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
- return false;
- if (T.isiOS() && T.isOSVersionLT(7, 0))
- return false;
- return true;
- }
- static bool hasBcmp(const Triple &TT) {
- // Posix removed support from bcmp() in 2001, but the glibc and several
- // implementations of the libc still have it.
- if (TT.isOSLinux())
- return TT.isGNUEnvironment() || TT.isMusl();
- // Both NetBSD and OpenBSD are planning to remove the function. Windows does
- // not have it.
- return TT.isOSFreeBSD() || TT.isOSSolaris();
- }
- static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
- FunctionType *FuncTy) {
- switch (CC) {
- default:
- return false;
- case llvm::CallingConv::C:
- return true;
- case llvm::CallingConv::ARM_APCS:
- case llvm::CallingConv::ARM_AAPCS:
- case llvm::CallingConv::ARM_AAPCS_VFP: {
- // The iOS ABI diverges from the standard in some cases, so for now don't
- // try to simplify those calls.
- if (Triple(TT).isiOS())
- return false;
- if (!FuncTy->getReturnType()->isPointerTy() &&
- !FuncTy->getReturnType()->isIntegerTy() &&
- !FuncTy->getReturnType()->isVoidTy())
- return false;
- for (auto *Param : FuncTy->params()) {
- if (!Param->isPointerTy() && !Param->isIntegerTy())
- return false;
- }
- return true;
- }
- }
- return false;
- }
- bool TargetLibraryInfoImpl::isCallingConvCCompatible(CallBase *CI) {
- return ::isCallingConvCCompatible(CI->getCallingConv(),
- CI->getModule()->getTargetTriple(),
- CI->getFunctionType());
- }
- bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) {
- return ::isCallingConvCCompatible(F->getCallingConv(),
- F->getParent()->getTargetTriple(),
- F->getFunctionType());
- }
- /// Initialize the set of available library functions based on the specified
- /// target triple. This should be carefully written so that a missing target
- /// triple gets a sane set of defaults.
- static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
- ArrayRef<StringLiteral> StandardNames) {
- // Verify that the StandardNames array is in alphabetical order.
- assert(
- llvm::is_sorted(StandardNames,
- [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) &&
- "TargetLibraryInfoImpl function names must be sorted");
- // Set IO unlocked variants as unavailable
- // Set them as available per system below
- TLI.setUnavailable(LibFunc_getc_unlocked);
- TLI.setUnavailable(LibFunc_getchar_unlocked);
- TLI.setUnavailable(LibFunc_putc_unlocked);
- TLI.setUnavailable(LibFunc_putchar_unlocked);
- TLI.setUnavailable(LibFunc_fputc_unlocked);
- TLI.setUnavailable(LibFunc_fgetc_unlocked);
- TLI.setUnavailable(LibFunc_fread_unlocked);
- TLI.setUnavailable(LibFunc_fwrite_unlocked);
- TLI.setUnavailable(LibFunc_fputs_unlocked);
- TLI.setUnavailable(LibFunc_fgets_unlocked);
- bool ShouldExtI32Param = false, ShouldExtI32Return = false,
- ShouldSignExtI32Param = false;
- // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
- // returns corresponding to C-level ints and unsigned ints.
- if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
- T.getArch() == Triple::systemz) {
- ShouldExtI32Param = true;
- ShouldExtI32Return = true;
- }
- // Mips, on the other hand, needs signext on i32 parameters corresponding
- // to both signed and unsigned ints.
- if (T.isMIPS()) {
- ShouldSignExtI32Param = true;
- }
- TLI.setShouldExtI32Param(ShouldExtI32Param);
- TLI.setShouldExtI32Return(ShouldExtI32Return);
- TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
- // Let's assume by default that the size of int is 32 bits, unless the target
- // is a 16-bit architecture because then it most likely is 16 bits. If that
- // isn't true for a target those defaults should be overridden below.
- TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
- // There is really no runtime library on AMDGPU, apart from
- // __kmpc_alloc/free_shared.
- if (T.isAMDGPU()) {
- TLI.disableAllFunctions();
- TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
- TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
- return;
- }
- // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and
- // later. All versions of watchOS support it.
- if (T.isMacOSX()) {
- // available IO unlocked variants on Mac OS X
- TLI.setAvailable(LibFunc_getc_unlocked);
- TLI.setAvailable(LibFunc_getchar_unlocked);
- TLI.setAvailable(LibFunc_putc_unlocked);
- TLI.setAvailable(LibFunc_putchar_unlocked);
- if (T.isMacOSXVersionLT(10, 5)) {
- TLI.setUnavailable(LibFunc_memset_pattern4);
- TLI.setUnavailable(LibFunc_memset_pattern8);
- TLI.setUnavailable(LibFunc_memset_pattern16);
- }
- } else if (T.isiOS()) {
- if (T.isOSVersionLT(3, 0)) {
- TLI.setUnavailable(LibFunc_memset_pattern4);
- TLI.setUnavailable(LibFunc_memset_pattern8);
- TLI.setUnavailable(LibFunc_memset_pattern16);
- }
- } else if (!T.isWatchOS()) {
- TLI.setUnavailable(LibFunc_memset_pattern4);
- TLI.setUnavailable(LibFunc_memset_pattern8);
- TLI.setUnavailable(LibFunc_memset_pattern16);
- }
- if (!hasSinCosPiStret(T)) {
- TLI.setUnavailable(LibFunc_sinpi);
- TLI.setUnavailable(LibFunc_sinpif);
- TLI.setUnavailable(LibFunc_cospi);
- TLI.setUnavailable(LibFunc_cospif);
- TLI.setUnavailable(LibFunc_sincospi_stret);
- TLI.setUnavailable(LibFunc_sincospif_stret);
- }
- if (!hasBcmp(T))
- TLI.setUnavailable(LibFunc_bcmp);
- if (T.isMacOSX() && T.getArch() == Triple::x86 &&
- !T.isMacOSXVersionLT(10, 7)) {
- // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
- // we don't care about) have two versions; on recent OSX, the one we want
- // has a $UNIX2003 suffix. The two implementations are identical except
- // for the return value in some edge cases. However, we don't want to
- // generate code that depends on the old symbols.
- TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
- TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
- }
- // iprintf and friends are only available on XCore, TCE, and Emscripten.
- if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
- T.getOS() != Triple::Emscripten) {
- TLI.setUnavailable(LibFunc_iprintf);
- TLI.setUnavailable(LibFunc_siprintf);
- TLI.setUnavailable(LibFunc_fiprintf);
- }
- // __small_printf and friends are only available on Emscripten.
- if (T.getOS() != Triple::Emscripten) {
- TLI.setUnavailable(LibFunc_small_printf);
- TLI.setUnavailable(LibFunc_small_sprintf);
- TLI.setUnavailable(LibFunc_small_fprintf);
- }
- if (T.isOSWindows() && !T.isOSCygMing()) {
- // XXX: The earliest documentation available at the moment is for VS2015/VC19:
- // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
- // XXX: In order to use an MSVCRT older than VC19,
- // the specific library version must be explicit in the target triple,
- // e.g., x86_64-pc-windows-msvc18.
- bool hasPartialC99 = true;
- if (T.isKnownWindowsMSVCEnvironment()) {
- VersionTuple Version = T.getEnvironmentVersion();
- hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19);
- }
- // Latest targets support C89 math functions, in part.
- bool isARM = (T.getArch() == Triple::aarch64 ||
- T.getArch() == Triple::arm);
- bool hasPartialFloat = (isARM ||
- T.getArch() == Triple::x86_64);
- // Win32 does not support float C89 math functions, in general.
- if (!hasPartialFloat) {
- TLI.setUnavailable(LibFunc_acosf);
- TLI.setUnavailable(LibFunc_asinf);
- TLI.setUnavailable(LibFunc_atan2f);
- TLI.setUnavailable(LibFunc_atanf);
- TLI.setUnavailable(LibFunc_ceilf);
- TLI.setUnavailable(LibFunc_cosf);
- TLI.setUnavailable(LibFunc_coshf);
- TLI.setUnavailable(LibFunc_expf);
- TLI.setUnavailable(LibFunc_floorf);
- TLI.setUnavailable(LibFunc_fmodf);
- TLI.setUnavailable(LibFunc_log10f);
- TLI.setUnavailable(LibFunc_logf);
- TLI.setUnavailable(LibFunc_modff);
- TLI.setUnavailable(LibFunc_powf);
- TLI.setUnavailable(LibFunc_remainderf);
- TLI.setUnavailable(LibFunc_sinf);
- TLI.setUnavailable(LibFunc_sinhf);
- TLI.setUnavailable(LibFunc_sqrtf);
- TLI.setUnavailable(LibFunc_tanf);
- TLI.setUnavailable(LibFunc_tanhf);
- }
- if (!isARM)
- TLI.setUnavailable(LibFunc_fabsf);
- TLI.setUnavailable(LibFunc_frexpf);
- TLI.setUnavailable(LibFunc_ldexpf);
- // Win32 does not support long double C89 math functions.
- TLI.setUnavailable(LibFunc_acosl);
- TLI.setUnavailable(LibFunc_asinl);
- TLI.setUnavailable(LibFunc_atan2l);
- TLI.setUnavailable(LibFunc_atanl);
- TLI.setUnavailable(LibFunc_ceill);
- TLI.setUnavailable(LibFunc_cosl);
- TLI.setUnavailable(LibFunc_coshl);
- TLI.setUnavailable(LibFunc_expl);
- TLI.setUnavailable(LibFunc_fabsl);
- TLI.setUnavailable(LibFunc_floorl);
- TLI.setUnavailable(LibFunc_fmodl);
- TLI.setUnavailable(LibFunc_frexpl);
- TLI.setUnavailable(LibFunc_ldexpl);
- TLI.setUnavailable(LibFunc_log10l);
- TLI.setUnavailable(LibFunc_logl);
- TLI.setUnavailable(LibFunc_modfl);
- TLI.setUnavailable(LibFunc_powl);
- TLI.setUnavailable(LibFunc_remainderl);
- TLI.setUnavailable(LibFunc_sinl);
- TLI.setUnavailable(LibFunc_sinhl);
- TLI.setUnavailable(LibFunc_sqrtl);
- TLI.setUnavailable(LibFunc_tanl);
- TLI.setUnavailable(LibFunc_tanhl);
- // Win32 does not fully support C99 math functions.
- if (!hasPartialC99) {
- TLI.setUnavailable(LibFunc_acosh);
- TLI.setUnavailable(LibFunc_acoshf);
- TLI.setUnavailable(LibFunc_asinh);
- TLI.setUnavailable(LibFunc_asinhf);
- TLI.setUnavailable(LibFunc_atanh);
- TLI.setUnavailable(LibFunc_atanhf);
- TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
- TLI.setUnavailable(LibFunc_cabsf);
- TLI.setUnavailable(LibFunc_cbrt);
- TLI.setUnavailable(LibFunc_cbrtf);
- TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
- TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
- TLI.setUnavailable(LibFunc_exp2);
- TLI.setUnavailable(LibFunc_exp2f);
- TLI.setUnavailable(LibFunc_expm1);
- TLI.setUnavailable(LibFunc_expm1f);
- TLI.setUnavailable(LibFunc_fmax);
- TLI.setUnavailable(LibFunc_fmaxf);
- TLI.setUnavailable(LibFunc_fmin);
- TLI.setUnavailable(LibFunc_fminf);
- TLI.setUnavailable(LibFunc_log1p);
- TLI.setUnavailable(LibFunc_log1pf);
- TLI.setUnavailable(LibFunc_log2);
- TLI.setUnavailable(LibFunc_log2f);
- TLI.setAvailableWithName(LibFunc_logb, "_logb");
- if (hasPartialFloat)
- TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
- else
- TLI.setUnavailable(LibFunc_logbf);
- TLI.setUnavailable(LibFunc_rint);
- TLI.setUnavailable(LibFunc_rintf);
- TLI.setUnavailable(LibFunc_round);
- TLI.setUnavailable(LibFunc_roundf);
- TLI.setUnavailable(LibFunc_trunc);
- TLI.setUnavailable(LibFunc_truncf);
- }
- // Win32 does not support long double C99 math functions.
- TLI.setUnavailable(LibFunc_acoshl);
- TLI.setUnavailable(LibFunc_asinhl);
- TLI.setUnavailable(LibFunc_atanhl);
- TLI.setUnavailable(LibFunc_cabsl);
- TLI.setUnavailable(LibFunc_cbrtl);
- TLI.setUnavailable(LibFunc_copysignl);
- TLI.setUnavailable(LibFunc_exp2l);
- TLI.setUnavailable(LibFunc_expm1l);
- TLI.setUnavailable(LibFunc_fmaxl);
- TLI.setUnavailable(LibFunc_fminl);
- TLI.setUnavailable(LibFunc_log1pl);
- TLI.setUnavailable(LibFunc_log2l);
- TLI.setUnavailable(LibFunc_logbl);
- TLI.setUnavailable(LibFunc_nearbyintl);
- TLI.setUnavailable(LibFunc_rintl);
- TLI.setUnavailable(LibFunc_roundl);
- TLI.setUnavailable(LibFunc_truncl);
- // Win32 does not support these functions, but
- // they are generally available on POSIX-compliant systems.
- TLI.setUnavailable(LibFunc_access);
- TLI.setUnavailable(LibFunc_chmod);
- TLI.setUnavailable(LibFunc_closedir);
- TLI.setUnavailable(LibFunc_fdopen);
- TLI.setUnavailable(LibFunc_fileno);
- TLI.setUnavailable(LibFunc_fseeko);
- TLI.setUnavailable(LibFunc_fstat);
- TLI.setUnavailable(LibFunc_ftello);
- TLI.setUnavailable(LibFunc_gettimeofday);
- TLI.setUnavailable(LibFunc_memccpy);
- TLI.setUnavailable(LibFunc_mkdir);
- TLI.setUnavailable(LibFunc_open);
- TLI.setUnavailable(LibFunc_opendir);
- TLI.setUnavailable(LibFunc_pclose);
- TLI.setUnavailable(LibFunc_popen);
- TLI.setUnavailable(LibFunc_read);
- TLI.setUnavailable(LibFunc_rmdir);
- TLI.setUnavailable(LibFunc_stat);
- TLI.setUnavailable(LibFunc_strcasecmp);
- TLI.setUnavailable(LibFunc_strncasecmp);
- TLI.setUnavailable(LibFunc_unlink);
- TLI.setUnavailable(LibFunc_utime);
- TLI.setUnavailable(LibFunc_write);
- }
- if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) {
- // These functions aren't available in either MSVC or MinGW environments.
- TLI.setUnavailable(LibFunc_bcmp);
- TLI.setUnavailable(LibFunc_bcopy);
- TLI.setUnavailable(LibFunc_bzero);
- TLI.setUnavailable(LibFunc_chown);
- TLI.setUnavailable(LibFunc_ctermid);
- TLI.setUnavailable(LibFunc_ffs);
- TLI.setUnavailable(LibFunc_flockfile);
- TLI.setUnavailable(LibFunc_fstatvfs);
- TLI.setUnavailable(LibFunc_ftrylockfile);
- TLI.setUnavailable(LibFunc_funlockfile);
- TLI.setUnavailable(LibFunc_getitimer);
- TLI.setUnavailable(LibFunc_getlogin_r);
- TLI.setUnavailable(LibFunc_getpwnam);
- TLI.setUnavailable(LibFunc_htonl);
- TLI.setUnavailable(LibFunc_htons);
- TLI.setUnavailable(LibFunc_lchown);
- TLI.setUnavailable(LibFunc_lstat);
- TLI.setUnavailable(LibFunc_ntohl);
- TLI.setUnavailable(LibFunc_ntohs);
- TLI.setUnavailable(LibFunc_pread);
- TLI.setUnavailable(LibFunc_pwrite);
- TLI.setUnavailable(LibFunc_readlink);
- TLI.setUnavailable(LibFunc_realpath);
- TLI.setUnavailable(LibFunc_setitimer);
- TLI.setUnavailable(LibFunc_statvfs);
- TLI.setUnavailable(LibFunc_stpcpy);
- TLI.setUnavailable(LibFunc_stpncpy);
- TLI.setUnavailable(LibFunc_times);
- TLI.setUnavailable(LibFunc_uname);
- TLI.setUnavailable(LibFunc_unsetenv);
- TLI.setUnavailable(LibFunc_utimes);
- }
- // Pick just one set of new/delete variants.
- if (T.isOSMSVCRT()) {
- // MSVC, doesn't have the Itanium new/delete.
- TLI.setUnavailable(LibFunc_ZdaPv);
- TLI.setUnavailable(LibFunc_ZdaPvRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZdaPvj);
- TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdaPvm);
- TLI.setUnavailable(LibFunc_ZdaPvmSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdlPv);
- TLI.setUnavailable(LibFunc_ZdlPvRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZdlPvj);
- TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdlPvm);
- TLI.setUnavailable(LibFunc_ZdlPvmSt11align_val_t);
- TLI.setUnavailable(LibFunc_Znaj);
- TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_Znam);
- TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnamSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_Znwj);
- TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_Znwm);
- TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t);
- } else {
- // Not MSVC, assume it's Itanium.
- TLI.setUnavailable(LibFunc_msvc_new_int);
- TLI.setUnavailable(LibFunc_msvc_new_int_nothrow);
- TLI.setUnavailable(LibFunc_msvc_new_longlong);
- TLI.setUnavailable(LibFunc_msvc_new_longlong_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr32);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr32_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr32_int);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr64);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr64_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_ptr64_longlong);
- TLI.setUnavailable(LibFunc_msvc_new_array_int);
- TLI.setUnavailable(LibFunc_msvc_new_array_int_nothrow);
- TLI.setUnavailable(LibFunc_msvc_new_array_longlong);
- TLI.setUnavailable(LibFunc_msvc_new_array_longlong_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_int);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_nothrow);
- TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_longlong);
- }
- switch (T.getOS()) {
- case Triple::MacOSX:
- // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
- // and their names are __exp10 and __exp10f. exp10l is not available on
- // OS X or iOS.
- TLI.setUnavailable(LibFunc_exp10l);
- if (T.isMacOSXVersionLT(10, 9)) {
- TLI.setUnavailable(LibFunc_exp10);
- TLI.setUnavailable(LibFunc_exp10f);
- } else {
- TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
- TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
- }
- break;
- case Triple::IOS:
- case Triple::TvOS:
- case Triple::WatchOS:
- TLI.setUnavailable(LibFunc_exp10l);
- if (!T.isWatchOS() &&
- (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
- TLI.setUnavailable(LibFunc_exp10);
- TLI.setUnavailable(LibFunc_exp10f);
- } else {
- TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
- TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
- }
- break;
- case Triple::Linux:
- // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
- // buggy prior to glibc version 2.18. Until this version is widely deployed
- // or we have a reasonable detection strategy, we cannot use exp10 reliably
- // on Linux.
- //
- // Fall through to disable all of them.
- LLVM_FALLTHROUGH;
- default:
- TLI.setUnavailable(LibFunc_exp10);
- TLI.setUnavailable(LibFunc_exp10f);
- TLI.setUnavailable(LibFunc_exp10l);
- }
- // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
- // Linux (GLIBC):
- // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
- // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
- // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
- switch (T.getOS()) {
- case Triple::Darwin:
- case Triple::MacOSX:
- case Triple::IOS:
- case Triple::TvOS:
- case Triple::WatchOS:
- case Triple::FreeBSD:
- case Triple::Linux:
- break;
- default:
- TLI.setUnavailable(LibFunc_ffsl);
- }
- // ffsll is available on at least FreeBSD and Linux (GLIBC):
- // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
- // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
- switch (T.getOS()) {
- case Triple::Darwin:
- case Triple::MacOSX:
- case Triple::IOS:
- case Triple::TvOS:
- case Triple::WatchOS:
- case Triple::FreeBSD:
- case Triple::Linux:
- break;
- default:
- TLI.setUnavailable(LibFunc_ffsll);
- }
- // The following functions are available on at least FreeBSD:
- // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
- // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
- // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
- if (!T.isOSFreeBSD()) {
- TLI.setUnavailable(LibFunc_fls);
- TLI.setUnavailable(LibFunc_flsl);
- TLI.setUnavailable(LibFunc_flsll);
- }
- // The following functions are only available on GNU/Linux (using glibc).
- // Linux variants without glibc (eg: bionic, musl) may have some subset.
- if (!T.isOSLinux() || !T.isGNUEnvironment()) {
- TLI.setUnavailable(LibFunc_dunder_strdup);
- TLI.setUnavailable(LibFunc_dunder_strtok_r);
- TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
- TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
- TLI.setUnavailable(LibFunc_under_IO_getc);
- TLI.setUnavailable(LibFunc_under_IO_putc);
- // But, Android and musl have memalign.
- if (!T.isAndroid() && !T.isMusl())
- TLI.setUnavailable(LibFunc_memalign);
- TLI.setUnavailable(LibFunc_fopen64);
- TLI.setUnavailable(LibFunc_fseeko64);
- TLI.setUnavailable(LibFunc_fstat64);
- TLI.setUnavailable(LibFunc_fstatvfs64);
- TLI.setUnavailable(LibFunc_ftello64);
- TLI.setUnavailable(LibFunc_lstat64);
- TLI.setUnavailable(LibFunc_open64);
- TLI.setUnavailable(LibFunc_stat64);
- TLI.setUnavailable(LibFunc_statvfs64);
- TLI.setUnavailable(LibFunc_tmpfile64);
- // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
- // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
- // so we keep these functions around just so that they're recognized by
- // the ConstantFolder.
- TLI.setUnavailable(LibFunc_acos_finite);
- TLI.setUnavailable(LibFunc_acosf_finite);
- TLI.setUnavailable(LibFunc_acosl_finite);
- TLI.setUnavailable(LibFunc_acosh_finite);
- TLI.setUnavailable(LibFunc_acoshf_finite);
- TLI.setUnavailable(LibFunc_acoshl_finite);
- TLI.setUnavailable(LibFunc_asin_finite);
- TLI.setUnavailable(LibFunc_asinf_finite);
- TLI.setUnavailable(LibFunc_asinl_finite);
- TLI.setUnavailable(LibFunc_atan2_finite);
- TLI.setUnavailable(LibFunc_atan2f_finite);
- TLI.setUnavailable(LibFunc_atan2l_finite);
- TLI.setUnavailable(LibFunc_atanh_finite);
- TLI.setUnavailable(LibFunc_atanhf_finite);
- TLI.setUnavailable(LibFunc_atanhl_finite);
- TLI.setUnavailable(LibFunc_cosh_finite);
- TLI.setUnavailable(LibFunc_coshf_finite);
- TLI.setUnavailable(LibFunc_coshl_finite);
- TLI.setUnavailable(LibFunc_exp10_finite);
- TLI.setUnavailable(LibFunc_exp10f_finite);
- TLI.setUnavailable(LibFunc_exp10l_finite);
- TLI.setUnavailable(LibFunc_exp2_finite);
- TLI.setUnavailable(LibFunc_exp2f_finite);
- TLI.setUnavailable(LibFunc_exp2l_finite);
- TLI.setUnavailable(LibFunc_exp_finite);
- TLI.setUnavailable(LibFunc_expf_finite);
- TLI.setUnavailable(LibFunc_expl_finite);
- TLI.setUnavailable(LibFunc_log10_finite);
- TLI.setUnavailable(LibFunc_log10f_finite);
- TLI.setUnavailable(LibFunc_log10l_finite);
- TLI.setUnavailable(LibFunc_log2_finite);
- TLI.setUnavailable(LibFunc_log2f_finite);
- TLI.setUnavailable(LibFunc_log2l_finite);
- TLI.setUnavailable(LibFunc_log_finite);
- TLI.setUnavailable(LibFunc_logf_finite);
- TLI.setUnavailable(LibFunc_logl_finite);
- TLI.setUnavailable(LibFunc_pow_finite);
- TLI.setUnavailable(LibFunc_powf_finite);
- TLI.setUnavailable(LibFunc_powl_finite);
- TLI.setUnavailable(LibFunc_sinh_finite);
- TLI.setUnavailable(LibFunc_sinhf_finite);
- TLI.setUnavailable(LibFunc_sinhl_finite);
- TLI.setUnavailable(LibFunc_sqrt_finite);
- TLI.setUnavailable(LibFunc_sqrtf_finite);
- TLI.setUnavailable(LibFunc_sqrtl_finite);
- }
- if ((T.isOSLinux() && T.isGNUEnvironment()) ||
- (T.isAndroid() && !T.isAndroidVersionLT(28))) {
- // available IO unlocked variants on GNU/Linux and Android P or later
- TLI.setAvailable(LibFunc_getc_unlocked);
- TLI.setAvailable(LibFunc_getchar_unlocked);
- TLI.setAvailable(LibFunc_putc_unlocked);
- TLI.setAvailable(LibFunc_putchar_unlocked);
- TLI.setAvailable(LibFunc_fputc_unlocked);
- TLI.setAvailable(LibFunc_fgetc_unlocked);
- TLI.setAvailable(LibFunc_fread_unlocked);
- TLI.setAvailable(LibFunc_fwrite_unlocked);
- TLI.setAvailable(LibFunc_fputs_unlocked);
- TLI.setAvailable(LibFunc_fgets_unlocked);
- }
- if (T.isAndroid() && T.isAndroidVersionLT(21)) {
- TLI.setUnavailable(LibFunc_stpcpy);
- TLI.setUnavailable(LibFunc_stpncpy);
- }
- if (T.isPS4()) {
- // PS4 does have memalign.
- TLI.setAvailable(LibFunc_memalign);
- // PS4 does not have new/delete with "unsigned int" size parameter;
- // it only has the "unsigned long" versions.
- TLI.setUnavailable(LibFunc_ZdaPvj);
- TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZdlPvj);
- TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
- TLI.setUnavailable(LibFunc_Znaj);
- TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_Znwj);
- TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
- TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
- TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
- // None of the *_chk functions.
- TLI.setUnavailable(LibFunc_memccpy_chk);
- TLI.setUnavailable(LibFunc_memcpy_chk);
- TLI.setUnavailable(LibFunc_memmove_chk);
- TLI.setUnavailable(LibFunc_mempcpy_chk);
- TLI.setUnavailable(LibFunc_memset_chk);
- TLI.setUnavailable(LibFunc_snprintf_chk);
- TLI.setUnavailable(LibFunc_sprintf_chk);
- TLI.setUnavailable(LibFunc_stpcpy_chk);
- TLI.setUnavailable(LibFunc_stpncpy_chk);
- TLI.setUnavailable(LibFunc_strcat_chk);
- TLI.setUnavailable(LibFunc_strcpy_chk);
- TLI.setUnavailable(LibFunc_strlcat_chk);
- TLI.setUnavailable(LibFunc_strlcpy_chk);
- TLI.setUnavailable(LibFunc_strlen_chk);
- TLI.setUnavailable(LibFunc_strncat_chk);
- TLI.setUnavailable(LibFunc_strncpy_chk);
- TLI.setUnavailable(LibFunc_vsnprintf_chk);
- TLI.setUnavailable(LibFunc_vsprintf_chk);
- // Various Posix system functions.
- TLI.setUnavailable(LibFunc_access);
- TLI.setUnavailable(LibFunc_chmod);
- TLI.setUnavailable(LibFunc_chown);
- TLI.setUnavailable(LibFunc_closedir);
- TLI.setUnavailable(LibFunc_ctermid);
- TLI.setUnavailable(LibFunc_execl);
- TLI.setUnavailable(LibFunc_execle);
- TLI.setUnavailable(LibFunc_execlp);
- TLI.setUnavailable(LibFunc_execv);
- TLI.setUnavailable(LibFunc_execvP);
- TLI.setUnavailable(LibFunc_execve);
- TLI.setUnavailable(LibFunc_execvp);
- TLI.setUnavailable(LibFunc_execvpe);
- TLI.setUnavailable(LibFunc_fork);
- TLI.setUnavailable(LibFunc_fstat);
- TLI.setUnavailable(LibFunc_fstatvfs);
- TLI.setUnavailable(LibFunc_getenv);
- TLI.setUnavailable(LibFunc_getitimer);
- TLI.setUnavailable(LibFunc_getlogin_r);
- TLI.setUnavailable(LibFunc_getpwnam);
- TLI.setUnavailable(LibFunc_gettimeofday);
- TLI.setUnavailable(LibFunc_lchown);
- TLI.setUnavailable(LibFunc_lstat);
- TLI.setUnavailable(LibFunc_mkdir);
- TLI.setUnavailable(LibFunc_open);
- TLI.setUnavailable(LibFunc_opendir);
- TLI.setUnavailable(LibFunc_pclose);
- TLI.setUnavailable(LibFunc_popen);
- TLI.setUnavailable(LibFunc_pread);
- TLI.setUnavailable(LibFunc_pwrite);
- TLI.setUnavailable(LibFunc_read);
- TLI.setUnavailable(LibFunc_readlink);
- TLI.setUnavailable(LibFunc_realpath);
- TLI.setUnavailable(LibFunc_rename);
- TLI.setUnavailable(LibFunc_rmdir);
- TLI.setUnavailable(LibFunc_setitimer);
- TLI.setUnavailable(LibFunc_stat);
- TLI.setUnavailable(LibFunc_statvfs);
- TLI.setUnavailable(LibFunc_system);
- TLI.setUnavailable(LibFunc_times);
- TLI.setUnavailable(LibFunc_tmpfile);
- TLI.setUnavailable(LibFunc_unlink);
- TLI.setUnavailable(LibFunc_uname);
- TLI.setUnavailable(LibFunc_unsetenv);
- TLI.setUnavailable(LibFunc_utime);
- TLI.setUnavailable(LibFunc_utimes);
- TLI.setUnavailable(LibFunc_valloc);
- TLI.setUnavailable(LibFunc_write);
- // Miscellaneous other functions not provided.
- TLI.setUnavailable(LibFunc_atomic_load);
- TLI.setUnavailable(LibFunc_atomic_store);
- TLI.setUnavailable(LibFunc___kmpc_alloc_shared);
- TLI.setUnavailable(LibFunc___kmpc_free_shared);
- TLI.setUnavailable(LibFunc_dunder_strndup);
- TLI.setUnavailable(LibFunc_bcmp);
- TLI.setUnavailable(LibFunc_bcopy);
- TLI.setUnavailable(LibFunc_bzero);
- TLI.setUnavailable(LibFunc_cabs);
- TLI.setUnavailable(LibFunc_cabsf);
- TLI.setUnavailable(LibFunc_cabsl);
- TLI.setUnavailable(LibFunc_ffs);
- TLI.setUnavailable(LibFunc_flockfile);
- TLI.setUnavailable(LibFunc_fseeko);
- TLI.setUnavailable(LibFunc_ftello);
- TLI.setUnavailable(LibFunc_ftrylockfile);
- TLI.setUnavailable(LibFunc_funlockfile);
- TLI.setUnavailable(LibFunc_htonl);
- TLI.setUnavailable(LibFunc_htons);
- TLI.setUnavailable(LibFunc_isascii);
- TLI.setUnavailable(LibFunc_memccpy);
- TLI.setUnavailable(LibFunc_mempcpy);
- TLI.setUnavailable(LibFunc_memrchr);
- TLI.setUnavailable(LibFunc_ntohl);
- TLI.setUnavailable(LibFunc_ntohs);
- TLI.setUnavailable(LibFunc_reallocf);
- TLI.setUnavailable(LibFunc_roundeven);
- TLI.setUnavailable(LibFunc_roundevenf);
- TLI.setUnavailable(LibFunc_roundevenl);
- TLI.setUnavailable(LibFunc_stpcpy);
- TLI.setUnavailable(LibFunc_stpncpy);
- TLI.setUnavailable(LibFunc_strlcat);
- TLI.setUnavailable(LibFunc_strlcpy);
- TLI.setUnavailable(LibFunc_strndup);
- TLI.setUnavailable(LibFunc_strnlen);
- TLI.setUnavailable(LibFunc_toascii);
- }
- // As currently implemented in clang, NVPTX code has no standard library to
- // speak of. Headers provide a standard-ish library implementation, but many
- // of the signatures are wrong -- for example, many libm functions are not
- // extern "C".
- //
- // libdevice, an IR library provided by nvidia, is linked in by the front-end,
- // but only used functions are provided to llvm. Moreover, most of the
- // functions in libdevice don't map precisely to standard library functions.
- //
- // FIXME: Having no standard library prevents e.g. many fastmath
- // optimizations, so this situation should be fixed.
- if (T.isNVPTX()) {
- TLI.disableAllFunctions();
- TLI.setAvailable(LibFunc_nvvm_reflect);
- TLI.setAvailable(llvm::LibFunc_malloc);
- TLI.setAvailable(llvm::LibFunc_free);
- // TODO: We could enable the following two according to [0] but we haven't
- // done an evaluation wrt. the performance implications.
- // [0]
- // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations
- //
- // TLI.setAvailable(llvm::LibFunc_memcpy);
- // TLI.setAvailable(llvm::LibFunc_memset);
- TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
- TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
- } else {
- TLI.setUnavailable(LibFunc_nvvm_reflect);
- }
- // These vec_malloc/free routines are only available on AIX.
- if (!T.isOSAIX()) {
- TLI.setUnavailable(LibFunc_vec_calloc);
- TLI.setUnavailable(LibFunc_vec_malloc);
- TLI.setUnavailable(LibFunc_vec_realloc);
- TLI.setUnavailable(LibFunc_vec_free);
- }
- TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
- }
- TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
- // Default to everything being available.
- memset(AvailableArray, -1, sizeof(AvailableArray));
- initialize(*this, Triple(), StandardNames);
- }
- TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
- // Default to everything being available.
- memset(AvailableArray, -1, sizeof(AvailableArray));
- initialize(*this, T, StandardNames);
- }
- TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
- : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
- ShouldExtI32Return(TLI.ShouldExtI32Return),
- ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
- SizeOfInt(TLI.SizeOfInt) {
- memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
- VectorDescs = TLI.VectorDescs;
- ScalarDescs = TLI.ScalarDescs;
- }
- TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
- : CustomNames(std::move(TLI.CustomNames)),
- ShouldExtI32Param(TLI.ShouldExtI32Param),
- ShouldExtI32Return(TLI.ShouldExtI32Return),
- ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
- SizeOfInt(TLI.SizeOfInt) {
- std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
- AvailableArray);
- VectorDescs = TLI.VectorDescs;
- ScalarDescs = TLI.ScalarDescs;
- }
- TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
- CustomNames = TLI.CustomNames;
- ShouldExtI32Param = TLI.ShouldExtI32Param;
- ShouldExtI32Return = TLI.ShouldExtI32Return;
- ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
- SizeOfInt = TLI.SizeOfInt;
- memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
- return *this;
- }
- TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
- CustomNames = std::move(TLI.CustomNames);
- ShouldExtI32Param = TLI.ShouldExtI32Param;
- ShouldExtI32Return = TLI.ShouldExtI32Return;
- ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
- SizeOfInt = TLI.SizeOfInt;
- std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
- AvailableArray);
- return *this;
- }
- static StringRef sanitizeFunctionName(StringRef funcName) {
- // Filter out empty names and names containing null bytes, those can't be in
- // our table.
- if (funcName.empty() || funcName.contains('\0'))
- return StringRef();
- // Check for \01 prefix that is used to mangle __asm declarations and
- // strip it if present.
- return GlobalValue::dropLLVMManglingEscape(funcName);
- }
- bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
- funcName = sanitizeFunctionName(funcName);
- if (funcName.empty())
- return false;
- const auto *Start = std::begin(StandardNames);
- const auto *End = std::end(StandardNames);
- const auto *I = std::lower_bound(Start, End, funcName);
- if (I != End && *I == funcName) {
- F = (LibFunc)(I - Start);
- return true;
- }
- return false;
- }
- bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
- LibFunc F,
- const Module &M) const {
- // FIXME: There is really no guarantee that sizeof(size_t) is equal to
- // sizeof(int*) for every target. So the assumption used here to derive the
- // SizeTBits based on the size of an integer pointer in address space zero
- // isn't always valid.
- unsigned SizeTBits = M.getDataLayout().getPointerSizeInBits(/*AddrSpace=*/0);
- unsigned NumParams = FTy.getNumParams();
- switch (F) {
- case LibFunc_execl:
- case LibFunc_execlp:
- case LibFunc_execle:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32));
- case LibFunc_execv:
- case LibFunc_execvp:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32));
- case LibFunc_execvP:
- case LibFunc_execvpe:
- case LibFunc_execve:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32));
- case LibFunc_strlen_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strlen:
- return NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(SizeTBits);
- case LibFunc_strchr:
- case LibFunc_strrchr:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0) == FTy.getReturnType() &&
- FTy.getParamType(1)->isIntegerTy());
- case LibFunc_strtol:
- case LibFunc_strtod:
- case LibFunc_strtof:
- case LibFunc_strtoul:
- case LibFunc_strtoll:
- case LibFunc_strtold:
- case LibFunc_strtoull:
- return ((NumParams == 2 || NumParams == 3) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_strcat_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strcat:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0) == FTy.getReturnType() &&
- FTy.getParamType(1) == FTy.getReturnType());
- case LibFunc_strncat_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strncat:
- return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0) == FTy.getReturnType() &&
- FTy.getParamType(1) == FTy.getReturnType() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_strcpy_chk:
- case LibFunc_stpcpy_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strcpy:
- case LibFunc_stpcpy:
- return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(0) == FTy.getParamType(1) &&
- FTy.getParamType(0)->isPointerTy());
- case LibFunc_strlcat_chk:
- case LibFunc_strlcpy_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strlcat:
- case LibFunc_strlcpy:
- return NumParams == 3 && FTy.getReturnType()->isIntegerTy(SizeTBits) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits);
- case LibFunc_strncpy_chk:
- case LibFunc_stpncpy_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_strncpy:
- case LibFunc_stpncpy:
- return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(0) == FTy.getParamType(1) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_strxfrm:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_strcmp:
- return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(0) == FTy.getParamType(1));
- case LibFunc_strncmp:
- return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(0) == FTy.getParamType(1) &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_strspn:
- case LibFunc_strcspn:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(0) == FTy.getParamType(1) &&
- FTy.getReturnType()->isIntegerTy());
- case LibFunc_strcoll:
- case LibFunc_strcasecmp:
- case LibFunc_strncasecmp:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_strstr:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_strpbrk:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(0) == FTy.getParamType(1));
- case LibFunc_strtok:
- case LibFunc_strtok_r:
- return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_scanf:
- case LibFunc_setbuf:
- case LibFunc_setvbuf:
- return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_strdup:
- case LibFunc_strndup:
- return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy());
- case LibFunc_sscanf:
- case LibFunc_stat:
- case LibFunc_statvfs:
- case LibFunc_siprintf:
- case LibFunc_small_sprintf:
- case LibFunc_sprintf:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32));
- case LibFunc_sprintf_chk:
- return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(32) &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits) &&
- FTy.getParamType(3)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32);
- case LibFunc_snprintf:
- return NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
- FTy.getParamType(2)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32);
- case LibFunc_snprintf_chk:
- return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
- FTy.getParamType(2)->isIntegerTy(32) &&
- FTy.getParamType(3)->isIntegerTy(SizeTBits) &&
- FTy.getParamType(4)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy(32);
- case LibFunc_setitimer:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_system:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc___kmpc_alloc_shared:
- case LibFunc_malloc:
- case LibFunc_vec_malloc:
- return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
- case LibFunc_memcmp:
- return NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits);
- case LibFunc_memchr:
- case LibFunc_memrchr:
- return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
- FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(1)->isIntegerTy(32) &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_modf:
- case LibFunc_modff:
- case LibFunc_modfl:
- return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_memcpy_chk:
- case LibFunc_mempcpy_chk:
- case LibFunc_memmove_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_memcpy:
- case LibFunc_mempcpy:
- case LibFunc_memmove:
- return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_memset_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_memset:
- return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy() &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_memccpy_chk:
- --NumParams;
- if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
- return false;
- LLVM_FALLTHROUGH;
- case LibFunc_memccpy:
- return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_memalign:
- return (FTy.getReturnType()->isPointerTy());
- case LibFunc_realloc:
- case LibFunc_reallocf:
- case LibFunc_vec_realloc:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0) == FTy.getReturnType() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits));
- case LibFunc_read:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_rewind:
- case LibFunc_rmdir:
- case LibFunc_remove:
- case LibFunc_realpath:
- return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_rename:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_readlink:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_write:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_aligned_alloc:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
- case LibFunc_bcopy:
- case LibFunc_bcmp:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_bzero:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_calloc:
- case LibFunc_vec_calloc:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0) == FTy.getParamType(1));
- case LibFunc_atof:
- case LibFunc_atoi:
- case LibFunc_atol:
- case LibFunc_atoll:
- case LibFunc_ferror:
- case LibFunc_getenv:
- case LibFunc_getpwnam:
- case LibFunc_iprintf:
- case LibFunc_small_printf:
- case LibFunc_pclose:
- case LibFunc_perror:
- case LibFunc_printf:
- case LibFunc_puts:
- case LibFunc_uname:
- case LibFunc_under_IO_getc:
- case LibFunc_unlink:
- case LibFunc_unsetenv:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_access:
- case LibFunc_chmod:
- case LibFunc_chown:
- case LibFunc_clearerr:
- case LibFunc_closedir:
- case LibFunc_ctermid:
- case LibFunc_fclose:
- case LibFunc_feof:
- case LibFunc_fflush:
- case LibFunc_fgetc:
- case LibFunc_fgetc_unlocked:
- case LibFunc_fileno:
- case LibFunc_flockfile:
- case LibFunc_free:
- case LibFunc_fseek:
- case LibFunc_fseeko64:
- case LibFunc_fseeko:
- case LibFunc_fsetpos:
- case LibFunc_ftell:
- case LibFunc_ftello64:
- case LibFunc_ftello:
- case LibFunc_ftrylockfile:
- case LibFunc_funlockfile:
- case LibFunc_getc:
- case LibFunc_getc_unlocked:
- case LibFunc_getlogin_r:
- case LibFunc_mkdir:
- case LibFunc_mktime:
- case LibFunc_times:
- case LibFunc_vec_free:
- return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
- case LibFunc___kmpc_free_shared:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits));
- case LibFunc_fopen:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_fork:
- return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
- case LibFunc_fdopen:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_fputc:
- case LibFunc_fputc_unlocked:
- case LibFunc_fstat:
- case LibFunc_frexp:
- case LibFunc_frexpf:
- case LibFunc_frexpl:
- case LibFunc_fstatvfs:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_fgets:
- case LibFunc_fgets_unlocked:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_fread:
- case LibFunc_fread_unlocked:
- return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(3)->isPointerTy());
- case LibFunc_fwrite:
- case LibFunc_fwrite_unlocked:
- return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy() &&
- FTy.getParamType(2)->isIntegerTy() &&
- FTy.getParamType(3)->isPointerTy());
- case LibFunc_fputs:
- case LibFunc_fputs_unlocked:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_fscanf:
- case LibFunc_fiprintf:
- case LibFunc_small_fprintf:
- case LibFunc_fprintf:
- return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_fgetpos:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_getchar:
- case LibFunc_getchar_unlocked:
- return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
- case LibFunc_gets:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_getitimer:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_ungetc:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_utime:
- case LibFunc_utimes:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_putc:
- case LibFunc_putc_unlocked:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_pread:
- case LibFunc_pwrite:
- return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_popen:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_vscanf:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_vsscanf:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_vfscanf:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_valloc:
- return (FTy.getReturnType()->isPointerTy());
- case LibFunc_vprintf:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_vfprintf:
- case LibFunc_vsprintf:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_vsprintf_chk:
- return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(32) &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits) && FTy.getParamType(3)->isPointerTy();
- case LibFunc_vsnprintf:
- return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_vsnprintf_chk:
- return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy(32) &&
- FTy.getParamType(3)->isIntegerTy(SizeTBits) && FTy.getParamType(4)->isPointerTy();
- case LibFunc_open:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_opendir:
- return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy());
- case LibFunc_tmpfile:
- return (FTy.getReturnType()->isPointerTy());
- case LibFunc_htonl:
- case LibFunc_ntohl:
- return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_htons:
- case LibFunc_ntohs:
- return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_lstat:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_lchown:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_qsort:
- return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
- case LibFunc_dunder_strdup:
- case LibFunc_dunder_strndup:
- return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy());
- case LibFunc_dunder_strtok_r:
- return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_under_IO_putc:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_dunder_isoc99_scanf:
- return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_stat64:
- case LibFunc_lstat64:
- case LibFunc_statvfs64:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_dunder_isoc99_sscanf:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_fopen64:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- case LibFunc_tmpfile64:
- return (FTy.getReturnType()->isPointerTy());
- case LibFunc_fstat64:
- case LibFunc_fstatvfs64:
- return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
- case LibFunc_open64:
- return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_gettimeofday:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy());
- // new(unsigned int);
- case LibFunc_Znwj:
- // new(unsigned long);
- case LibFunc_Znwm:
- // new[](unsigned int);
- case LibFunc_Znaj:
- // new[](unsigned long);
- case LibFunc_Znam:
- // new(unsigned int);
- case LibFunc_msvc_new_int:
- // new(unsigned long long);
- case LibFunc_msvc_new_longlong:
- // new[](unsigned int);
- case LibFunc_msvc_new_array_int:
- // new[](unsigned long long);
- case LibFunc_msvc_new_array_longlong:
- return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
- // new(unsigned int, nothrow);
- case LibFunc_ZnwjRKSt9nothrow_t:
- // new(unsigned long, nothrow);
- case LibFunc_ZnwmRKSt9nothrow_t:
- // new[](unsigned int, nothrow);
- case LibFunc_ZnajRKSt9nothrow_t:
- // new[](unsigned long, nothrow);
- case LibFunc_ZnamRKSt9nothrow_t:
- // new(unsigned int, nothrow);
- case LibFunc_msvc_new_int_nothrow:
- // new(unsigned long long, nothrow);
- case LibFunc_msvc_new_longlong_nothrow:
- // new[](unsigned int, nothrow);
- case LibFunc_msvc_new_array_int_nothrow:
- // new[](unsigned long long, nothrow);
- case LibFunc_msvc_new_array_longlong_nothrow:
- // new(unsigned int, align_val_t)
- case LibFunc_ZnwjSt11align_val_t:
- // new(unsigned long, align_val_t)
- case LibFunc_ZnwmSt11align_val_t:
- // new[](unsigned int, align_val_t)
- case LibFunc_ZnajSt11align_val_t:
- // new[](unsigned long, align_val_t)
- case LibFunc_ZnamSt11align_val_t:
- return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
- // new(unsigned int, align_val_t, nothrow)
- case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
- // new(unsigned long, align_val_t, nothrow)
- case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
- // new[](unsigned int, align_val_t, nothrow)
- case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
- // new[](unsigned long, align_val_t, nothrow)
- case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
- return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
- // void operator delete[](void*);
- case LibFunc_ZdaPv:
- // void operator delete(void*);
- case LibFunc_ZdlPv:
- // void operator delete[](void*);
- case LibFunc_msvc_delete_array_ptr32:
- // void operator delete[](void*);
- case LibFunc_msvc_delete_array_ptr64:
- // void operator delete(void*);
- case LibFunc_msvc_delete_ptr32:
- // void operator delete(void*);
- case LibFunc_msvc_delete_ptr64:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
- // void operator delete[](void*, nothrow);
- case LibFunc_ZdaPvRKSt9nothrow_t:
- // void operator delete[](void*, unsigned int);
- case LibFunc_ZdaPvj:
- // void operator delete[](void*, unsigned long);
- case LibFunc_ZdaPvm:
- // void operator delete(void*, nothrow);
- case LibFunc_ZdlPvRKSt9nothrow_t:
- // void operator delete(void*, unsigned int);
- case LibFunc_ZdlPvj:
- // void operator delete(void*, unsigned long);
- case LibFunc_ZdlPvm:
- // void operator delete(void*, align_val_t)
- case LibFunc_ZdlPvSt11align_val_t:
- // void operator delete[](void*, align_val_t)
- case LibFunc_ZdaPvSt11align_val_t:
- // void operator delete[](void*, unsigned int);
- case LibFunc_msvc_delete_array_ptr32_int:
- // void operator delete[](void*, nothrow);
- case LibFunc_msvc_delete_array_ptr32_nothrow:
- // void operator delete[](void*, unsigned long long);
- case LibFunc_msvc_delete_array_ptr64_longlong:
- // void operator delete[](void*, nothrow);
- case LibFunc_msvc_delete_array_ptr64_nothrow:
- // void operator delete(void*, unsigned int);
- case LibFunc_msvc_delete_ptr32_int:
- // void operator delete(void*, nothrow);
- case LibFunc_msvc_delete_ptr32_nothrow:
- // void operator delete(void*, unsigned long long);
- case LibFunc_msvc_delete_ptr64_longlong:
- // void operator delete(void*, nothrow);
- case LibFunc_msvc_delete_ptr64_nothrow:
- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
- // void operator delete(void*, align_val_t, nothrow)
- case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
- // void operator delete[](void*, align_val_t, nothrow)
- case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
- // void operator delete(void*, unsigned int, align_val_t)
- case LibFunc_ZdlPvjSt11align_val_t:
- // void operator delete(void*, unsigned long, align_val_t)
- case LibFunc_ZdlPvmSt11align_val_t:
- // void operator delete[](void*, unsigned int, align_val_t);
- case LibFunc_ZdaPvjSt11align_val_t:
- // void operator delete[](void*, unsigned long, align_val_t);
- case LibFunc_ZdaPvmSt11align_val_t:
- return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
- // void __atomic_load(size_t, void *, void *, int)
- case LibFunc_atomic_load:
- // void __atomic_store(size_t, void *, void *, int)
- case LibFunc_atomic_store:
- return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy() &&
- FTy.getParamType(3)->isIntegerTy());
- case LibFunc_memset_pattern4:
- case LibFunc_memset_pattern8:
- case LibFunc_memset_pattern16:
- return (!FTy.isVarArg() && NumParams == 3 &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isIntegerTy());
- case LibFunc_cxa_guard_abort:
- case LibFunc_cxa_guard_acquire:
- case LibFunc_cxa_guard_release:
- case LibFunc_nvvm_reflect:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
- case LibFunc_sincospi_stret:
- case LibFunc_sincospif_stret:
- return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
- case LibFunc_acos:
- case LibFunc_acos_finite:
- case LibFunc_acosf:
- case LibFunc_acosf_finite:
- case LibFunc_acosh:
- case LibFunc_acosh_finite:
- case LibFunc_acoshf:
- case LibFunc_acoshf_finite:
- case LibFunc_acoshl:
- case LibFunc_acoshl_finite:
- case LibFunc_acosl:
- case LibFunc_acosl_finite:
- case LibFunc_asin:
- case LibFunc_asin_finite:
- case LibFunc_asinf:
- case LibFunc_asinf_finite:
- case LibFunc_asinh:
- case LibFunc_asinhf:
- case LibFunc_asinhl:
- case LibFunc_asinl:
- case LibFunc_asinl_finite:
- case LibFunc_atan:
- case LibFunc_atanf:
- case LibFunc_atanh:
- case LibFunc_atanh_finite:
- case LibFunc_atanhf:
- case LibFunc_atanhf_finite:
- case LibFunc_atanhl:
- case LibFunc_atanhl_finite:
- case LibFunc_atanl:
- case LibFunc_cbrt:
- case LibFunc_cbrtf:
- case LibFunc_cbrtl:
- case LibFunc_ceil:
- case LibFunc_ceilf:
- case LibFunc_ceill:
- case LibFunc_cos:
- case LibFunc_cosf:
- case LibFunc_cosh:
- case LibFunc_cosh_finite:
- case LibFunc_coshf:
- case LibFunc_coshf_finite:
- case LibFunc_coshl:
- case LibFunc_coshl_finite:
- case LibFunc_cosl:
- case LibFunc_exp10:
- case LibFunc_exp10_finite:
- case LibFunc_exp10f:
- case LibFunc_exp10f_finite:
- case LibFunc_exp10l:
- case LibFunc_exp10l_finite:
- case LibFunc_exp2:
- case LibFunc_exp2_finite:
- case LibFunc_exp2f:
- case LibFunc_exp2f_finite:
- case LibFunc_exp2l:
- case LibFunc_exp2l_finite:
- case LibFunc_exp:
- case LibFunc_exp_finite:
- case LibFunc_expf:
- case LibFunc_expf_finite:
- case LibFunc_expl:
- case LibFunc_expl_finite:
- case LibFunc_expm1:
- case LibFunc_expm1f:
- case LibFunc_expm1l:
- case LibFunc_fabs:
- case LibFunc_fabsf:
- case LibFunc_fabsl:
- case LibFunc_floor:
- case LibFunc_floorf:
- case LibFunc_floorl:
- case LibFunc_log10:
- case LibFunc_log10_finite:
- case LibFunc_log10f:
- case LibFunc_log10f_finite:
- case LibFunc_log10l:
- case LibFunc_log10l_finite:
- case LibFunc_log1p:
- case LibFunc_log1pf:
- case LibFunc_log1pl:
- case LibFunc_log2:
- case LibFunc_log2_finite:
- case LibFunc_log2f:
- case LibFunc_log2f_finite:
- case LibFunc_log2l:
- case LibFunc_log2l_finite:
- case LibFunc_log:
- case LibFunc_log_finite:
- case LibFunc_logb:
- case LibFunc_logbf:
- case LibFunc_logbl:
- case LibFunc_logf:
- case LibFunc_logf_finite:
- case LibFunc_logl:
- case LibFunc_logl_finite:
- case LibFunc_nearbyint:
- case LibFunc_nearbyintf:
- case LibFunc_nearbyintl:
- case LibFunc_rint:
- case LibFunc_rintf:
- case LibFunc_rintl:
- case LibFunc_round:
- case LibFunc_roundf:
- case LibFunc_roundl:
- case LibFunc_roundeven:
- case LibFunc_roundevenf:
- case LibFunc_roundevenl:
- case LibFunc_sin:
- case LibFunc_sinf:
- case LibFunc_sinh:
- case LibFunc_sinh_finite:
- case LibFunc_sinhf:
- case LibFunc_sinhf_finite:
- case LibFunc_sinhl:
- case LibFunc_sinhl_finite:
- case LibFunc_sinl:
- case LibFunc_sqrt:
- case LibFunc_sqrt_finite:
- case LibFunc_sqrtf:
- case LibFunc_sqrtf_finite:
- case LibFunc_sqrtl:
- case LibFunc_sqrtl_finite:
- case LibFunc_tan:
- case LibFunc_tanf:
- case LibFunc_tanh:
- case LibFunc_tanhf:
- case LibFunc_tanhl:
- case LibFunc_tanl:
- case LibFunc_trunc:
- case LibFunc_truncf:
- case LibFunc_truncl:
- return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_atan2:
- case LibFunc_atan2_finite:
- case LibFunc_atan2f:
- case LibFunc_atan2f_finite:
- case LibFunc_atan2l:
- case LibFunc_atan2l_finite:
- case LibFunc_fmin:
- case LibFunc_fminf:
- case LibFunc_fminl:
- case LibFunc_fmax:
- case LibFunc_fmaxf:
- case LibFunc_fmaxl:
- case LibFunc_fmod:
- case LibFunc_fmodf:
- case LibFunc_fmodl:
- case LibFunc_remainder:
- case LibFunc_remainderf:
- case LibFunc_remainderl:
- case LibFunc_copysign:
- case LibFunc_copysignf:
- case LibFunc_copysignl:
- case LibFunc_pow:
- case LibFunc_pow_finite:
- case LibFunc_powf:
- case LibFunc_powf_finite:
- case LibFunc_powl:
- case LibFunc_powl_finite:
- return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
- FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getReturnType() == FTy.getParamType(1));
- case LibFunc_ldexp:
- case LibFunc_ldexpf:
- case LibFunc_ldexpl:
- return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
- FTy.getReturnType() == FTy.getParamType(0) &&
- FTy.getParamType(1)->isIntegerTy(getIntSize()));
- case LibFunc_ffs:
- case LibFunc_ffsl:
- case LibFunc_ffsll:
- case LibFunc_fls:
- case LibFunc_flsl:
- case LibFunc_flsll:
- return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getParamType(0)->isIntegerTy());
- case LibFunc_isdigit:
- case LibFunc_isascii:
- case LibFunc_toascii:
- case LibFunc_putchar:
- case LibFunc_putchar_unlocked:
- return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_abs:
- case LibFunc_labs:
- case LibFunc_llabs:
- return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_cxa_atexit:
- return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isPointerTy() &&
- FTy.getParamType(2)->isPointerTy());
- case LibFunc_sinpi:
- case LibFunc_cospi:
- return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_sinpif:
- case LibFunc_cospif:
- return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
- FTy.getReturnType() == FTy.getParamType(0));
- case LibFunc_strnlen:
- return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits));
- case LibFunc_posix_memalign:
- return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
- FTy.getParamType(0)->isPointerTy() &&
- FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
- FTy.getParamType(2)->isIntegerTy(SizeTBits));
- case LibFunc_wcslen:
- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
- FTy.getReturnType()->isIntegerTy());
- case LibFunc_cabs:
- case LibFunc_cabsf:
- case LibFunc_cabsl: {
- Type* RetTy = FTy.getReturnType();
- if (!RetTy->isFloatingPointTy())
- return false;
- // NOTE: These prototypes are target specific and currently support
- // "complex" passed as an array or discrete real & imaginary parameters.
- // Add other calling conventions to enable libcall optimizations.
- if (NumParams == 1)
- return (FTy.getParamType(0)->isArrayTy() &&
- FTy.getParamType(0)->getArrayNumElements() == 2 &&
- FTy.getParamType(0)->getArrayElementType() == RetTy);
- else if (NumParams == 2)
- return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
- else
- return false;
- }
- case LibFunc::NumLibFuncs:
- case LibFunc::NotLibFunc:
- break;
- }
- llvm_unreachable("Invalid libfunc");
- }
- bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
- LibFunc &F) const {
- // Intrinsics don't overlap w/libcalls; if our module has a large number of
- // intrinsics, this ends up being an interesting compile time win since we
- // avoid string normalization and comparison.
- if (FDecl.isIntrinsic()) return false;
- const Module *M = FDecl.getParent();
- assert(M && "Expecting FDecl to be connected to a Module.");
- return getLibFunc(FDecl.getName(), F) &&
- isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M);
- }
- void TargetLibraryInfoImpl::disableAllFunctions() {
- memset(AvailableArray, 0, sizeof(AvailableArray));
- }
- static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
- return LHS.ScalarFnName < RHS.ScalarFnName;
- }
- static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
- return LHS.VectorFnName < RHS.VectorFnName;
- }
- static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
- return LHS.ScalarFnName < S;
- }
- void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
- llvm::append_range(VectorDescs, Fns);
- llvm::sort(VectorDescs, compareByScalarFnName);
- llvm::append_range(ScalarDescs, Fns);
- llvm::sort(ScalarDescs, compareByVectorFnName);
- }
- void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
- enum VectorLibrary VecLib) {
- switch (VecLib) {
- case Accelerate: {
- const VecDesc VecFuncs[] = {
- #define TLI_DEFINE_ACCELERATE_VECFUNCS
- #include "llvm/Analysis/VecFuncs.def"
- };
- addVectorizableFunctions(VecFuncs);
- break;
- }
- case DarwinLibSystemM: {
- const VecDesc VecFuncs[] = {
- #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
- #include "llvm/Analysis/VecFuncs.def"
- };
- addVectorizableFunctions(VecFuncs);
- break;
- }
- case LIBMVEC_X86: {
- const VecDesc VecFuncs[] = {
- #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
- #include "llvm/Analysis/VecFuncs.def"
- };
- addVectorizableFunctions(VecFuncs);
- break;
- }
- case MASSV: {
- const VecDesc VecFuncs[] = {
- #define TLI_DEFINE_MASSV_VECFUNCS
- #include "llvm/Analysis/VecFuncs.def"
- };
- addVectorizableFunctions(VecFuncs);
- break;
- }
- case SVML: {
- const VecDesc VecFuncs[] = {
- #define TLI_DEFINE_SVML_VECFUNCS
- #include "llvm/Analysis/VecFuncs.def"
- };
- addVectorizableFunctions(VecFuncs);
- break;
- }
- case NoLibrary:
- break;
- }
- }
- bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
- funcName = sanitizeFunctionName(funcName);
- if (funcName.empty())
- return false;
- std::vector<VecDesc>::const_iterator I =
- llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
- return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
- }
- StringRef
- TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
- const ElementCount &VF) const {
- F = sanitizeFunctionName(F);
- if (F.empty())
- return F;
- std::vector<VecDesc>::const_iterator I =
- llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
- while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
- if (I->VectorizationFactor == VF)
- return I->VectorFnName;
- ++I;
- }
- return StringRef();
- }
- TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
- FunctionAnalysisManager &) {
- if (!BaselineInfoImpl)
- BaselineInfoImpl =
- TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
- return TargetLibraryInfo(*BaselineInfoImpl, &F);
- }
- unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
- if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
- M.getModuleFlag("wchar_size")))
- return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
- return 0;
- }
- TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
- : ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
- initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
- }
- TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
- : ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
- initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
- }
- TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
- const TargetLibraryInfoImpl &TLIImpl)
- : ImmutablePass(ID), TLA(TLIImpl) {
- initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
- }
- AnalysisKey TargetLibraryAnalysis::Key;
- // Register the basic pass.
- INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
- "Target Library Information", false, true)
- char TargetLibraryInfoWrapperPass::ID = 0;
- void TargetLibraryInfoWrapperPass::anchor() {}
- void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF,
- ElementCount &FixedVF,
- ElementCount &ScalableVF) const {
- ScalarF = sanitizeFunctionName(ScalarF);
- // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the
- // same as a scalar.
- ScalableVF = ElementCount::getScalable(0);
- FixedVF = ElementCount::getFixed(1);
- if (ScalarF.empty())
- return;
- std::vector<VecDesc>::const_iterator I =
- llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
- while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) {
- ElementCount *VF =
- I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF;
- if (ElementCount::isKnownGT(I->VectorizationFactor, *VF))
- *VF = I->VectorizationFactor;
- ++I;
- }
- }
|