30#define DEBUG_TYPE "replace-with-veclib"
33 "Number of calls to intrinsics that have been replaced.");
36 "Number of vector library function declarations added.");
39 "Number of functions added to `llvm.compiler.used`");
48 Function *TLIFunc = M->getFunction(TLIName);
51 Function::ExternalLinkage, TLIName, *M);
55 << TLIName <<
"` of type `" << *(TLIFunc->
getType())
58 ++NumTLIFuncDeclAdded;
65 <<
"` to `@llvm.compiler.used`.\n");
78 "Expecting function types to be identical");
80 if (isa<FPMathOperator>(Replacement)) {
86 << OldFunc->
getName() <<
"` with call to `" << TLIName
109 auto *ArgType =
Arg.value()->getType();
117 auto *VectorArgTy = dyn_cast<VectorType>(ArgType);
123 ElementCount NumElements = VectorArgTy->getElementCount();
129 if (VF.
isNonZero() && VF != NumElements) {
135 ScalarTypes.
push_back(VectorArgTy->getElementType());
142 std::string ScalarName;
158 const std::string TLIName =
162 << ScalarName <<
"` and vector width " << VF <<
".\n");
164 if (!TLIName.empty()) {
177 bool Changed =
false;
180 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
189 for (
auto *CI : ReplacedCalls) {
190 CI->eraseFromParent();
222 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
243 "Replace intrinsics with calls to vector library",
false,
amdgpu Simplify well known AMD library calls
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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.
print must be executed print the must be executed context for all instructions
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI, CallInst &CI)
Replace intrinsics with calls to vector library
static bool runImpl(const TargetLibraryInfo &TLI, Function &F)
static bool replaceWithTLIFunction(CallInst &CI, const StringRef TLIName)
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.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
This class represents a function call, abstracting a target machine's calling convention.
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)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
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...
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This analysis provides dependence information for the memory accesses of a loop.
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.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
constexpr bool isNonZero() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
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.
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)