24 "No vector functions library"),
26 "Accelerate framework"),
28 "Darwin_libsystem_m",
"Darwin libsystem_m"),
30 "GLIBC Vector Math library"),
32 "IBM MASS vector library"),
34 "Intel SVML library"),
36 "SIMD Library for Evaluating Elementary Functions")));
38StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
40#define TLI_DEFINE_STRING
41#include "llvm/Analysis/TargetLibraryInfo.def"
72#include "llvm/Analysis/TargetLibraryInfo.def"
76 "Missing library function signatures");
87 if (
T.isMacOSX() &&
T.isMacOSXVersionLT(10, 9))
90 if (
T.isiOS() &&
T.isOSVersionLT(7, 0))
100 return TT.isGNUEnvironment() || TT.isMusl();
103 return TT.isOSFreeBSD() || TT.isOSSolaris();
122 if (!FuncTy->getReturnType()->isPointerTy() &&
123 !FuncTy->getReturnType()->isIntegerTy() &&
124 !FuncTy->getReturnType()->isVoidTy())
127 for (
auto *Param : FuncTy->params()) {
128 if (!Param->isPointerTy() && !Param->isIntegerTy())
144 return ::isCallingConvCCompatible(
F->getCallingConv(),
145 F->getParent()->getTargetTriple(),
146 F->getFunctionType());
158 "TargetLibraryInfoImpl function names must be sorted");
173 bool ShouldExtI32Param, ShouldExtI32Return;
174 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
176 ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
205 if (
T.isMacOSXVersionLT(10, 5)) {
210 }
else if (
T.isiOS()) {
211 if (
T.isOSVersionLT(3, 0)) {
216 }
else if (!
T.isWatchOS()) {
235 !
T.isMacOSXVersionLT(10, 7)) {
260 if (
T.isOSWindows() && !
T.isOSCygMing()) {
266 bool hasPartialC99 =
true;
267 if (
T.isKnownWindowsMSVCEnvironment()) {
269 hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19);
275 bool hasPartialFloat = (isARM ||
279 if (!hasPartialFloat) {
332 if (!hasPartialC99) {
416 if (
T.isOSWindows() && !
T.isWindowsCygwinEnvironment()) {
453 if (
T.isOSMSVCRT()) {
491 TLI.
setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
494 TLI.
setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
525 if (
T.isMacOSXVersionLT(10, 9)) {
537 if (!
T.isWatchOS() &&
538 (
T.isOSVersionLT(7, 0) || (
T.isOSVersionLT(9, 0) &&
T.isX86()))) {
598 if (!
T.isOSFreeBSD()) {
606 if (!
T.isOSLinux() || !
T.isGNUEnvironment()) {
614 if (!
T.isAndroid() && !
T.isMusl())
678 if ((
T.isOSLinux() &&
T.isGNUEnvironment()) ||
679 (
T.isAndroid() && !
T.isAndroidVersionLT(28))) {
693 if (
T.isAndroid() &&
T.isAndroidVersionLT(21)) {
870 memset(AvailableArray, -1,
sizeof(AvailableArray));
877 memset(AvailableArray, -1,
sizeof(AvailableArray));
883 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
884 ShouldExtI32Return(TLI.ShouldExtI32Return),
885 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
886 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
887 SizeOfInt(TLI.SizeOfInt) {
888 memcpy(AvailableArray, TLI.AvailableArray,
sizeof(AvailableArray));
889 VectorDescs = TLI.VectorDescs;
890 ScalarDescs = TLI.ScalarDescs;
894 : CustomNames(
std::
move(TLI.CustomNames)),
895 ShouldExtI32Param(TLI.ShouldExtI32Param),
896 ShouldExtI32Return(TLI.ShouldExtI32Return),
897 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
898 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
899 SizeOfInt(TLI.SizeOfInt) {
900 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
902 VectorDescs = TLI.VectorDescs;
903 ScalarDescs = TLI.ScalarDescs;
907 CustomNames = TLI.CustomNames;
908 ShouldExtI32Param = TLI.ShouldExtI32Param;
909 ShouldExtI32Return = TLI.ShouldExtI32Return;
910 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
911 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
912 SizeOfInt = TLI.SizeOfInt;
913 memcpy(AvailableArray, TLI.AvailableArray,
sizeof(AvailableArray));
918 CustomNames = std::move(TLI.CustomNames);
919 ShouldExtI32Param = TLI.ShouldExtI32Param;
920 ShouldExtI32Return = TLI.ShouldExtI32Return;
921 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
922 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
923 SizeOfInt = TLI.SizeOfInt;
924 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
942 if (funcName.
empty())
945 const auto *Start = std::begin(StandardNames);
946 const auto *
End = std::end(StandardNames);
947 const auto *
I = std::lower_bound(Start,
End, funcName);
948 if (
I !=
End && *
I == funcName) {
958 unsigned SizeTBits) {
1004bool TargetLibraryInfoImpl::isValidProtoForLibFunc(
const FunctionType &FTy,
1007 unsigned NumParams = FTy.getNumParams();
1013 case LibFunc_cabsl: {
1015 if (!
RetTy->isFloatingPointTy())
1018 Type *ParamTy = FTy.getParamType(0);
1025 else if (NumParams == 2)
1026 return ParamTy ==
RetTy && FTy.getParamType(1) ==
RetTy;
1032 case LibFunc_sincospi_stret:
1033 case LibFunc_sincospif_stret: {
1038 Type *ParamTy = FTy.getParamType(0);
1039 if (
auto *Ty = dyn_cast<StructType>(
RetTy)) {
1040 if (Ty->getNumElements() != 2)
1042 return (Ty->getElementType(0) == ParamTy &&
1043 Ty->getElementType(1) == ParamTy);
1046 if (
auto *Ty = dyn_cast<FixedVectorType>(
RetTy)) {
1047 if (Ty->getNumElements() != 2)
1049 return Ty->getElementType() == ParamTy;
1066 Type *Ty = FTy.getReturnType(), *LastTy = Ty;
1068 for (
auto TyID : ProtoTypes) {
1074 if (TyID ==
Ellip) {
1079 return FTy.isFunctionVarArg();
1083 assert(
Idx != 0 &&
"Type ID 'Same' must not be first!");
1087 if (!Ty || !
matchType(TyID, Ty, IntBits, SizeTBits))
1092 if (
Idx == NumParams) {
1100 Ty = FTy.getParamType(
Idx++);
1105 return Idx == NumParams + 1 && !FTy.isFunctionVarArg();
1116 assert(M &&
"Expecting FDecl to be connected to a Module.");
1123 memset(AvailableArray, 0,
sizeof(AvailableArray));
1127 return LHS.ScalarFnName <
RHS.ScalarFnName;
1131 return LHS.VectorFnName <
RHS.VectorFnName;
1135 return LHS.ScalarFnName < S;
1151 #define TLI_DEFINE_ACCELERATE_VECFUNCS
1152 #include "llvm/Analysis/VecFuncs.def"
1159 #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1160 #include "llvm/Analysis/VecFuncs.def"
1167 #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1168 #include "llvm/Analysis/VecFuncs.def"
1175 #define TLI_DEFINE_MASSV_VECFUNCS
1176 #include "llvm/Analysis/VecFuncs.def"
1183 #define TLI_DEFINE_SVML_VECFUNCS
1184 #include "llvm/Analysis/VecFuncs.def"
1190 const VecDesc VecFuncs_VF2[] = {
1191#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1192#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, false},
1193#include "llvm/Analysis/VecFuncs.def"
1195 const VecDesc VecFuncs_VF4[] = {
1196#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1197#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, false},
1198#include "llvm/Analysis/VecFuncs.def"
1200 const VecDesc VecFuncs_VFScalable[] = {
1201#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1202#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK) {SCAL, VEC, VF, MASK},
1203#include "llvm/Analysis/VecFuncs.def"
1206 switch (TargetTriple.
getArch()) {
1225 if (funcName.
empty())
1228 std::vector<VecDesc>::const_iterator
I =
1230 return I != VectorDescs.end() &&
StringRef(
I->ScalarFnName) == funcName;
1235 bool Masked)
const {
1239 std::vector<VecDesc>::const_iterator
I =
1241 while (
I != VectorDescs.end() &&
StringRef(
I->ScalarFnName) ==
F) {
1242 if ((
I->VectorizationFactor == VF) && (
I->Masked == Masked))
1243 return I->VectorFnName;
1251 if (!BaselineInfoImpl)
1258 if (
auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1259 M.getModuleFlag(
"wchar_size")))
1260 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1277 return M.getDataLayout().getPointerSizeInBits(
AddressSpace);
1300 "Target Library Information",
false,
true)
1313 if (ScalarF.
empty())
1316 std::vector<VecDesc>::const_iterator
I =
1318 while (
I != VectorDescs.end() &&
StringRef(
I->ScalarFnName) == ScalarF) {
1320 I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF;
1322 *VF =
I->VectorizationFactor;
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool hasSinCosPiStret(const Triple &T)
static StringRef sanitizeFunctionName(StringRef funcName)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
static bool matchType(FuncArgTypeID ArgTy, const Type *Ty, unsigned IntBits, unsigned SizeTBits)
static bool hasBcmp(const Triple &TT)
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"), clEnumValN(TargetLibraryInfoImpl::SLEEFGNUABI, "sleefgnuabi", "SIMD Library for Evaluating Elementary Functions")))
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS)
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS)
static const FuncProtoTy Signatures[]
static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT, FunctionType *FuncTy)
std::array< FuncArgTypeID, 8 > FuncProtoTy
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S)
A container for analyses that lazily runs them and caches their results.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallingConv::ID getCallingConv() const
FunctionType * getFunctionType() const
static constexpr ElementCount getScalable(ScalarTy MinVal)
static constexpr ElementCount getFixed(ScalarTy MinVal)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Module * getParent()
Get the module that this global value is contained inside of...
ImmutablePass class - This class is used to provide information that does not need to be run.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
A Module instance is used to store all the information related to an LLVM module.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
Implementation of the target library information.
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &Scalable) const
Returns the largest vectorization factor used in the list of vector functions.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used.
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib, const llvm::Triple &TargetTriple)
Calls addVectorizableFunctions with a known preset of functions for the given vector library.
void setIntSize(unsigned Bits)
Initialize the C-level size of an integer.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
static bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
void setShouldSignExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext attribute if they correspond t...
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
void disableAllFunctions()
Disables all builtins.
VectorLibrary
List of known vector-functions libraries.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const
Return the name of the equivalent of F, vectorized with factor VF.
void setAvailable(LibFunc F)
Forces a function to be marked as available.
TargetLibraryInfoWrapperPass()
Provides information about what library functions are available for the current target.
static void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isPointerTy() const
True if this is an instance of PointerType.
Type * getArrayElementType() const
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
uint64_t getArrayNumElements() const
bool isStructTy() const
True if this is an instance of StructType.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isVoidTy() const
Return true if this is 'void'.
StringRef getName() const
Return a constant reference to the value's name.
Represents a version number in the form major[.minor[.subminor[.build]]].
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ C
The default llvm calling convention, compatible with C.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
void sort(IteratorTy Start, IteratorTy End)
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
A special type used by analysis passes to provide an address that identifies that particular analysis...
Describes a possible vectorization of a function.