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");
79 if (
auto OptMaskpos =
Info.getParamIndexForOptionalMask()) {
82 Args.insert(Args.begin() + OptMaskpos.value(),
88 II->getOperandBundlesAsDefs(OpBundles);
91 II->replaceAllUsesWith(Replacement);
93 if (isa<FPMathOperator>(Replacement))
94 Replacement->copyFastMathFlags(
II);
102 assert(
II !=
nullptr &&
"Intrinsic cannot be null");
105 auto *VTy = dyn_cast<VectorType>(
II->getType());
112 auto *ArgTy = Arg.value()->getType();
115 }
else if (
auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
116 ScalarArgTypes.
push_back(VectorArgTy->getElementType());
120 EC = VectorArgTy->getElementCount();
121 else if (EC != VectorArgTy->getElementCount())
130 std::string ScalarName =
144 <<
"` and vector width " << EC <<
" to: `"
149 Type *ScalarRetTy =
II->getType()->getScalarType();
151 FunctionType::get(ScalarRetTy, ScalarArgTypes,
false);
161 for (
auto &VFParam : OptInfo->Shape.Parameters) {
162 if (VFParam.ParamKind == VFParamKind::GlobalPredicate)
167 assert(VFParam.ParamPos <
II->arg_size() &&
"ParamPos has invalid range");
168 Type *OrigTy =
II->getArgOperand(VFParam.ParamPos)->getType();
169 if (OrigTy->
isVectorTy() != (VFParam.ParamKind == VFParamKind::Vector)) {
171 <<
". Wrong type at index " << VFParam.ParamPos <<
": "
183 II->getCalledFunction());
186 <<
"` with call to `" << TLIFunc->
getName() <<
"`.\n");
195 if (
auto *
II = dyn_cast<IntrinsicInst>(&
I)) {
196 if (!
II->getType()->isVectorTy() && !
II->getType()->isVoidTy())
204 for (
auto *
I : ReplacedCalls)
205 I->eraseFromParent();
206 return !ReplacedCalls.
empty();
217 LLVM_DEBUG(
dbgs() <<
"Intrinsic calls replaced with vector libraries: "
218 << NumCallsReplaced <<
"\n");
239 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
259 "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.
uint64_t IntrinsicInst * II
#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 bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI, IntrinsicInst *II)
Returns true when successfully replaced II, which is a call to a vectorized intrinsic,...
static void replaceWithTLIFunction(IntrinsicInst *II, VFInfo &Info, Function *TLIVecFunc)
Replace the intrinsic call II to TLIVecFunc, which is the corresponding function from the vector libr...
Replace intrinsics with calls to vector library
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)
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...
A wrapper class for inspecting calls to intrinsic functions.
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.
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)
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 tuples (A, B,...
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.