37#include "llvm/IR/IntrinsicsSPIRV.h"
48class SPIRVPrepareFunctionsImpl {
49 const SPIRVTargetMachine &TM;
50 function_ref<
const TargetTransformInfo &(
Function &)> GetTTI;
51 bool substituteIntrinsicCalls(Function *
F);
52 bool substituteAbortKHRCalls(Function *
F);
54 Function *removeAggregateTypesFromSignature(Function *
F);
55 bool removeAggregateTypesFromCalls(Function *
F);
58 SPIRVPrepareFunctionsImpl(
59 const SPIRVTargetMachine &TM,
60 function_ref<
const TargetTransformInfo &(Function &)> GetTTI)
61 : TM(TM), GetTTI(GetTTI) {}
62 bool runOnModule(
Module &M);
65class SPIRVPrepareFunctionsLegacy :
public ModulePass {
66 const SPIRVTargetMachine &TM;
70 SPIRVPrepareFunctionsLegacy(
const SPIRVTargetMachine &TM)
71 : ModulePass(ID), TM(TM) {}
73 bool runOnModule(
Module &M)
override {
74 auto GetTTI = [
this](
Function &
F) ->
const TargetTransformInfo & {
75 return getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
77 return SPIRVPrepareFunctionsImpl(TM, GetTTI).runOnModule(M);
80 void getAnalysisUsage(AnalysisUsage &AU)
const override {
84 StringRef getPassName()
const override {
return "SPIRV prepare functions"; }
89 cl::desc(
"Emit unknown intrinsics as calls to external functions. A "
90 "comma-separated input list of intrinsic prefixes must be "
91 "provided, and only intrinsics carrying a listed prefix get "
92 "emitted as described."),
96char SPIRVPrepareFunctionsLegacy::ID = 0;
99 "SPIRV prepare functions",
false,
false)
105 Function *IntrinsicFunc =
II->getCalledFunction();
106 assert(IntrinsicFunc &&
"Missing function");
107 std::string FuncName = IntrinsicFunc->
getName().
str();
109 FuncName =
"spirv." + FuncName;
118 if (
F &&
F->getFunctionType() == FT)
143 "cannot lower the intrinsic '" +
144 Intrinsic->getCalledFunction()->getName() +
145 "' that takes a metadata argument",
156 FuncName +=
".volatile";
164 M->getOrInsertFunction(FuncName,
Intrinsic->getFunctionType());
165 auto IntrinsicID =
Intrinsic->getIntrinsicID();
170 switch (IntrinsicID) {
171 case Intrinsic::memset: {
180 IsVolatile->setName(
"isvolatile");
183 auto *MemSet = IRB.
CreateMemSet(Dest, Val, Len, MSI->getDestAlign(),
187 MemSet->eraseFromParent();
190 case Intrinsic::bswap: {
194 Intrinsic::bswap,
Intrinsic->getType(),
F->getArg(0));
208 AnnoVal =
Ref->getOperand(0);
210 OptAnnoVal =
Ref->getOperand(0);
221 C &&
C->getNumOperands()) {
222 Value *MaybeStruct =
C->getOperand(0);
224 for (
unsigned I = 0,
E = Struct->getNumOperands();
I !=
E; ++
I) {
226 Anno += (
I == 0 ?
": " :
", ") +
227 std::to_string(CInt->getType()->getIntegerBitWidth() == 1
228 ? CInt->getZExtValue()
229 : CInt->getSExtValue());
233 for (
unsigned I = 0,
E = Struct->getType()->getStructNumElements();
235 Anno +=
I == 0 ?
": 0" :
", 0";
242 const std::string &Anno,
249 static const std::regex R(
250 "\\{(\\d+)(?:[:,](\\d+|\"[^\"]*\")(?:,(\\d+|\"[^\"]*\"))*)?\\}");
253 for (std::sregex_iterator
254 It = std::sregex_iterator(Anno.begin(), Anno.end(), R),
255 ItEnd = std::sregex_iterator();
257 if (It->position() != Pos)
259 Pos = It->position() + It->length();
260 std::smatch Match = *It;
262 for (std::size_t i = 1; i < Match.size(); ++i) {
263 std::ssub_match SMatch = Match[i];
264 std::string Item = SMatch.str();
265 if (Item.length() == 0)
267 if (Item[0] ==
'"') {
268 Item = Item.substr(1, Item.length() - 2);
270 static const std::regex RStr(
"^(\\d+)(?:,(\\d+))*$");
271 if (std::smatch MatchStr; std::regex_match(Item, MatchStr, RStr)) {
272 for (std::size_t SubIdx = 1; SubIdx < MatchStr.size(); ++SubIdx)
273 if (std::string SubStr = MatchStr[SubIdx].str(); SubStr.length())
275 ConstantInt::get(Int32Ty, std::stoi(SubStr))));
286 if (MDsItem.
size() == 0)
290 return Pos ==
static_cast<int>(Anno.length()) ? std::move(MDs)
299 Value *PtrArg =
nullptr;
301 PtrArg = BI->getOperand(0);
303 PtrArg =
II->getOperand(0);
306 4 <
II->arg_size() ?
II->getArgOperand(4) :
nullptr);
315 if (MDs.
size() == 0) {
317 Int32Ty,
static_cast<uint32_t>(SPIRV::Decoration::UserSemantic)));
325 Intrinsic::spv_assign_decoration, {PtrArg->
getType()},
327 II->replaceAllUsesWith(
II->getOperand(0));
337 Type *FSHRetTy = FSHFuncTy->getReturnType();
342 if (!FSHFunc->
empty()) {
354 unsigned BitWidth = IntTy->getIntegerBitWidth();
356 Value *BitWidthForInsts =
360 Value *RotateModVal =
362 Value *FirstShift =
nullptr, *SecShift =
nullptr;
375 Value *SubRotateVal = IRB.
CreateSub(BitWidthForInsts, RotateModVal);
394 if (!ConstrainedCmpIntrinsic)
416 if (
II->getIntrinsicID() == Intrinsic::assume) {
418 II->getModule(), Intrinsic::SPVIntrinsics::spv_assume);
419 II->setCalledFunction(
F);
420 }
else if (
II->getIntrinsicID() == Intrinsic::expect) {
422 II->getModule(), Intrinsic::SPVIntrinsics::spv_expect,
423 {II->getOperand(0)->getType()});
424 II->setCalledFunction(
F);
431 auto *LifetimeArg0 =
II->getArgOperand(0);
435 II->eraseFromParent();
441 std::optional<TypeSize>
Size =
442 Alloca->getAllocationSize(Alloca->getDataLayout());
444 Builder.CreateIntrinsic(NewID, Alloca->getType(), {SizeVal, LifetimeArg0});
445 II->eraseFromParent();
453 Value *
A = FPI->getArgOperand(0);
457 Builder.SetInsertPoint(
II);
458 std::optional<RoundingMode> Rounding = FPI->getRoundingMode();
459 Value *Product = Builder.CreateFMul(
A,
Mul,
II->getName() +
".mul");
460 Value *Result = Builder.CreateConstrainedFPBinOp(
461 Intrinsic::experimental_constrained_fadd, Product,
Add, {},
462 II->getName() +
".add",
nullptr, Rounding);
463 II->replaceAllUsesWith(Result);
469bool SPIRVPrepareFunctionsImpl::substituteIntrinsicCalls(
Function *
F) {
470 if (
F->isDeclaration())
474 const SPIRVSubtarget &STI = TM.
getSubtarget<SPIRVSubtarget>(*F);
475 SmallVector<Instruction *> EraseFromParent;
476 const TargetTransformInfo &
TTI = GetTTI(*
F);
477 for (BasicBlock &BB : *
F) {
487 II->getCalledOperand()->getName().starts_with(
"llvm.spv"))
489 switch (
II->getIntrinsicID()) {
490 case Intrinsic::memset:
491 case Intrinsic::bswap:
494 case Intrinsic::fshl:
495 case Intrinsic::fshr:
499 case Intrinsic::assume:
500 case Intrinsic::expect:
505 case Intrinsic::lifetime_start:
508 II, Intrinsic::SPVIntrinsics::spv_lifetime_start);
510 II->eraseFromParent();
514 case Intrinsic::lifetime_end:
517 II, Intrinsic::SPVIntrinsics::spv_lifetime_end);
519 II->eraseFromParent();
523 case Intrinsic::ptr_annotation:
527 case Intrinsic::experimental_constrained_fmuladd:
531 case Intrinsic::experimental_constrained_fcmp:
532 case Intrinsic::experimental_constrained_fcmps:
539 if (
II->isAssumeLikeIntrinsic()) {
540 if (!
II->getType()->isVoidTy())
542 II->eraseFromParent();
547 any_of(SPVAllowUnknownIntrinsics, [
II](
auto &&Prefix) {
550 return II->getCalledFunction()->getName().starts_with(Prefix);
557 for (
auto *
I : EraseFromParent)
558 I->eraseFromParent();
572 transform(ChangedTys, std::back_inserter(MDArgs), [=, &Ctx](
auto &&CTy) {
577 if (!AsmConstraints.empty())
586SPIRVPrepareFunctionsImpl::removeAggregateTypesFromSignature(Function *
F) {
587 bool IsRetAggr =
F->getReturnType()->isAggregateType();
591 if (
F->isIntrinsic())
596 bool HasAggrArg =
llvm::any_of(
F->args(), [](Argument &Arg) {
597 return Arg.getType()->isAggregateType();
599 bool DoClone = IsRetAggr || HasAggrArg;
603 Type *RetType = IsRetAggr ?
B.getInt32Ty() :
F->getReturnType();
605 ChangedTypes.
push_back(std::pair<int, Type *>(-1,
F->getReturnType()));
607 for (
const auto &Arg :
F->args()) {
608 if (Arg.getType()->isAggregateType()) {
611 std::pair<int, Type *>(Arg.getArgNo(), Arg.getType()));
615 FunctionType *NewFTy =
616 FunctionType::get(RetType, ArgTypes,
F->getFunctionType()->isVarArg());
619 F->getName(),
F->getParent());
623 for (
auto &Arg :
F->args()) {
624 StringRef ArgName = Arg.getName();
625 NewFArgIt->setName(ArgName);
626 VMap[&Arg] = &(*NewFArgIt++);
636 std::move(ChangedTypes), NewF->
getName());
643 C->handleOperandChange(
F, NewF);
645 U->replaceUsesOfWith(
F, NewF);
649 if (RetType !=
F->getReturnType())
650 TM.
getSubtarget<SPIRVSubtarget>(*F).getSPIRVGlobalRegistry()->addMutated(
651 NewF,
F->getReturnType());
662 if (!Name.contains(
"__spirv_AbortKHR"))
665 if (Demangled.empty())
685 Msg =
B.CreateLoad(AggTy,
Msg);
687 B.CreateIntrinsic(Intrinsic::spv_abort, {
Msg->getType()}, {
Msg});
694bool SPIRVPrepareFunctionsImpl::substituteAbortKHRCalls(Function *
F) {
699 for (User *U :
F->users()) {
701 if (!CI || CI->getCalledFunction() !=
F)
703 if (CI->arg_size() != 1)
708 for (CallInst *CI : Calls)
711 return !Calls.empty();
721bool SPIRVPrepareFunctionsImpl::terminateBlocksAfterTrap(
Module &M,
723 assert((IID == Intrinsic::trap || IID == Intrinsic::ubsantrap) &&
724 "Expected trap intrinsic ID");
734 if (!
ST.canUseExtension(SPIRV::Extension::SPV_KHR_abort))
738 for (User *U :
F->users()) {
740 if (!CI || CI->getCalledFunction() !=
F)
746 for (CallInst *CI : Calls) {
760 std::string SafeConstraints(
"=r,");
761 for (
unsigned I = 0u;
I != Tmp.
size() - 1; ++
I) {
762 if (Tmp[
I].
starts_with(
'=') && (Tmp[
I][1] ==
'&' || isalnum(Tmp[
I][1])))
764 SafeConstraints.append(Tmp[
I]).append({
','});
766 SafeConstraints.append(Tmp.
back());
768 return SafeConstraints;
776bool SPIRVPrepareFunctionsImpl::removeAggregateTypesFromCalls(Function *
F) {
777 if (
F->isDeclaration() ||
F->isIntrinsic())
783 if (!CB->getCalledOperand() || CB->getCalledFunction())
785 if (CB->getType()->isAggregateType() ||
787 [](
auto &&Arg) { return Arg->getType()->isAggregateType(); }))
797 unsigned MutatedCallIdx = 0;
798 for (
auto &&[CB, NewFnTy] : Calls) {
802 Type *RetTy = CB->getType();
808 for (
auto &&Arg : CB->args()) {
809 if (Arg->getType()->isAggregateType()) {
811 ChangedTypes.
emplace_back(Arg.getOperandNo(), Arg->getType());
816 NewFnTy = FunctionType::get(RetTy, NewArgTypes,
817 CB->getFunctionType()->isVarArg());
821 (
"spv.mutated_callsite." +
F->getName() +
"." + Twine(MutatedCallIdx++))
824 "spv.mutated_callsite",
827 std::string Constraints;
829 Constraints = ASM->getConstraintString();
832 NewFnTy, ASM->getAsmString(),
834 ASM->isAlignStack(), ASM->getDialect(), ASM->canThrow()));
838 F->getParent()->getOrInsertNamedMetadata(
"spv.mutated_callsites"),
839 std::move(ChangedTypes),
Key, Constraints);
842 for (
auto &&[CB, NewFTy] : Calls) {
843 if (NewFTy->getReturnType() != CB->getType())
844 TM.
getSubtarget<SPIRVSubtarget>(*F).getSPIRVGlobalRegistry()->addMutated(
846 CB->mutateFunctionType(NewFTy);
852bool SPIRVPrepareFunctionsImpl::runOnModule(
Module &M) {
856 const_cast<SPIRVTargetMachine &
>(TM)
857 .getMutableSubtargetImpl()
858 ->resolveEnvFromModule(M);
861 if (
M.getFunctionDefs().empty()) {
873 Changed |= terminateBlocksAfterTrap(M, Intrinsic::trap);
874 Changed |= terminateBlocksAfterTrap(M, Intrinsic::ubsantrap);
876 for (GlobalVariable &GV :
M.globals()) {
879 if (GV.hasAvailableExternallyLinkage() && !GV.isDeclaration()) {
886 for (Function &
F : M) {
889 if (
F.hasAvailableExternallyLinkage() && !
F.isDeclaration()) {
894 Changed |= substituteAbortKHRCalls(&
F);
895 Changed |= substituteIntrinsicCalls(&
F);
897 Changed |= removeAggregateTypesFromCalls(&
F);
900 std::vector<Function *> FuncsWorklist;
902 FuncsWorklist.push_back(&
F);
904 for (
auto *
F : FuncsWorklist) {
905 Function *NewF = removeAggregateTypesFromSignature(
F);
908 F->eraseFromParent();
922 return SPIRVPrepareFunctionsImpl(TM, GetTTI).runOnModule(M)
929 return new SPIRVPrepareFunctionsLegacy(TM);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Machine Check Debug Module
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static void lowerFunnelShifts(IntrinsicInst *FSHIntrinsic)
static std::string getAnnotation(Value *AnnoVal, Value *OptAnnoVal)
spirv prepare SPIRV prepare static false std::string lowerLLVMIntrinsicName(IntrinsicInst *II)
static void lowerConstrainedFPCmpIntrinsic(ConstrainedFPCmpIntrinsic *ConstrainedCmpIntrinsic, SmallVector< Instruction * > &EraseFromParent)
static void lowerConstrainedFmuladd(IntrinsicInst *II, SmallVector< Instruction * > &EraseFromParent)
static void lowerPtrAnnotation(IntrinsicInst *II)
static bool lowerIntrinsicToFunction(IntrinsicInst *Intrinsic, const TargetTransformInfo &TTI)
static bool isAbortKHRBuiltin(const Function &F)
static SmallVector< Metadata * > parseAnnotation(Value *I, const std::string &Anno, LLVMContext &Ctx, Type *Int32Ty)
static std::string fixMultiOutputConstraintString(StringRef Constraints)
static void rewriteAbortKHRCall(CallInst *CI)
static void addFunctionTypeMutation(NamedMDNode *NMD, SmallVector< std::pair< int, Type * > > ChangedTys, StringRef Name, StringRef AsmConstraints="")
static bool toSpvLifetimeIntrinsic(IntrinsicInst *II, Intrinsic::ID NewID)
static void lowerExpectAssume(IntrinsicInst *II)
static Function * getOrCreateFunction(Module *M, Type *RetTy, ArrayRef< Type * > ArgTypes, StringRef Name)
#define SPIRV_WAS_AVAILABLE_EXTERNALLY_ATTR
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
This class represents an incoming formal argument to a Function.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This is the shared class of boolean and integer constants.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Constrained floating point compare intrinsics.
LLVM_ABI FCmpInst::Predicate getPredicate() const
Diagnostic information for unsupported feature in backend.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
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)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Type * getReturnType() const
Returns the type of the ret val.
void setCallingConv(CallingConv::ID CC)
Argument * getArg(unsigned i) const
Module * getParent()
Get the module that this global value is contained inside of...
void setDSOLocal(bool Local)
@ ExternalLinkage
Externally visible function.
LLVM_ABI CallInst * CreateIntrinsicWithoutFolding(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={})
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert a memset to the specified pointer and the specified value.
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static LLVM_ABI InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
LLVM_ABI void LowerIntrinsicCall(CallInst *CI)
Replace a call to the specified intrinsic function.
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
LLVMContext & getContext() const
Get the global data context.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Module * getParent()
Get the module that holds this named metadata collection.
LLVM_ABI void addOperand(MDNode *M)
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
bool canUseExtension(SPIRV::Extension::Extension E) const
reference emplace_back(ArgTypes &&... Args)
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 TargetTransformInfo.
const Triple & getTargetTriple() const
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
VendorType getVendor() const
Get the parsed vendor type of this triple.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isAggregateType() const
Return true if the type is an aggregate type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Type * getElementType() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
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 isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
std::string lookupBuiltinNameHelper(StringRef DemangledCall, FPDecorationId *DecorationId)
Parses the name part of the demangled builtin call.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
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...
bool sortBlocks(Function &F)
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
Function * getOrCreateBackendServiceFunction(Module &M)
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
auto dyn_cast_or_null(const Y &Val)
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
@ Ref
The access may reference the value stored in memory.
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
void replace(R &&Range, const T &OldValue, const T &NewValue)
Provide wrappers to std::replace which take ranges instead of having to pass begin/end explicitly.
constexpr unsigned BitWidth
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI void expandMemSetAsLoop(MemSetInst *MemSet, const TargetTransformInfo *TTI=nullptr)
Expand MemSet as a loop.
LLVM_ABI void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
ModulePass * createSPIRVPrepareFunctionsPass(const SPIRVTargetMachine &TM)
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Implement std::hash so that hash_code can be used in STL containers.