35#define DEBUG_TYPE "replace-with-veclib"
38 "Number of calls to intrinsics that have been replaced.");
41 "Number of vector library function declarations added.");
44 "Number of functions added to `llvm.compiler.used`");
51 std::optional<CallingConv::ID> CC,
63 << TLIName <<
"` of type `" << *(TLIFunc->
getType())
66 ++NumTLIFuncDeclAdded;
71 <<
"` to `@llvm.compiler.used`.\n");
83 if (Info.isMasked()) {
91 II->getOperandBundlesAsDefs(OpBundles);
96 TLIVecFunc, Args, OpBundles,
II->getFastMathFlagsOrNone());
100 II->replaceAllUsesWith(Replacement);
109 assert(
II !=
nullptr &&
"Intrinsic cannot be null");
111 Type *RetTy =
II->getType();
128 auto *ArgTy = Arg.value()->getType();
136 auto *ScalarArgTy = VectorArgTy->getElementType();
143 EC = VectorArgTy->getElementCount();
144 else if (EC != VectorArgTy->getElementCount())
153 std::string ScalarName =
167 <<
"` and vector width " << EC <<
" to: `"
183 for (
auto &VFParam : OptInfo->Shape.Parameters) {
189 assert(VFParam.ParamPos <
II->arg_size() &&
"ParamPos has invalid range");
190 Type *OrigTy =
II->getArgOperand(VFParam.ParamPos)->getType();
193 <<
". Wrong type at index " << VFParam.ParamPos <<
": "
208 <<
"` with call to `" << TLIFunc->
getName() <<
"`.\n");
237 if (
II->getIntrinsicID() != Intrinsic::sincos)
239 Value *Arg =
II->getArgOperand(0);
245 Type *ScalarTy = VTy->getElementType();
254 LibFunc LF = NotLibFunc;
256 LF = LibFunc_sincosf;
268 for (
User *U :
II->users()) {
278 CallInst *SinCall =
B.CreateCall(SinFn, {Arg},
II,
"sin");
279 CallInst *CosCall =
B.CreateCall(CosFn, {Arg},
II,
"cos");
286 EV->replaceAllUsesWith(EV->getIndices()[0] == 0 ? SinCall : CosCall);
287 EV->eraseFromParent();
315 if (!
II->getType()->isVectorTy() && !
II->getType()->isVoidTy())
322 for (
auto *
I : ReplacedCalls)
323 I->eraseFromParent();
324 return !ReplacedCalls.
empty();
335 LLVM_DEBUG(
dbgs() <<
"Intrinsic calls replaced with vector libraries: "
336 << NumCallsReplaced <<
"\n");
377 "Replace intrinsics with calls to vector library",
false,
381 "Replace intrinsics with calls to vector library",
false,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool runImpl(MachineFunction &MF)
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)
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...
static bool trySplitVectorSinCos(const TargetLibraryInfo &TLI, IntrinsicInst *II, SmallVectorImpl< Instruction * > &Replaced)
If II is a vector llvm.sincos with no direct vector library mapping but the target does have vector m...
static bool hasIntrinsicVectorMapping(const TargetLibraryInfo &TLI, Intrinsic::ID IID, Type *ScalarTy, ElementCount EC, Module *M)
Returns true when TLI has a vector mapping for IID at the given element type and EC.
Function * getTLIFunction(Module *M, FunctionType *VectorFTy, const StringRef TLIName, std::optional< CallingConv::ID > CC, Function *ScalarFunc=nullptr)
Returns a vector Function that it adds to the Module M.
static bool hasVectorMapping(const TargetLibraryInfo &TLI, StringRef Name, ElementCount EC)
Returns true when TLI has a vector mapping for the scalar function name Name at EC (matching either m...
static bool runImpl(const TargetLibraryInfo &TLI, Function &F)
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.
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.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI 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 LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
const Function & getFunction() const
void setCallingConv(CallingConv::ID CC)
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.
@ ExternalLinkage
Externally visible function.
Legacy wrapper pass to provide the GlobalsAAResult object.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
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.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
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.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Analysis pass that exposes the ScalarEvolution for a function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
std::string str() const
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 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.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI 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::optional< CallingConv::ID > getCallingConv() const
LLVM_ABI std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getVectorFnName() const
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
LLVM_ABI 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,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ABI bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic has a scalar operand.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI FunctionPass * createReplaceWithVeclibLegacyPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...
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.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Holds the VFShape for a specific scalar to vector function mapping.