26 "No vector functions library"),
28 "Accelerate framework"),
30 "Darwin_libsystem_m",
"Darwin libsystem_m"),
32 "GLIBC Vector Math library"),
34 "IBM MASS vector library"),
36 "Intel SVML library"),
38 "SIMD Library for Evaluating Elementary Functions"),
40 "Arm Performance Libraries"),
42 "AMD vector math library")));
44StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
46#define TLI_DEFINE_STRING
47#include "llvm/Analysis/TargetLibraryInfo.def"
51 assert(!VectorFnName.
empty() &&
"Vector function name must not be empty.");
54 Out << VABIPrefix <<
"_" << ScalarFnName <<
"(" << VectorFnName <<
")";
55 return std::string(Out.
str());
86#include "llvm/Analysis/TargetLibraryInfo.def"
90 "Missing library function signatures");
101 if (
T.isMacOSX() &&
T.isMacOSXVersionLT(10, 9))
104 if (
T.isiOS() &&
T.isOSVersionLT(7, 0))
114 return TT.isGNUEnvironment() || TT.isMusl();
117 return TT.isOSFreeBSD() || TT.isOSSolaris();
136 if (!FuncTy->getReturnType()->isPointerTy() &&
137 !FuncTy->getReturnType()->isIntegerTy() &&
138 !FuncTy->getReturnType()->isVoidTy())
141 for (
auto *Param : FuncTy->params()) {
142 if (!Param->isPointerTy() && !Param->isIntegerTy())
158 return ::isCallingConvCCompatible(
F->getCallingConv(),
159 F->getParent()->getTargetTriple(),
160 F->getFunctionType());
181 bool ShouldExtI32Param, ShouldExtI32Return;
182 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
184 ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
214 if (
T.isMacOSXVersionLT(10, 5)) {
219 }
else if (
T.isiOS()) {
220 if (
T.isOSVersionLT(3, 0)) {
225 }
else if (!
T.isWatchOS()) {
244 !
T.isMacOSXVersionLT(10, 7)) {
269 if (
T.isOSWindows() && !
T.isOSCygMing()) {
275 bool hasPartialC99 =
true;
276 if (
T.isKnownWindowsMSVCEnvironment()) {
278 hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19);
284 bool hasPartialFloat = (isARM ||
288 if (!hasPartialFloat) {
341 if (!hasPartialC99) {
425 if (
T.isOSWindows() && !
T.isWindowsCygwinEnvironment()) {
467 if (
T.isOSMSVCRT()) {
505 TLI.
setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
508 TLI.
setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
539 if (
T.isMacOSXVersionLT(10, 9)) {
552 if (!
T.isWatchOS() &&
553 (
T.isOSVersionLT(7, 0) || (
T.isOSVersionLT(9, 0) &&
T.isX86()))) {
615 if (!
T.isOSFreeBSD()) {
623 if (!
T.isOSLinux() || !
T.isGNUEnvironment()) {
631 if (!
T.isAndroid() && !
T.isMusl())
695 if ((
T.isOSLinux() &&
T.isGNUEnvironment()) ||
696 (
T.isAndroid() && !
T.isAndroidVersionLT(28))) {
710 if (
T.isAndroid() &&
T.isAndroidVersionLT(21)) {
890 memset(AvailableArray, -1,
sizeof(AvailableArray));
897 memset(AvailableArray, -1,
sizeof(AvailableArray));
903 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
904 ShouldExtI32Return(TLI.ShouldExtI32Return),
905 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
906 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
907 SizeOfInt(TLI.SizeOfInt) {
908 memcpy(AvailableArray, TLI.AvailableArray,
sizeof(AvailableArray));
909 VectorDescs = TLI.VectorDescs;
910 ScalarDescs = TLI.ScalarDescs;
914 : CustomNames(
std::
move(TLI.CustomNames)),
915 ShouldExtI32Param(TLI.ShouldExtI32Param),
916 ShouldExtI32Return(TLI.ShouldExtI32Return),
917 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
918 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
919 SizeOfInt(TLI.SizeOfInt) {
920 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
922 VectorDescs = TLI.VectorDescs;
923 ScalarDescs = TLI.ScalarDescs;
927 CustomNames = TLI.CustomNames;
928 ShouldExtI32Param = TLI.ShouldExtI32Param;
929 ShouldExtI32Return = TLI.ShouldExtI32Return;
930 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
931 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
932 SizeOfInt = TLI.SizeOfInt;
933 memcpy(AvailableArray, TLI.AvailableArray,
sizeof(AvailableArray));
938 CustomNames = std::move(TLI.CustomNames);
939 ShouldExtI32Param = TLI.ShouldExtI32Param;
940 ShouldExtI32Return = TLI.ShouldExtI32Return;
941 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
942 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
943 SizeOfInt = TLI.SizeOfInt;
944 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
965 for (
const auto &Func : StandardNames)
972 if (funcName.
empty())
978 if (
auto Loc = Indices.
find(funcName); Loc != Indices.
end()) {
988 unsigned SizeTBits) {
1034bool TargetLibraryInfoImpl::isValidProtoForLibFunc(
const FunctionType &FTy,
1037 unsigned NumParams = FTy.getNumParams();
1043 case LibFunc_cabsl: {
1045 if (!
RetTy->isFloatingPointTy())
1048 Type *ParamTy = FTy.getParamType(0);
1055 else if (NumParams == 2)
1056 return ParamTy ==
RetTy && FTy.getParamType(1) ==
RetTy;
1062 case LibFunc_sincospi_stret:
1063 case LibFunc_sincospif_stret: {
1068 Type *ParamTy = FTy.getParamType(0);
1069 if (
auto *Ty = dyn_cast<StructType>(
RetTy)) {
1070 if (Ty->getNumElements() != 2)
1072 return (Ty->getElementType(0) == ParamTy &&
1073 Ty->getElementType(1) == ParamTy);
1076 if (
auto *Ty = dyn_cast<FixedVectorType>(
RetTy)) {
1077 if (Ty->getNumElements() != 2)
1079 return Ty->getElementType() == ParamTy;
1096 Type *Ty = FTy.getReturnType(), *LastTy = Ty;
1098 for (
auto TyID : ProtoTypes) {
1104 if (TyID ==
Ellip) {
1109 return FTy.isFunctionVarArg();
1113 assert(
Idx != 0 &&
"Type ID 'Same' must not be first!");
1117 if (!Ty || !
matchType(TyID, Ty, IntBits, SizeTBits))
1122 if (
Idx == NumParams) {
1130 Ty = FTy.getParamType(
Idx++);
1135 return Idx == NumParams + 1 && !FTy.isFunctionVarArg();
1146 assert(M &&
"Expecting FDecl to be connected to a Module.");
1148 if (FDecl.LibFuncCache == Function::UnknownLibFunc)
1155 F = FDecl.LibFuncCache;
1165 F = Ty->
isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
1170 memset(AvailableArray, 0,
sizeof(AvailableArray));
1174 return LHS.getScalarFnName() <
RHS.getScalarFnName();
1178 return LHS.getVectorFnName() <
RHS.getVectorFnName();
1182 return LHS.getScalarFnName() < S;
1198 #define TLI_DEFINE_ACCELERATE_VECFUNCS
1199 #include "llvm/Analysis/VecFuncs.def"
1206 #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1207 #include "llvm/Analysis/VecFuncs.def"
1214 #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1215 #include "llvm/Analysis/VecFuncs.def"
1222 #define TLI_DEFINE_MASSV_VECFUNCS
1223 #include "llvm/Analysis/VecFuncs.def"
1230 #define TLI_DEFINE_SVML_VECFUNCS
1231 #include "llvm/Analysis/VecFuncs.def"
1237 const VecDesc VecFuncs_VF2[] = {
1238#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1239#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1240 {SCAL, VEC, VF, false, VABI_PREFIX},
1241#include "llvm/Analysis/VecFuncs.def"
1243 const VecDesc VecFuncs_VF4[] = {
1244#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1245#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1246 {SCAL, VEC, VF, false, VABI_PREFIX},
1247#include "llvm/Analysis/VecFuncs.def"
1249 const VecDesc VecFuncs_VFScalable[] = {
1250#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1251#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1252 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1253#include "llvm/Analysis/VecFuncs.def"
1256 switch (TargetTriple.
getArch()) {
1270#define TLI_DEFINE_ARMPL_VECFUNCS
1271#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1272 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1273#include "llvm/Analysis/VecFuncs.def"
1276 switch (TargetTriple.
getArch()) {
1288#define TLI_DEFINE_AMDLIBM_VECFUNCS
1289#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1290 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1291#include "llvm/Analysis/VecFuncs.def"
1303 if (funcName.
empty())
1306 std::vector<VecDesc>::const_iterator
I =
1308 return I != VectorDescs.end() &&
StringRef(
I->getScalarFnName()) == funcName;
1313 bool Masked)
const {
1322 bool Masked)
const {
1326 std::vector<VecDesc>::const_iterator
I =
1328 while (
I != VectorDescs.end() &&
StringRef(
I->getScalarFnName()) ==
F) {
1329 if ((
I->getVectorizationFactor() == VF) && (
I->isMasked() == Masked))
1338 if (!BaselineInfoImpl)
1345 if (
auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1346 M.getModuleFlag(
"wchar_size")))
1347 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1364 return M.getDataLayout().getPointerSizeInBits(
AddressSpace);
1387 "Target Library Information",
false,
true)
1400 if (ScalarF.
empty())
1403 std::vector<VecDesc>::const_iterator
I =
1405 while (
I != VectorDescs.end() &&
StringRef(
I->getScalarFnName()) == ScalarF) {
1407 I->getVectorizationFactor().isScalable() ? &ScalableVF : &FixedVF;
1409 *VF =
I->getVectorizationFactor();
#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
This file defines the DenseMap class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
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 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)
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"), clEnumValN(TargetLibraryInfoImpl::ArmPL, "ArmPL", "Arm Performance Libraries"), clEnumValN(TargetLibraryInfoImpl::AMDLIBM, "AMDLIBM", "AMD vector math library")))
std::array< FuncArgTypeID, 8 > FuncProtoTy
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S)
static DenseMap< StringRef, LibFunc > buildIndexMap(ArrayRef< StringLiteral > StandardNames)
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
iterator find(const_arg_type_t< KeyT > Val)
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
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...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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...
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
Return a pointer to a VecDesc object holding all info for scalar to vector mappings in TLI for the eq...
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.
Provides info so a possible vectorization of a function can be computed.
std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getVectorFnName() const
Represents a version number in the form major[.minor[.subminor[.build]]].
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
#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 range R to container C.
void sort(IteratorTy Start, IteratorTy End)
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 &)
Implement std::hash so that hash_code can be used in STL containers.
A special type used by analysis passes to provide an address that identifies that particular analysis...