diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/InjectTLIMappings.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/InjectTLIMappings.cpp | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp b/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp index 9192e74b9ace9..9d8f59d62d6d0 100644 --- a/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp +++ b/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp @@ -13,8 +13,12 @@ #include "llvm/Transforms/Utils/InjectTLIMappings.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/DemandedBits.h" +#include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/VectorUtils.h" #include "llvm/IR/InstIterator.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -30,40 +34,6 @@ STATISTIC(NumVFDeclAdded, STATISTIC(NumCompUsedAdded, "Number of `@llvm.compiler.used` operands that have been added."); -/// Helper function to map the TLI name to a strings that holds -/// scalar-to-vector mapping. -/// -/// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>) -/// -/// where: -/// -/// <isa> = "_LLVM_" -/// <mask> = "N". Note: TLI does not support masked interfaces. -/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor` -/// field of the `VecDesc` struct. -/// <vparams> = "v", as many as are the number of parameters of CI. -/// <scalarname> = the name of the scalar function called by CI. -/// <vectorname> = the name of the vector function mapped by the TLI. -static std::string mangleTLIName(StringRef VectorName, const CallInst &CI, - unsigned VF) { - SmallString<256> Buffer; - llvm::raw_svector_ostream Out(Buffer); - Out << "_ZGV" << VFABI::_LLVM_ << "N" << VF; - for (unsigned I = 0; I < CI.getNumArgOperands(); ++I) - Out << "v"; - Out << "_" << CI.getCalledFunction()->getName() << "(" << VectorName << ")"; - return Out.str(); -} - -/// A helper function for converting Scalar types to vector types. -/// If the incoming type is void, we return void. If the VF is 1, we return -/// the scalar type. -static Type *ToVectorTy(Type *Scalar, unsigned VF, bool isScalable = false) { - if (Scalar->isVoidTy() || VF == 1) - return Scalar; - return VectorType::get(Scalar, {VF, isScalable}); -} - /// A helper function that adds the vector function declaration that /// vectorizes the CallInst CI with a vectorization factor of VF /// lanes. The TLI assumes that all parameters and the return type of @@ -107,7 +77,7 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) { if (CI.isNoBuiltin() || !CI.getCalledFunction()) return; - const std::string ScalarName = CI.getCalledFunction()->getName(); + const std::string ScalarName = std::string(CI.getCalledFunction()->getName()); // Nothing to be done if the TLI thinks the function is not // vectorizable. if (!TLI.isFunctionVectorizable(ScalarName)) @@ -120,9 +90,11 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) { // All VFs in the TLI are powers of 2. for (unsigned VF = 2, WidestVF = TLI.getWidestVF(ScalarName); VF <= WidestVF; VF *= 2) { - const std::string TLIName = TLI.getVectorizedFunction(ScalarName, VF); + const std::string TLIName = + std::string(TLI.getVectorizedFunction(ScalarName, VF)); if (!TLIName.empty()) { - std::string MangledName = mangleTLIName(TLIName, CI, VF); + std::string MangledName = VFABI::mangleTLIVectorName( + TLIName, ScalarName, CI.getNumArgOperands(), VF); if (!OriginalSetOfMappings.count(MangledName)) { Mappings.push_back(MangledName); ++NumCallInjected; @@ -168,6 +140,12 @@ void InjectTLIMappingsLegacy::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addRequired<TargetLibraryInfoWrapperPass>(); AU.addPreserved<TargetLibraryInfoWrapperPass>(); + AU.addPreserved<ScalarEvolutionWrapperPass>(); + AU.addPreserved<AAResultsWrapperPass>(); + AU.addPreserved<LoopAccessLegacyAnalysis>(); + AU.addPreserved<DemandedBitsWrapperPass>(); + AU.addPreserved<OptimizationRemarkEmitterWrapperPass>(); + AU.addPreserved<GlobalsAAWrapperPass>(); } //////////////////////////////////////////////////////////////////////////////// |