37#include "llvm/IR/IntrinsicsSPIRV.h"
49class SPIRVPrepareFunctionsImpl {
50 const SPIRVTargetMachine &TM;
51 function_ref<
const TargetTransformInfo &(
Function &)> GetTTI;
52 bool substituteIntrinsicCalls(
Function *
F);
53 bool substituteAbortKHRCalls(
Function *
F);
56 bool removeAggregateTypesFromCalls(
Function *
F);
59 SPIRVPrepareFunctionsImpl(
60 const SPIRVTargetMachine &TM,
61 function_ref<
const TargetTransformInfo &(
Function &)> GetTTI)
62 : TM(TM), GetTTI(GetTTI) {}
63 bool runOnModule(
Module &M);
66class SPIRVPrepareFunctionsLegacy :
public ModulePass {
67 const SPIRVTargetMachine &TM;
71 SPIRVPrepareFunctionsLegacy(
const SPIRVTargetMachine &TM)
72 : ModulePass(ID), TM(TM) {}
74 bool runOnModule(
Module &M)
override {
75 auto GetTTI = [
this](
Function &
F) ->
const TargetTransformInfo & {
76 return getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
78 return SPIRVPrepareFunctionsImpl(TM, GetTTI).runOnModule(M);
81 void getAnalysisUsage(AnalysisUsage &AU)
const override {
85 StringRef getPassName()
const override {
return "SPIRV prepare functions"; }
89char SPIRVPrepareFunctionsLegacy::ID = 0;
92 "SPIRV prepare functions",
false,
false)
98 Function *IntrinsicFunc =
II->getCalledFunction();
99 assert(IntrinsicFunc &&
"Missing function");
100 std::string FuncName = IntrinsicFunc->
getName().
str();
102 FuncName =
"spirv." + FuncName;
111 if (
F &&
F->getFunctionType() == FT)
146 GV->setAlignment(
Align);
149 ? Intrinsic::memcpy_inline
165 "cannot lower the intrinsic '" +
166 Intrinsic->getCalledFunction()->getName() +
167 "' that takes a metadata argument",
178 FuncName +=
".volatile";
186 M->getOrInsertFunction(FuncName,
Intrinsic->getFunctionType());
187 auto IntrinsicID =
Intrinsic->getIntrinsicID();
192 switch (IntrinsicID) {
193 case Intrinsic::memset: {
202 IsVolatile->setName(
"isvolatile");
205 auto *MemSet = IRB.
CreateMemSet(Dest, Val, Len, MSI->getDestAlign(),
209 MemSet->eraseFromParent();
212 case Intrinsic::bswap: {
216 Intrinsic::bswap,
Intrinsic->getType(),
F->getArg(0));
230 AnnoVal =
Ref->getOperand(0);
232 OptAnnoVal =
Ref->getOperand(0);
243 C &&
C->getNumOperands()) {
244 Value *MaybeStruct =
C->getOperand(0);
246 for (
unsigned I = 0,
E = Struct->getNumOperands();
I !=
E; ++
I) {
248 Anno += (
I == 0 ?
": " :
", ") +
249 std::to_string(CInt->getType()->getIntegerBitWidth() == 1
250 ? CInt->getZExtValue()
251 : CInt->getSExtValue());
255 for (
unsigned I = 0,
E = Struct->getType()->getStructNumElements();
257 Anno +=
I == 0 ?
": 0" :
", 0";
264 const std::string &Anno,
271 static const std::regex R(
272 "\\{(\\d+)(?:[:,](\\d+|\"[^\"]*\")(?:,(\\d+|\"[^\"]*\"))*)?\\}");
275 for (std::sregex_iterator
276 It = std::sregex_iterator(Anno.begin(), Anno.end(), R),
277 ItEnd = std::sregex_iterator();
279 if (It->position() != Pos)
281 Pos = It->position() + It->length();
282 std::smatch Match = *It;
284 for (std::size_t i = 1; i < Match.size(); ++i) {
285 std::ssub_match SMatch = Match[i];
286 std::string Item = SMatch.str();
287 if (Item.length() == 0)
289 if (Item[0] ==
'"') {
290 Item = Item.substr(1, Item.length() - 2);
292 static const std::regex RStr(
"^(\\d+)(?:,(\\d+))*$");
293 if (std::smatch MatchStr; std::regex_match(Item, MatchStr, RStr)) {
294 for (std::size_t SubIdx = 1; SubIdx < MatchStr.size(); ++SubIdx)
295 if (std::string SubStr = MatchStr[SubIdx].str(); SubStr.length())
297 ConstantInt::get(Int32Ty, std::stoi(SubStr))));
308 if (MDsItem.
size() == 0)
312 return Pos ==
static_cast<int>(Anno.length()) ? std::move(MDs)
321 Value *PtrArg =
nullptr;
323 PtrArg = BI->getOperand(0);
325 PtrArg =
II->getOperand(0);
328 4 <
II->arg_size() ?
II->getArgOperand(4) :
nullptr);
337 if (MDs.
size() == 0) {
339 Int32Ty,
static_cast<uint32_t>(SPIRV::Decoration::UserSemantic)));
347 Intrinsic::spv_assign_decoration, {PtrArg->
getType()},
349 II->replaceAllUsesWith(
II->getOperand(0));
359 Type *FSHRetTy = FSHFuncTy->getReturnType();
364 if (!FSHFunc->
empty()) {
376 unsigned BitWidth = IntTy->getIntegerBitWidth();
378 Value *BitWidthForInsts =
382 Value *RotateModVal =
384 Value *FirstShift =
nullptr, *SecShift =
nullptr;
397 Value *SubRotateVal = IRB.
CreateSub(BitWidthForInsts, RotateModVal);
416 if (!ConstrainedCmpIntrinsic)
438 if (
II->getIntrinsicID() == Intrinsic::assume) {
440 II->getModule(), Intrinsic::SPVIntrinsics::spv_assume);
441 II->setCalledFunction(
F);
442 }
else if (
II->getIntrinsicID() == Intrinsic::expect) {
444 II->getModule(), Intrinsic::SPVIntrinsics::spv_expect,
445 {II->getOperand(0)->getType()});
446 II->setCalledFunction(
F);
447 }
else if (
II->getIntrinsicID() == Intrinsic::expect_with_probability) {
450 Value *Res =
II->getArgOperand(0);
455 Intrinsic::SPVIntrinsics::spv_expect, {
II->getType()},
456 {
II->getArgOperand(0),
II->getArgOperand(1)});
465 auto *LifetimeArg0 =
II->getArgOperand(0);
469 II->eraseFromParent();
474 if (!Alloca || !Alloca->isStaticAlloca()) {
475 II->eraseFromParent();
480 std::optional<TypeSize>
Size =
481 Alloca->getAllocationSize(Alloca->getDataLayout());
483 Builder.CreateIntrinsic(NewID, Alloca->getType(), {SizeVal, LifetimeArg0});
484 II->eraseFromParent();
492 Value *
A = FPI->getArgOperand(0);
496 Builder.SetInsertPoint(
II);
497 std::optional<RoundingMode> Rounding = FPI->getRoundingMode();
498 Value *Product = Builder.CreateFMul(
A,
Mul,
II->getName() +
".mul");
500 Intrinsic::experimental_constrained_fadd, Product,
Add, {},
501 II->getName() +
".add",
nullptr, Rounding);
509 Type *Ty =
X->getType();
510 Value *XSign = Builder.CreateCopySign(ConstantFP::get(Ty, 1.0),
X);
512 Value *
Sign = IsMax ? Builder.CreateSelect(XNeg,
Y,
X)
513 : Builder.CreateSelect(XNeg,
X,
Y);
514 return Builder.CreateCopySign(Res,
Sign);
535 Type *Ty =
X->getType();
536 Value *Res = Builder.CreateIntrinsic(
537 IsMax ? Intrinsic::maxnum : Intrinsic::minnum, {Ty}, {
X,
Y}, FMF);
541 Value *Uno = Builder.CreateFCmpUNO(
X,
Y);
551 Builder,
II->getIntrinsicID() == Intrinsic::maximum,
II->getArgOperand(0),
552 II->getArgOperand(1),
II->getFastMathFlags());
554 II->replaceAllUsesWith(Res);
565 bool IsMax =
II->getIntrinsicID() == Intrinsic::maximumnum;
566 Value *
X =
II->getArgOperand(0), *
Y =
II->getArgOperand(1);
567 Type *Ty =
X->getType();
570 X = Builder.CreateSelect(Builder.CreateFCmpUNO(
X,
X),
Y,
X);
571 Y = Builder.CreateSelect(Builder.CreateFCmpUNO(
Y,
Y),
X,
Y);
575 Value *Res = Builder.CreateIntrinsic(
576 IsMax ? Intrinsic::maxnum : Intrinsic::minnum, {Ty}, {
X,
Y});
580 II->replaceAllUsesWith(Res);
590 bool IsMax =
II->getIntrinsicID() == Intrinsic::vector_reduce_fmaximum;
591 Value *Vec =
II->getArgOperand(0);
595 for (
unsigned I = 0;
I < NumElts; ++
I)
596 Elts.
push_back(Builder.CreateExtractElement(Vec,
I));
597 Value *Res = Elts[0];
602 II->replaceAllUsesWith(Res);
608bool SPIRVPrepareFunctionsImpl::substituteIntrinsicCalls(
Function *
F) {
609 if (
F->isDeclaration())
613 const SPIRVSubtarget &STI = TM.
getSubtarget<SPIRVSubtarget>(*F);
614 SmallVector<Instruction *> EraseFromParent;
615 const TargetTransformInfo &
TTI = GetTTI(*
F);
616 for (BasicBlock &BB : *
F) {
626 II->getCalledOperand()->getName().starts_with(
"llvm.spv"))
633 switch (
II->getIntrinsicID()) {
634 case Intrinsic::memset:
635 case Intrinsic::bswap:
638 case Intrinsic::fshl:
639 case Intrinsic::fshr:
643 case Intrinsic::minimum:
644 case Intrinsic::maximum:
648 case Intrinsic::minimumnum:
649 case Intrinsic::maximumnum:
653 case Intrinsic::vector_reduce_fminimum:
654 case Intrinsic::vector_reduce_fmaximum:
658 case Intrinsic::assume:
659 case Intrinsic::expect:
660 case Intrinsic::expect_with_probability:
665 case Intrinsic::lifetime_start:
668 II, Intrinsic::SPVIntrinsics::spv_lifetime_start);
670 II->eraseFromParent();
674 case Intrinsic::lifetime_end:
677 II, Intrinsic::SPVIntrinsics::spv_lifetime_end);
679 II->eraseFromParent();
683 case Intrinsic::ptr_annotation:
687 case Intrinsic::experimental_constrained_fmuladd:
691 case Intrinsic::experimental_constrained_fcmp:
692 case Intrinsic::experimental_constrained_fcmps:
699 if (
II->isAssumeLikeIntrinsic()) {
700 if (!
II->getType()->isVoidTy())
702 II->eraseFromParent();
706 if (STI.getTargetTriple().getVendor() ==
Triple::AMD ||
708 [
II](StringRef Prefix) {
711 return II->getCalledFunction()->getName().starts_with(
719 for (
auto *
I : EraseFromParent)
720 I->eraseFromParent();
734 transform(ChangedTys, std::back_inserter(MDArgs), [=, &Ctx](
auto &&CTy) {
739 if (!AsmConstraints.empty())
748 V->removeRetAttrs(AttributeFuncs::typeIncompatible(FTy->getReturnType(),
749 Attrs.getRetAttrs()));
752 I, AttributeFuncs::typeIncompatible(Ty, Attrs.getParamAttrs(
I)));
759SPIRVPrepareFunctionsImpl::removeAggregateTypesFromSignature(
Function *
F) {
760 bool IsRetAggr =
F->getReturnType()->isAggregateType();
764 if (
F->isIntrinsic())
769 bool HasAggrArg =
llvm::any_of(
F->args(), [](Argument &Arg) {
770 return Arg.getType()->isAggregateType();
772 bool DoClone = IsRetAggr || HasAggrArg;
776 Type *RetType = IsRetAggr ?
B.getInt32Ty() :
F->getReturnType();
778 ChangedTypes.
push_back(std::pair<int, Type *>(-1,
F->getReturnType()));
780 for (
const auto &Arg :
F->args()) {
781 if (Arg.getType()->isAggregateType()) {
784 std::pair<int, Type *>(Arg.getArgNo(), Arg.getType()));
788 FunctionType *NewFTy =
789 FunctionType::get(RetType, ArgTypes,
F->getFunctionType()->isVarArg());
792 F->getName(),
F->getParent());
796 for (
auto &Arg :
F->args()) {
797 StringRef ArgName = Arg.getName();
798 NewFArgIt->setName(ArgName);
799 VMap[&Arg] = &(*NewFArgIt++);
811 std::move(ChangedTypes), NewF->
getName());
813 for (User *U :
F->users()) {
822 "RAUW requires F and NewF to share the same pointer type");
823 F->replaceAllUsesWith(NewF);
826 if (RetType !=
F->getReturnType())
827 TM.
getSubtarget<SPIRVSubtarget>(*F).getSPIRVGlobalRegistry()->addMutated(
828 NewF,
F->getReturnType());
839 if (!Name.contains(
"__spirv_AbortKHR"))
842 if (Demangled.empty())
862 Msg =
B.CreateLoad(AggTy,
Msg);
864 B.CreateIntrinsic(Intrinsic::spv_abort, {
Msg->getType()}, {
Msg});
871bool SPIRVPrepareFunctionsImpl::substituteAbortKHRCalls(
Function *
F) {
878 if (!CI || CI->getCalledFunction() !=
F)
880 if (CI->arg_size() != 1)
896bool SPIRVPrepareFunctionsImpl::terminateBlocksAfterTrap(
Module &M,
898 assert((IID == Intrinsic::trap || IID == Intrinsic::ubsantrap) &&
899 "Expected trap intrinsic ID");
909 if (!
ST.canUseExtension(SPIRV::Extension::SPV_KHR_abort))
915 if (!CI || CI->getCalledFunction() !=
F)
930 std::string SafeConstraints(
"=r,");
931 for (
unsigned I = 0u;
I != Tmp.
size() - 1; ++
I) {
932 if (Tmp[
I].
starts_with(
'=') && (Tmp[
I][1] ==
'&' || isalnum(Tmp[
I][1])))
934 SafeConstraints.append(Tmp[
I]).append({
','});
936 SafeConstraints.append(Tmp.
back());
938 return SafeConstraints;
946bool SPIRVPrepareFunctionsImpl::removeAggregateTypesFromCalls(
Function *
F) {
947 if (
F->isDeclaration() ||
F->isIntrinsic())
953 if (!CB->getCalledOperand() || CB->getCalledFunction())
955 if (CB->getType()->isAggregateType() ||
957 [](
auto &&Arg) { return Arg->getType()->isAggregateType(); }))
967 unsigned MutatedCallIdx = 0;
968 for (
auto &&[CB, NewFnTy] : Calls) {
972 Type *RetTy = CB->getType();
978 for (
auto &&Arg : CB->args()) {
979 if (Arg->getType()->isAggregateType()) {
981 ChangedTypes.
emplace_back(Arg.getOperandNo(), Arg->getType());
986 NewFnTy = FunctionType::get(RetTy, NewArgTypes,
987 CB->getFunctionType()->isVarArg());
991 (
"spv.mutated_callsite." +
F->getName() +
"." + Twine(MutatedCallIdx++))
994 "spv.mutated_callsite",
997 std::string Constraints;
999 Constraints = ASM->getConstraintString();
1002 NewFnTy, ASM->getAsmString(),
1004 ASM->isAlignStack(), ASM->getDialect(), ASM->canThrow()));
1008 F->getParent()->getOrInsertNamedMetadata(
"spv.mutated_callsites"),
1009 std::move(ChangedTypes),
Key, Constraints);
1012 for (
auto &&[CB, NewFTy] : Calls) {
1013 if (NewFTy->getReturnType() != CB->getType())
1014 TM.
getSubtarget<SPIRVSubtarget>(*F).getSPIRVGlobalRegistry()->addMutated(
1016 CB->mutateFunctionType(NewFTy);
1023bool SPIRVPrepareFunctionsImpl::runOnModule(
Module &M) {
1027 const_cast<SPIRVTargetMachine &
>(TM)
1028 .getMutableSubtargetImpl()
1029 ->resolveEnvFromModule(M);
1032 if (
M.getFunctionDefs().empty()) {
1040 IRB.CreateRetVoid();
1044 Changed |= terminateBlocksAfterTrap(M, Intrinsic::trap);
1045 Changed |= terminateBlocksAfterTrap(M, Intrinsic::ubsantrap);
1047 for (GlobalVariable &GV :
M.globals()) {
1050 if (GV.hasAvailableExternallyLinkage() && !GV.isDeclaration()) {
1057 std::vector<Function *> FuncsWorklist;
1061 if (
F.hasAvailableExternallyLinkage() && !
F.isDeclaration()) {
1066 Changed |= substituteAbortKHRCalls(&
F);
1067 Changed |= substituteIntrinsicCalls(&
F);
1069 Changed |= removeAggregateTypesFromCalls(&
F);
1070 FuncsWorklist.push_back(&
F);
1073 for (
auto *
F : FuncsWorklist) {
1074 Function *NewF = removeAggregateTypesFromSignature(
F);
1077 F->eraseFromParent();
1091 return SPIRVPrepareFunctionsImpl(TM, GetTTI).runOnModule(M)
1098 return new SPIRVPrepareFunctionsLegacy(TM);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 Value * expandFMinimumMaximum(IRBuilderBase &Builder, bool IsMax, Value *X, Value *Y, FastMathFlags FMF)
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 bool lowerConstantMemSet(MemSetInst *MSI, const SPIRVSubtarget &STI)
static Value * fixZeroSign(IRBuilderBase &Builder, bool IsMax, Value *Res, Value *X, Value *Y)
static void lowerVectorReduceFMinimumMaximum(IntrinsicInst *II, SmallVector< Instruction * > &EraseFromParent)
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 void removeIncompatibleAttrs(T *V)
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 void lowerFMinimumMaximumNum(IntrinsicInst *II, SmallVector< Instruction * > &EraseFromParent)
static void lowerFMinimumMaximum(IntrinsicInst *II, SmallVector< Instruction * > &EraseFromParent)
static Function * getOrCreateFunction(Module *M, Type *RetTy, ArrayRef< Type * > ArgTypes, StringRef Name)
#define SPIRV_WAS_AVAILABLE_EXTERNALLY_ATTR
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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),...
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
InstListType::iterator iterator
Instruction iterators...
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.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static LLVM_ABI ConstantFP * getZero(Type *Ty, bool Negative=false)
static LLVM_ABI ConstantFP * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
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.
Convenience struct for specifying and reasoning about fast-math flags.
bool noSignedZeros() const
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
LLVM_ABI void setComdat(Comdat *C)
Module * getParent()
Get the module that this global value is contained inside of...
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
Common base class shared among various IRBuilders.
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.
LLVM_ABI CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
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...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
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)
Value * getLength() const
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
MaybeAlign getDestAlign() const
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)
const SPIRVOptions & getCLOpts() const
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 STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
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.
@ 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.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
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.
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 ReplaceInstWithValue(BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
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.
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
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.
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 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
LLVM_ABI void expandMemSetAsLoop(MemSetInst *MemSet, const TargetTransformInfo &TTI)
Expand MemSet as a loop according to the target's preferences.
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.