LLVM 18.0.0git
SPIRVPrepareFunctions.cpp
Go to the documentation of this file.
1//===-- SPIRVPrepareFunctions.cpp - modify function signatures --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This pass modifies function signatures containing aggregate arguments
10// and/or return value before IRTranslator. Information about the original
11// signatures is stored in metadata. It is used during call lowering to
12// restore correct SPIR-V types of function arguments and return values.
13// This pass also substitutes some llvm intrinsic calls with calls to newly
14// generated functions (as the Khronos LLVM/SPIR-V Translator does).
15//
16// NOTE: this pass is a module-level one due to the necessity to modify
17// GVs/functions.
18//
19//===----------------------------------------------------------------------===//
20
21#include "SPIRV.h"
22#include "SPIRVTargetMachine.h"
23#include "SPIRVUtils.h"
25#include "llvm/IR/IRBuilder.h"
27#include "llvm/IR/Intrinsics.h"
28#include "llvm/IR/IntrinsicsSPIRV.h"
31
32using namespace llvm;
33
34namespace llvm {
36}
37
38namespace {
39
40class SPIRVPrepareFunctions : public ModulePass {
41 bool substituteIntrinsicCalls(Function *F);
42 Function *removeAggregateTypesFromSignature(Function *F);
43
44public:
45 static char ID;
46 SPIRVPrepareFunctions() : ModulePass(ID) {
48 }
49
50 bool runOnModule(Module &M) override;
51
52 StringRef getPassName() const override { return "SPIRV prepare functions"; }
53
54 void getAnalysisUsage(AnalysisUsage &AU) const override {
56 }
57};
58
59} // namespace
60
61char SPIRVPrepareFunctions::ID = 0;
62
63INITIALIZE_PASS(SPIRVPrepareFunctions, "prepare-functions",
64 "SPIRV prepare functions", false, false)
65
66std::string lowerLLVMIntrinsicName(IntrinsicInst *II) {
67 Function *IntrinsicFunc = II->getCalledFunction();
68 assert(IntrinsicFunc && "Missing function");
69 std::string FuncName = IntrinsicFunc->getName().str();
70 std::replace(FuncName.begin(), FuncName.end(), '.', '_');
71 FuncName = "spirv." + FuncName;
72 return FuncName;
73}
74
76 ArrayRef<Type *> ArgTypes,
78 FunctionType *FT = FunctionType::get(RetTy, ArgTypes, false);
79 Function *F = M->getFunction(Name);
80 if (F && F->getFunctionType() == FT)
81 return F;
83 if (F)
84 NewF->setDSOLocal(F->isDSOLocal());
86 return NewF;
87}
88
89static bool lowerIntrinsicToFunction(IntrinsicInst *Intrinsic) {
90 // For @llvm.memset.* intrinsic cases with constant value and length arguments
91 // are emulated via "storing" a constant array to the destination. For other
92 // cases we wrap the intrinsic in @spirv.llvm_memset_* function and expand the
93 // intrinsic to a loop via expandMemSetAsLoop().
94 if (auto *MSI = dyn_cast<MemSetInst>(Intrinsic))
95 if (isa<Constant>(MSI->getValue()) && isa<ConstantInt>(MSI->getLength()))
96 return false; // It is handled later using OpCopyMemorySized.
97
98 Module *M = Intrinsic->getModule();
99 std::string FuncName = lowerLLVMIntrinsicName(Intrinsic);
100 if (Intrinsic->isVolatile())
101 FuncName += ".volatile";
102 // Redirect @llvm.intrinsic.* call to @spirv.llvm_intrinsic_*
103 Function *F = M->getFunction(FuncName);
104 if (F) {
105 Intrinsic->setCalledFunction(F);
106 return true;
107 }
108 // TODO copy arguments attributes: nocapture writeonly.
109 FunctionCallee FC =
110 M->getOrInsertFunction(FuncName, Intrinsic->getFunctionType());
111 auto IntrinsicID = Intrinsic->getIntrinsicID();
112 Intrinsic->setCalledFunction(FC);
113
114 F = dyn_cast<Function>(FC.getCallee());
115 assert(F && "Callee must be a function");
116
117 switch (IntrinsicID) {
118 case Intrinsic::memset: {
119 auto *MSI = static_cast<MemSetInst *>(Intrinsic);
120 Argument *Dest = F->getArg(0);
121 Argument *Val = F->getArg(1);
122 Argument *Len = F->getArg(2);
123 Argument *IsVolatile = F->getArg(3);
124 Dest->setName("dest");
125 Val->setName("val");
126 Len->setName("len");
127 IsVolatile->setName("isvolatile");
128 BasicBlock *EntryBB = BasicBlock::Create(M->getContext(), "entry", F);
129 IRBuilder<> IRB(EntryBB);
130 auto *MemSet = IRB.CreateMemSet(Dest, Val, Len, MSI->getDestAlign(),
131 MSI->isVolatile());
132 IRB.CreateRetVoid();
133 expandMemSetAsLoop(cast<MemSetInst>(MemSet));
134 MemSet->eraseFromParent();
135 break;
136 }
137 case Intrinsic::bswap: {
138 BasicBlock *EntryBB = BasicBlock::Create(M->getContext(), "entry", F);
139 IRBuilder<> IRB(EntryBB);
140 auto *BSwap = IRB.CreateIntrinsic(Intrinsic::bswap, Intrinsic->getType(),
141 F->getArg(0));
142 IRB.CreateRet(BSwap);
143 IntrinsicLowering IL(M->getDataLayout());
144 IL.LowerIntrinsicCall(BSwap);
145 break;
146 }
147 default:
148 break;
149 }
150 return true;
151}
152
153static void lowerFunnelShifts(IntrinsicInst *FSHIntrinsic) {
154 // Get a separate function - otherwise, we'd have to rework the CFG of the
155 // current one. Then simply replace the intrinsic uses with a call to the new
156 // function.
157 // Generate LLVM IR for i* @spirv.llvm_fsh?_i* (i* %a, i* %b, i* %c)
158 Module *M = FSHIntrinsic->getModule();
159 FunctionType *FSHFuncTy = FSHIntrinsic->getFunctionType();
160 Type *FSHRetTy = FSHFuncTy->getReturnType();
161 const std::string FuncName = lowerLLVMIntrinsicName(FSHIntrinsic);
162 Function *FSHFunc =
163 getOrCreateFunction(M, FSHRetTy, FSHFuncTy->params(), FuncName);
164
165 if (!FSHFunc->empty()) {
166 FSHIntrinsic->setCalledFunction(FSHFunc);
167 return;
168 }
169 BasicBlock *RotateBB = BasicBlock::Create(M->getContext(), "rotate", FSHFunc);
170 IRBuilder<> IRB(RotateBB);
171 Type *Ty = FSHFunc->getReturnType();
172 // Build the actual funnel shift rotate logic.
173 // In the comments, "int" is used interchangeably with "vector of int
174 // elements".
175 FixedVectorType *VectorTy = dyn_cast<FixedVectorType>(Ty);
176 Type *IntTy = VectorTy ? VectorTy->getElementType() : Ty;
177 unsigned BitWidth = IntTy->getIntegerBitWidth();
178 ConstantInt *BitWidthConstant = IRB.getInt({BitWidth, BitWidth});
179 Value *BitWidthForInsts =
180 VectorTy
181 ? IRB.CreateVectorSplat(VectorTy->getNumElements(), BitWidthConstant)
182 : BitWidthConstant;
183 Value *RotateModVal =
184 IRB.CreateURem(/*Rotate*/ FSHFunc->getArg(2), BitWidthForInsts);
185 Value *FirstShift = nullptr, *SecShift = nullptr;
186 if (FSHIntrinsic->getIntrinsicID() == Intrinsic::fshr) {
187 // Shift the less significant number right, the "rotate" number of bits
188 // will be 0-filled on the left as a result of this regular shift.
189 FirstShift = IRB.CreateLShr(FSHFunc->getArg(1), RotateModVal);
190 } else {
191 // Shift the more significant number left, the "rotate" number of bits
192 // will be 0-filled on the right as a result of this regular shift.
193 FirstShift = IRB.CreateShl(FSHFunc->getArg(0), RotateModVal);
194 }
195 // We want the "rotate" number of the more significant int's LSBs (MSBs) to
196 // occupy the leftmost (rightmost) "0 space" left by the previous operation.
197 // Therefore, subtract the "rotate" number from the integer bitsize...
198 Value *SubRotateVal = IRB.CreateSub(BitWidthForInsts, RotateModVal);
199 if (FSHIntrinsic->getIntrinsicID() == Intrinsic::fshr) {
200 // ...and left-shift the more significant int by this number, zero-filling
201 // the LSBs.
202 SecShift = IRB.CreateShl(FSHFunc->getArg(0), SubRotateVal);
203 } else {
204 // ...and right-shift the less significant int by this number, zero-filling
205 // the MSBs.
206 SecShift = IRB.CreateLShr(FSHFunc->getArg(1), SubRotateVal);
207 }
208 // A simple binary addition of the shifted ints yields the final result.
209 IRB.CreateRet(IRB.CreateOr(FirstShift, SecShift));
210
211 FSHIntrinsic->setCalledFunction(FSHFunc);
212}
213
214static void buildUMulWithOverflowFunc(Function *UMulFunc) {
215 // The function body is already created.
216 if (!UMulFunc->empty())
217 return;
218
219 BasicBlock *EntryBB = BasicBlock::Create(UMulFunc->getParent()->getContext(),
220 "entry", UMulFunc);
221 IRBuilder<> IRB(EntryBB);
222 // Build the actual unsigned multiplication logic with the overflow
223 // indication. Do unsigned multiplication Mul = A * B. Then check
224 // if unsigned division Div = Mul / A is not equal to B. If so,
225 // then overflow has happened.
226 Value *Mul = IRB.CreateNUWMul(UMulFunc->getArg(0), UMulFunc->getArg(1));
227 Value *Div = IRB.CreateUDiv(Mul, UMulFunc->getArg(0));
228 Value *Overflow = IRB.CreateICmpNE(UMulFunc->getArg(0), Div);
229
230 // umul.with.overflow intrinsic return a structure, where the first element
231 // is the multiplication result, and the second is an overflow bit.
232 Type *StructTy = UMulFunc->getReturnType();
233 Value *Agg = IRB.CreateInsertValue(PoisonValue::get(StructTy), Mul, {0});
234 Value *Res = IRB.CreateInsertValue(Agg, Overflow, {1});
235 IRB.CreateRet(Res);
236}
237
239 // If we cannot use the SPV_KHR_expect_assume extension, then we need to
240 // ignore the intrinsic and move on. It should be removed later on by LLVM.
241 // Otherwise we should lower the intrinsic to the corresponding SPIR-V
242 // instruction.
243 // For @llvm.assume we have OpAssumeTrueKHR.
244 // For @llvm.expect we have OpExpectKHR.
245 //
246 // We need to lower this into a builtin and then the builtin into a SPIR-V
247 // instruction.
248 if (II->getIntrinsicID() == Intrinsic::assume) {
250 II->getModule(), Intrinsic::SPVIntrinsics::spv_assume);
251 II->setCalledFunction(F);
252 } else if (II->getIntrinsicID() == Intrinsic::expect) {
254 II->getModule(), Intrinsic::SPVIntrinsics::spv_expect,
255 {II->getOperand(0)->getType()});
256 II->setCalledFunction(F);
257 } else {
258 llvm_unreachable("Unknown intrinsic");
259 }
260
261 return;
262}
263
264static void lowerUMulWithOverflow(IntrinsicInst *UMulIntrinsic) {
265 // Get a separate function - otherwise, we'd have to rework the CFG of the
266 // current one. Then simply replace the intrinsic uses with a call to the new
267 // function.
268 Module *M = UMulIntrinsic->getModule();
269 FunctionType *UMulFuncTy = UMulIntrinsic->getFunctionType();
270 Type *FSHLRetTy = UMulFuncTy->getReturnType();
271 const std::string FuncName = lowerLLVMIntrinsicName(UMulIntrinsic);
272 Function *UMulFunc =
273 getOrCreateFunction(M, FSHLRetTy, UMulFuncTy->params(), FuncName);
275 UMulIntrinsic->setCalledFunction(UMulFunc);
276}
277
278// Substitutes calls to LLVM intrinsics with either calls to SPIR-V intrinsics
279// or calls to proper generated functions. Returns True if F was modified.
280bool SPIRVPrepareFunctions::substituteIntrinsicCalls(Function *F) {
281 bool Changed = false;
282 for (BasicBlock &BB : *F) {
283 for (Instruction &I : BB) {
284 auto Call = dyn_cast<CallInst>(&I);
285 if (!Call)
286 continue;
287 Function *CF = Call->getCalledFunction();
288 if (!CF || !CF->isIntrinsic())
289 continue;
290 auto *II = cast<IntrinsicInst>(Call);
291 if (II->getIntrinsicID() == Intrinsic::memset ||
292 II->getIntrinsicID() == Intrinsic::bswap)
293 Changed |= lowerIntrinsicToFunction(II);
294 else if (II->getIntrinsicID() == Intrinsic::fshl ||
295 II->getIntrinsicID() == Intrinsic::fshr) {
297 Changed = true;
298 } else if (II->getIntrinsicID() == Intrinsic::umul_with_overflow) {
300 Changed = true;
301 } else if (II->getIntrinsicID() == Intrinsic::assume ||
302 II->getIntrinsicID() == Intrinsic::expect) {
304 Changed = true;
305 }
306 }
307 }
308 return Changed;
309}
310
311// Returns F if aggregate argument/return types are not present or cloned F
312// function with the types replaced by i32 types. The change in types is
313// noted in 'spv.cloned_funcs' metadata for later restoration.
314Function *
315SPIRVPrepareFunctions::removeAggregateTypesFromSignature(Function *F) {
316 IRBuilder<> B(F->getContext());
317
318 bool IsRetAggr = F->getReturnType()->isAggregateType();
319 bool HasAggrArg =
320 std::any_of(F->arg_begin(), F->arg_end(), [](Argument &Arg) {
321 return Arg.getType()->isAggregateType();
322 });
323 bool DoClone = IsRetAggr || HasAggrArg;
324 if (!DoClone)
325 return F;
326 SmallVector<std::pair<int, Type *>, 4> ChangedTypes;
327 Type *RetType = IsRetAggr ? B.getInt32Ty() : F->getReturnType();
328 if (IsRetAggr)
329 ChangedTypes.push_back(std::pair<int, Type *>(-1, F->getReturnType()));
330 SmallVector<Type *, 4> ArgTypes;
331 for (const auto &Arg : F->args()) {
332 if (Arg.getType()->isAggregateType()) {
333 ArgTypes.push_back(B.getInt32Ty());
334 ChangedTypes.push_back(
335 std::pair<int, Type *>(Arg.getArgNo(), Arg.getType()));
336 } else
337 ArgTypes.push_back(Arg.getType());
338 }
339 FunctionType *NewFTy =
340 FunctionType::get(RetType, ArgTypes, F->getFunctionType()->isVarArg());
341 Function *NewF =
342 Function::Create(NewFTy, F->getLinkage(), F->getName(), *F->getParent());
343
345 auto NewFArgIt = NewF->arg_begin();
346 for (auto &Arg : F->args()) {
347 StringRef ArgName = Arg.getName();
348 NewFArgIt->setName(ArgName);
349 VMap[&Arg] = &(*NewFArgIt++);
350 }
352
353 CloneFunctionInto(NewF, F, VMap, CloneFunctionChangeType::LocalChangesOnly,
354 Returns);
355 NewF->takeName(F);
356
357 NamedMDNode *FuncMD =
358 F->getParent()->getOrInsertNamedMetadata("spv.cloned_funcs");
360 MDArgs.push_back(MDString::get(B.getContext(), NewF->getName()));
361 for (auto &ChangedTyP : ChangedTypes)
362 MDArgs.push_back(MDNode::get(
363 B.getContext(),
364 {ConstantAsMetadata::get(B.getInt32(ChangedTyP.first)),
365 ValueAsMetadata::get(Constant::getNullValue(ChangedTyP.second))}));
366 MDNode *ThisFuncMD = MDNode::get(B.getContext(), MDArgs);
367 FuncMD->addOperand(ThisFuncMD);
368
369 for (auto *U : make_early_inc_range(F->users())) {
370 if (auto *CI = dyn_cast<CallInst>(U))
371 CI->mutateFunctionType(NewF->getFunctionType());
372 U->replaceUsesOfWith(F, NewF);
373 }
374 return NewF;
375}
376
377bool SPIRVPrepareFunctions::runOnModule(Module &M) {
378 bool Changed = false;
379 for (Function &F : M)
380 Changed |= substituteIntrinsicCalls(&F);
381
382 std::vector<Function *> FuncsWorklist;
383 for (auto &F : M)
384 FuncsWorklist.push_back(&F);
385
386 for (auto *F : FuncsWorklist) {
387 Function *NewF = removeAggregateTypesFromSignature(F);
388
389 if (NewF != F) {
390 F->eraseFromParent();
391 Changed = true;
392 }
393 }
394 return Changed;
395}
396
398 return new SPIRVPrepareFunctions();
399}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
return RetTy
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void lowerFunnelShifts(IntrinsicInst *FSHIntrinsic)
static bool lowerIntrinsicToFunction(IntrinsicInst *Intrinsic)
static void lowerUMulWithOverflow(IntrinsicInst *UMulIntrinsic)
static void lowerExpectAssume(IntrinsicInst *II)
static void buildUMulWithOverflowFunc(Function *UMulFunc)
static Function * getOrCreateFunction(Module *M, Type *RetTy, ArrayRef< Type * > ArgTypes, StringRef Name)
BinaryOperator * Mul
Represent the analysis usage information of a pass.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:105
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1270
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1451
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:536
unsigned getNumElements() const
Definition: DerivedTypes.h:579
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:138
bool empty() const
Definition: Function.h:769
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:176
arg_iterator arg_begin()
Definition: Function.h:778
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:211
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:181
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:243
Argument * getArg(unsigned i) const
Definition: Function.h:796
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
void setDSOLocal(bool Local)
Definition: GlobalValue.h:299
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1365
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:2482
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.cpp:1223
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Definition: IRBuilder.cpp:941
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
Definition: IRBuilder.h:586
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1428
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:1086
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1369
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2204
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1335
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1407
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:1081
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1488
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:488
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1395
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2625
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:71
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:54
void LowerIntrinsicCall(CallInst *CI)
Replace a call to the specified intrinsic function.
Metadata node.
Definition: Metadata.h:950
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1416
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:499
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
A tuple of MDNodes.
Definition: Metadata.h:1604
void addOperand(MDNode *M)
Definition: Metadata.cpp:1287
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1743
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getIntegerBitWidth() const
LLVM Value Representation.
Definition: Value.h:74
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:378
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:384
Type * getElementType() const
Definition: DerivedTypes.h:433
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
Definition: CallingConv.h:135
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1422
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeSPIRVPrepareFunctionsPass(PassRegistry &)
ModulePass * createSPIRVPrepareFunctionsPass()
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...
Definition: STLExtras.h:666
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:184
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.
void expandMemSetAsLoop(MemSetInst *MemSet)
Expand MemSet as a loop. MemSet is not deleted.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858