diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-18 20:30:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2024-04-06 20:11:55 +0000 |
commit | 5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch) | |
tree | 1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp | |
parent | 3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff) | |
parent | 312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp | 89 |
1 files changed, 65 insertions, 24 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp b/contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp index 05fa67d0bbf1..20959cf6948f 100644 --- a/contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/contrib/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallString.h" #include "llvm/IR/Constants.h" #include "llvm/InitializePasses.h" #include "llvm/Support/CommandLine.h" @@ -43,6 +45,14 @@ StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = #include "llvm/Analysis/TargetLibraryInfo.def" }; +std::string VecDesc::getVectorFunctionABIVariantString() const { + assert(!VectorFnName.empty() && "Vector function name must not be empty."); + SmallString<256> Buffer; + llvm::raw_svector_ostream Out(Buffer); + Out << VABIPrefix << "_" << ScalarFnName << "(" << VectorFnName << ")"; + return std::string(Out.str()); +} + // Recognized types of library function arguments and return types. enum FuncArgTypeID : char { Void = 0, // Must be zero. @@ -203,6 +213,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, TLI.setAvailable(LibFunc_getchar_unlocked); TLI.setAvailable(LibFunc_putc_unlocked); TLI.setAvailable(LibFunc_putchar_unlocked); + TLI.setUnavailable(LibFunc_memrchr); if (T.isMacOSXVersionLT(10, 5)) { TLI.setUnavailable(LibFunc_memset_pattern4); @@ -939,16 +950,26 @@ static StringRef sanitizeFunctionName(StringRef funcName) { return GlobalValue::dropLLVMManglingEscape(funcName); } +static DenseMap<StringRef, LibFunc> +buildIndexMap(ArrayRef<StringLiteral> StandardNames) { + DenseMap<StringRef, LibFunc> Indices; + unsigned Idx = 0; + Indices.reserve(LibFunc::NumLibFuncs); + for (const auto &Func : StandardNames) + Indices[Func] = static_cast<LibFunc>(Idx++); + return Indices; +} + 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); + static const DenseMap<StringRef, LibFunc> Indices = + buildIndexMap(StandardNames); + + if (auto Loc = Indices.find(funcName); Loc != Indices.end()) { + F = Loc->second; return true; } return false; @@ -1117,8 +1138,15 @@ bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 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); + if (FDecl.LibFuncCache == Function::UnknownLibFunc) + if (!getLibFunc(FDecl.getName(), FDecl.LibFuncCache)) + FDecl.LibFuncCache = NotLibFunc; + + if (FDecl.LibFuncCache == NotLibFunc) + return false; + + F = FDecl.LibFuncCache; + return isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M); } void TargetLibraryInfoImpl::disableAllFunctions() { @@ -1126,15 +1154,15 @@ void TargetLibraryInfoImpl::disableAllFunctions() { } static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { - return LHS.ScalarFnName < RHS.ScalarFnName; + return LHS.getScalarFnName() < RHS.getScalarFnName(); } static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { - return LHS.VectorFnName < RHS.VectorFnName; + return LHS.getVectorFnName() < RHS.getVectorFnName(); } static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { - return LHS.ScalarFnName < S; + return LHS.getScalarFnName() < S; } void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { @@ -1191,17 +1219,20 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( case SLEEFGNUABI: { const VecDesc VecFuncs_VF2[] = { #define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS -#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, /* MASK = */ false}, +#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \ + {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX}, #include "llvm/Analysis/VecFuncs.def" }; const VecDesc VecFuncs_VF4[] = { #define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS -#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, /* MASK = */ false}, +#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \ + {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX}, #include "llvm/Analysis/VecFuncs.def" }; const VecDesc VecFuncs_VFScalable[] = { #define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS -#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK) {SCAL, VEC, VF, MASK}, +#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \ + {SCAL, VEC, VF, MASK, VABI_PREFIX}, #include "llvm/Analysis/VecFuncs.def" }; @@ -1220,7 +1251,8 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( case ArmPL: { const VecDesc VecFuncs[] = { #define TLI_DEFINE_ARMPL_VECFUNCS -#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK) {SCAL, VEC, VF, MASK}, +#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \ + {SCAL, VEC, VF, MASK, VABI_PREFIX}, #include "llvm/Analysis/VecFuncs.def" }; @@ -1246,23 +1278,32 @@ bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { std::vector<VecDesc>::const_iterator I = llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName); - return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; + return I != VectorDescs.end() && StringRef(I->getScalarFnName()) == funcName; } StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const { + const VecDesc *VD = getVectorMappingInfo(F, VF, Masked); + if (VD) + return VD->getVectorFnName(); + return StringRef(); +} + +const VecDesc * +TargetLibraryInfoImpl::getVectorMappingInfo(StringRef F, const ElementCount &VF, + bool Masked) const { F = sanitizeFunctionName(F); if (F.empty()) - return F; + return nullptr; std::vector<VecDesc>::const_iterator I = llvm::lower_bound(VectorDescs, F, compareWithScalarFnName); - while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { - if ((I->VectorizationFactor == VF) && (I->Masked == Masked)) - return I->VectorFnName; + while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == F) { + if ((I->getVectorizationFactor() == VF) && (I->isMasked() == Masked)) + return &(*I); ++I; } - return StringRef(); + return nullptr; } TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F, @@ -1334,11 +1375,11 @@ void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF, std::vector<VecDesc>::const_iterator I = llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName); - while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) { + while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == ScalarF) { ElementCount *VF = - I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF; - if (ElementCount::isKnownGT(I->VectorizationFactor, *VF)) - *VF = I->VectorizationFactor; + I->getVectorizationFactor().isScalable() ? &ScalableVF : &FixedVF; + if (ElementCount::isKnownGT(I->getVectorizationFactor(), *VF)) + *VF = I->getVectorizationFactor(); ++I; } } |