34#define DEBUG_TYPE "replace-with-veclib"
37 "Number of calls to intrinsics that have been replaced.");
40 "Number of vector library function declarations added.");
43 "Number of functions added to `llvm.compiler.used`");
51 Function *TLIFunc = M->getFunction(TLIName);
59 << TLIName <<
"` of type `" << *(TLIFunc->
getType())
62 ++NumTLIFuncDeclAdded;
67 <<
"` to `@llvm.compiler.used`.\n");
78 auto *CI = dyn_cast<CallInst>(&
I);
80 if (
auto OptMaskpos =
Info.getParamIndexForOptionalMask()) {
83 Args.insert(Args.begin() + OptMaskpos.value(),
90 CI->getOperandBundlesAsDefs(OpBundles);
93 I.replaceAllUsesWith(Replacement);
95 if (isa<FPMathOperator>(Replacement))
96 Replacement->copyFastMathFlags(&
I);
106 auto *VTy = dyn_cast<VectorType>(
I.getType());
113 std::string ScalarName;
115 auto *CI = dyn_cast<CallInst>(&
I);
117 FuncToReplace = CI->getCalledFunction();
121 auto *ArgTy = Arg.value()->getType();
124 }
else if (
auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
125 ScalarArgTypes.
push_back(VectorArgTy->getElementType());
129 EC = VectorArgTy->getElementCount();
130 else if (EC != VectorArgTy->getElementCount())
142 assert(VTy &&
"Return type must be a vector");
143 auto *ScalarTy = VTy->getScalarType();
145 if (!TLI.
getLibFunc(
I.getOpcode(), ScalarTy, Func))
147 ScalarName = TLI.
getName(Func);
148 ScalarArgTypes = {ScalarTy, ScalarTy};
160 <<
"` and vector width " << EC <<
" to: `"
165 Type *ScalarRetTy =
I.getType()->getScalarType();
167 FunctionType::get(ScalarRetTy, ScalarArgTypes,
false);
178 for (
auto &VFParam : OptInfo->Shape.Parameters) {
179 if (VFParam.ParamKind == VFParamKind::GlobalPredicate)
184 assert(VFParam.ParamPos < CI->arg_size() &&
185 "ParamPos has invalid range.");
186 Type *OrigTy = CI->getArgOperand(VFParam.ParamPos)->getType();
187 if (OrigTy->
isVectorTy() != (VFParam.ParamKind == VFParamKind::Vector)) {
189 <<
". Wrong type at index " << VFParam.ParamPos
190 <<
": " << *OrigTy <<
"\n");
205 <<
"` with call to `" << TLIFunc->
getName() <<
"`.\n");
213 Type *Ty =
I->getType();
214 if (
auto *CI = dyn_cast<CallInst>(
I))
216 CI->getCalledFunction()->getIntrinsicID() !=
218 if (
I->getOpcode() == Instruction::FRem && Ty->
isVectorTy())
224 bool Changed =
false;
236 for (
auto *CI : ReplacedCalls)
237 CI->eraseFromParent();
249 LLVM_DEBUG(
dbgs() <<
"Instructions replaced with vector libraries: "
250 << NumCallsReplaced <<
"\n");
271 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
291 "Replace intrinsics with calls to vector library",
false,
Expand Atomic instructions
Analysis containing CSE Info
static bool runImpl(Function &F, const TargetLowering &TLI)
expand Expand reduction intrinsics
This is the interface for a simple mod/ref and alias analysis over globals.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Function * getTLIFunction(Module *M, FunctionType *VectorFTy, const StringRef TLIName, Function *ScalarFunc=nullptr)
Returns a vector Function that it adds to the Module M.
static void replaceWithTLIFunction(Instruction &I, VFInfo &Info, Function *TLIVecFunc)
Replace the instruction I with a call to the corresponding function from the vector library (TLIVecFu...
static bool isSupportedInstruction(Instruction *I)
Supported instruction I must be a vectorized frem or a call to an intrinsic that returns either void ...
Replace intrinsics with calls to vector library
static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI, Instruction &I)
Returns true when successfully replaced I with a suitable function taking vector arguments,...
static bool runImpl(const TargetLibraryInfo &TLI, Function &F)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
static Constant * getAllOnesValue(Type *Ty)
An analysis that produces DemandedBits for a function.
static constexpr ElementCount getFixed(ScalarTy MinVal)
FunctionPass class - This class is used to implement most global optimizations.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
PointerType * getType() const
Global values are always pointers.
Legacy wrapper pass to provide the GlobalsAAResult object.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This analysis provides dependence information for the memory accesses of a loop.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
void preserve()
Mark an analysis as preserved.
Analysis pass that exposes the ScalarEvolution for a function.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
StringRef getName(LibFunc F) const
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
static IntegerType * getInt1Ty(LLVMContext &C)
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
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
FunctionType * createFunctionType(const VFInfo &Info, const FunctionType *ScalarFTy)
Constructs a FunctionType by applying vector function information to the type of a matching scalar fu...
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
FunctionPass * createReplaceWithVeclibLegacyPass()
bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx)
Identifies if the vector form of the intrinsic has a scalar operand.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Holds the VFShape for a specific scalar to vector function mapping.