LLVM 17.0.0git
AMDGPUPrintfRuntimeBinding.cpp
Go to the documentation of this file.
1//=== AMDGPUPrintfRuntimeBinding.cpp - OpenCL printf implementation -------===//
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// \file
9//
10// The pass bind printfs to a kernel arg pointer that will be bound to a buffer
11// later by the runtime.
12//
13// This pass traverses the functions in the module and converts
14// each call to printf to a sequence of operations that
15// store the following into the printf buffer:
16// - format string (passed as a module's metadata unique ID)
17// - bitwise copies of printf arguments
18// The backend passes will need to store metadata in the kernel
19//===----------------------------------------------------------------------===//
20
21#include "AMDGPU.h"
26#include "llvm/IR/Dominators.h"
27#include "llvm/IR/IRBuilder.h"
33
34using namespace llvm;
35
36#define DEBUG_TYPE "printfToRuntime"
37#define DWORD_ALIGN 4
38
39namespace {
40class AMDGPUPrintfRuntimeBinding final : public ModulePass {
41
42public:
43 static char ID;
44
45 explicit AMDGPUPrintfRuntimeBinding();
46
47private:
48 bool runOnModule(Module &M) override;
49
50 void getAnalysisUsage(AnalysisUsage &AU) const override {
53 }
54};
55
56class AMDGPUPrintfRuntimeBindingImpl {
57public:
58 AMDGPUPrintfRuntimeBindingImpl(
59 function_ref<const DominatorTree &(Function &)> GetDT,
60 function_ref<const TargetLibraryInfo &(Function &)> GetTLI)
61 : GetDT(GetDT), GetTLI(GetTLI) {}
62 bool run(Module &M);
63
64private:
65 void getConversionSpecifiers(SmallVectorImpl<char> &OpConvSpecifiers,
66 StringRef fmt, size_t num_ops) const;
67
68 bool lowerPrintfForGpu(Module &M);
69
71 const DominatorTree *DT) {
72 return simplifyInstruction(I, {*TD, TLI, DT});
73 }
74
75 const DataLayout *TD;
76 function_ref<const DominatorTree &(Function &)> GetDT;
77 function_ref<const TargetLibraryInfo &(Function &)> GetTLI;
79};
80} // namespace
81
82char AMDGPUPrintfRuntimeBinding::ID = 0;
83
84INITIALIZE_PASS_BEGIN(AMDGPUPrintfRuntimeBinding,
85 "amdgpu-printf-runtime-binding", "AMDGPU Printf lowering",
86 false, false)
89INITIALIZE_PASS_END(AMDGPUPrintfRuntimeBinding, "amdgpu-printf-runtime-binding",
91
92char &llvm::AMDGPUPrintfRuntimeBindingID = AMDGPUPrintfRuntimeBinding::ID;
93
94namespace llvm {
96 return new AMDGPUPrintfRuntimeBinding();
97}
98} // namespace llvm
99
100AMDGPUPrintfRuntimeBinding::AMDGPUPrintfRuntimeBinding() : ModulePass(ID) {
102}
103
104void AMDGPUPrintfRuntimeBindingImpl::getConversionSpecifiers(
105 SmallVectorImpl<char> &OpConvSpecifiers, StringRef Fmt,
106 size_t NumOps) const {
107 // not all format characters are collected.
108 // At this time the format characters of interest
109 // are %p and %s, which use to know if we
110 // are either storing a literal string or a
111 // pointer to the printf buffer.
112 static const char ConvSpecifiers[] = "cdieEfgGaosuxXp";
113 size_t CurFmtSpecifierIdx = 0;
114 size_t PrevFmtSpecifierIdx = 0;
115
116 while ((CurFmtSpecifierIdx = Fmt.find_first_of(
117 ConvSpecifiers, CurFmtSpecifierIdx)) != StringRef::npos) {
118 bool ArgDump = false;
119 StringRef CurFmt = Fmt.substr(PrevFmtSpecifierIdx,
120 CurFmtSpecifierIdx - PrevFmtSpecifierIdx);
121 size_t pTag = CurFmt.find_last_of("%");
122 if (pTag != StringRef::npos) {
123 ArgDump = true;
124 while (pTag && CurFmt[--pTag] == '%') {
125 ArgDump = !ArgDump;
126 }
127 }
128
129 if (ArgDump)
130 OpConvSpecifiers.push_back(Fmt[CurFmtSpecifierIdx]);
131
132 PrevFmtSpecifierIdx = ++CurFmtSpecifierIdx;
133 }
134}
135
136static bool shouldPrintAsStr(char Specifier, Type *OpType) {
137 return Specifier == 's' && isa<PointerType>(OpType);
138}
139
141static_assert(NonLiteralStr.size() == 3);
142
144 StringRef S;
145 if (!getConstantStringInfo(V, S))
146 S = NonLiteralStr;
147
148 return S;
149}
150
151static void diagnoseInvalidFormatString(const CallBase *CI) {
152 DiagnosticInfoUnsupported UnsupportedFormatStr(
153 *CI->getParent()->getParent(),
154 "printf format string must be a trivially resolved constant string "
155 "global variable",
156 CI->getDebugLoc());
157 CI->getContext().diagnose(UnsupportedFormatStr);
158}
159
160bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
161 LLVMContext &Ctx = M.getContext();
162 IRBuilder<> Builder(Ctx);
163 Type *I32Ty = Type::getInt32Ty(Ctx);
164
165 // Instead of creating global variables, the printf format strings are
166 // extracted and passed as metadata. This avoids polluting llvm's symbol
167 // tables in this module. Metadata is going to be extracted by the backend
168 // passes and inserted into the OpenCL binary as appropriate.
169 NamedMDNode *metaD = M.getOrInsertNamedMetadata("llvm.printf.fmts");
170 unsigned UniqID = metaD->getNumOperands();
171
172 for (auto *CI : Printfs) {
173 unsigned NumOps = CI->arg_size();
174
175 SmallString<16> OpConvSpecifiers;
176 Value *Op = CI->getArgOperand(0);
177
178 if (auto LI = dyn_cast<LoadInst>(Op)) {
179 Op = LI->getPointerOperand();
180 for (auto *Use : Op->users()) {
181 if (auto SI = dyn_cast<StoreInst>(Use)) {
182 Op = SI->getValueOperand();
183 break;
184 }
185 }
186 }
187
188 if (auto I = dyn_cast<Instruction>(Op)) {
189 Value *Op_simplified =
190 simplify(I, &GetTLI(*I->getFunction()), &GetDT(*I->getFunction()));
191 if (Op_simplified)
192 Op = Op_simplified;
193 }
194
195 StringRef FormatStr;
196 if (!getConstantStringInfo(Op, FormatStr)) {
197 Value *Stripped = Op->stripPointerCasts();
198 if (!isa<UndefValue>(Stripped) && !isa<ConstantPointerNull>(Stripped))
200 continue;
201 }
202
203 // We need this call to ascertain that we are printing a string or a
204 // pointer. It takes out the specifiers and fills up the first arg.
205 getConversionSpecifiers(OpConvSpecifiers, FormatStr, NumOps - 1);
206
207 // Add metadata for the string
208 std::string AStreamHolder;
209 raw_string_ostream Sizes(AStreamHolder);
210 int Sum = DWORD_ALIGN;
211 Sizes << CI->arg_size() - 1;
212 Sizes << ':';
213 for (unsigned ArgCount = 1;
214 ArgCount < CI->arg_size() && ArgCount <= OpConvSpecifiers.size();
215 ArgCount++) {
216 Value *Arg = CI->getArgOperand(ArgCount);
217 Type *ArgType = Arg->getType();
218 unsigned ArgSize = TD->getTypeAllocSize(ArgType);
219 //
220 // ArgSize by design should be a multiple of DWORD_ALIGN,
221 // expand the arguments that do not follow this rule.
222 //
223 if (ArgSize % DWORD_ALIGN != 0) {
224 Type *ResType = Type::getInt32Ty(Ctx);
225 if (auto *VecType = dyn_cast<VectorType>(ArgType))
226 ResType = VectorType::get(ResType, VecType->getElementCount());
227 Builder.SetInsertPoint(CI);
228 Builder.SetCurrentDebugLocation(CI->getDebugLoc());
229
230 if (ArgType->isFloatingPointTy()) {
231 Arg = Builder.CreateBitCast(
232 Arg,
233 IntegerType::getIntNTy(Ctx, ArgType->getPrimitiveSizeInBits()));
234 }
235
236 if (OpConvSpecifiers[ArgCount - 1] == 'x' ||
237 OpConvSpecifiers[ArgCount - 1] == 'X' ||
238 OpConvSpecifiers[ArgCount - 1] == 'u' ||
239 OpConvSpecifiers[ArgCount - 1] == 'o')
240 Arg = Builder.CreateZExt(Arg, ResType);
241 else
242 Arg = Builder.CreateSExt(Arg, ResType);
243 ArgType = Arg->getType();
244 ArgSize = TD->getTypeAllocSize(ArgType);
245 CI->setOperand(ArgCount, Arg);
246 }
247 if (OpConvSpecifiers[ArgCount - 1] == 'f') {
248 ConstantFP *FpCons = dyn_cast<ConstantFP>(Arg);
249 if (FpCons)
250 ArgSize = 4;
251 else {
252 FPExtInst *FpExt = dyn_cast<FPExtInst>(Arg);
253 if (FpExt && FpExt->getType()->isDoubleTy() &&
254 FpExt->getOperand(0)->getType()->isFloatTy())
255 ArgSize = 4;
256 }
257 }
258 if (shouldPrintAsStr(OpConvSpecifiers[ArgCount - 1], ArgType))
259 ArgSize = alignTo(getAsConstantStr(Arg).size() + 1, 4);
260
261 LLVM_DEBUG(dbgs() << "Printf ArgSize (in buffer) = " << ArgSize
262 << " for type: " << *ArgType << '\n');
263 Sizes << ArgSize << ':';
264 Sum += ArgSize;
265 }
266 LLVM_DEBUG(dbgs() << "Printf format string in source = " << FormatStr
267 << '\n');
268 for (char C : FormatStr) {
269 // Rest of the C escape sequences (e.g. \') are handled correctly
270 // by the MDParser
271 switch (C) {
272 case '\a':
273 Sizes << "\\a";
274 break;
275 case '\b':
276 Sizes << "\\b";
277 break;
278 case '\f':
279 Sizes << "\\f";
280 break;
281 case '\n':
282 Sizes << "\\n";
283 break;
284 case '\r':
285 Sizes << "\\r";
286 break;
287 case '\v':
288 Sizes << "\\v";
289 break;
290 case ':':
291 // ':' cannot be scanned by Flex, as it is defined as a delimiter
292 // Replace it with it's octal representation \72
293 Sizes << "\\72";
294 break;
295 default:
296 Sizes << C;
297 break;
298 }
299 }
300
301 // Insert the printf_alloc call
302 Builder.SetInsertPoint(CI);
303 Builder.SetCurrentDebugLocation(CI->getDebugLoc());
304
306 Attribute::NoUnwind);
307
308 Type *SizetTy = Type::getInt32Ty(Ctx);
309
310 Type *Tys_alloc[1] = {SizetTy};
311 Type *I8Ty = Type::getInt8Ty(Ctx);
312 Type *I8Ptr = PointerType::get(I8Ty, 1);
313 FunctionType *FTy_alloc = FunctionType::get(I8Ptr, Tys_alloc, false);
314 FunctionCallee PrintfAllocFn =
315 M.getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);
316
317 LLVM_DEBUG(dbgs() << "Printf metadata = " << Sizes.str() << '\n');
318 std::string fmtstr = itostr(++UniqID) + ":" + Sizes.str();
319 MDString *fmtStrArray = MDString::get(Ctx, fmtstr);
320
321 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
322 metaD->addOperand(myMD);
323 Value *sumC = ConstantInt::get(SizetTy, Sum, false);
324 SmallVector<Value *, 1> alloc_args;
325 alloc_args.push_back(sumC);
326 CallInst *pcall =
327 CallInst::Create(PrintfAllocFn, alloc_args, "printf_alloc_fn", CI);
328
329 //
330 // Insert code to split basicblock with a
331 // piece of hammock code.
332 // basicblock splits after buffer overflow check
333 //
334 ConstantPointerNull *zeroIntPtr =
335 ConstantPointerNull::get(PointerType::get(I8Ty, 1));
336 auto *cmp = cast<ICmpInst>(Builder.CreateICmpNE(pcall, zeroIntPtr, ""));
337 if (!CI->use_empty()) {
338 Value *result =
339 Builder.CreateSExt(Builder.CreateNot(cmp), I32Ty, "printf_res");
340 CI->replaceAllUsesWith(result);
341 }
342 SplitBlock(CI->getParent(), cmp);
343 Instruction *Brnch =
344 SplitBlockAndInsertIfThen(cmp, cmp->getNextNode(), false);
345
346 Builder.SetInsertPoint(Brnch);
347
348 // store unique printf id in the buffer
349 //
351 I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 0)), "PrintBuffID", Brnch);
352
353 Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS);
354 Value *id_gep_cast =
355 new BitCastInst(BufferIdx, idPointer, "PrintBuffIdCast", Brnch);
356
357 new StoreInst(ConstantInt::get(I32Ty, UniqID), id_gep_cast, Brnch);
358
359 // 1st 4 bytes hold the printf_id
360 // the following GEP is the buffer pointer
361 BufferIdx = GetElementPtrInst::Create(I8Ty, pcall,
362 ConstantInt::get(Ctx, APInt(32, 4)),
363 "PrintBuffGep", Brnch);
364
366 for (unsigned ArgCount = 1;
367 ArgCount < CI->arg_size() && ArgCount <= OpConvSpecifiers.size();
368 ArgCount++) {
369 Value *Arg = CI->getArgOperand(ArgCount);
370 Type *ArgType = Arg->getType();
371 SmallVector<Value *, 32> WhatToStore;
372 if (ArgType->isFPOrFPVectorTy() && !isa<VectorType>(ArgType)) {
373 if (OpConvSpecifiers[ArgCount - 1] == 'f') {
374 if (auto *FpCons = dyn_cast<ConstantFP>(Arg)) {
375 APFloat Val(FpCons->getValueAPF());
376 bool Lost = false;
377 Val.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
378 &Lost);
379 Arg = ConstantFP::get(Ctx, Val);
380 } else if (auto *FpExt = dyn_cast<FPExtInst>(Arg)) {
381 if (FpExt->getType()->isDoubleTy() &&
382 FpExt->getOperand(0)->getType()->isFloatTy()) {
383 Arg = FpExt->getOperand(0);
384 }
385 }
386 }
387 WhatToStore.push_back(Arg);
388 } else if (isa<PointerType>(ArgType)) {
389 if (shouldPrintAsStr(OpConvSpecifiers[ArgCount - 1], ArgType)) {
391 if (!S.empty()) {
392 const uint64_t ReadSize = 4;
393
394 DataExtractor Extractor(S, /*IsLittleEndian=*/true, 8);
396 while (Offset && Offset.tell() < S.size()) {
397 uint64_t ReadNow = std::min(ReadSize, S.size() - Offset.tell());
398 uint64_t ReadBytes = 0;
399 switch (ReadNow) {
400 default: llvm_unreachable("min(4, X) > 4?");
401 case 1:
402 ReadBytes = Extractor.getU8(Offset);
403 break;
404 case 2:
405 ReadBytes = Extractor.getU16(Offset);
406 break;
407 case 3:
408 ReadBytes = Extractor.getU24(Offset);
409 break;
410 case 4:
411 ReadBytes = Extractor.getU32(Offset);
412 break;
413 }
414
415 cantFail(Offset.takeError(),
416 "failed to read bytes from constant array");
417
418 APInt IntVal(8 * ReadSize, ReadBytes);
419
420 // TODO: Should not bothering aligning up.
421 if (ReadNow < ReadSize)
422 IntVal = IntVal.zext(8 * ReadSize);
423
424 Type *IntTy = Type::getIntNTy(Ctx, IntVal.getBitWidth());
425 WhatToStore.push_back(ConstantInt::get(IntTy, IntVal));
426 }
427 } else {
428 // Empty string, give a hint to RT it is no NULL
429 Value *ANumV = ConstantInt::get(Int32Ty, 0xFFFFFF00, false);
430 WhatToStore.push_back(ANumV);
431 }
432 } else {
433 WhatToStore.push_back(Arg);
434 }
435 } else {
436 WhatToStore.push_back(Arg);
437 }
438 for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) {
439 Value *TheBtCast = WhatToStore[I];
440 unsigned ArgSize = TD->getTypeAllocSize(TheBtCast->getType());
441 StoreInst *StBuff = new StoreInst(TheBtCast, BufferIdx, Brnch);
442 LLVM_DEBUG(dbgs() << "inserting store to printf buffer:\n"
443 << *StBuff << '\n');
444 (void)StBuff;
445 if (I + 1 == E && ArgCount + 1 == CI->arg_size())
446 break;
447 BufferIdx = GetElementPtrInst::Create(
448 I8Ty, BufferIdx, {ConstantInt::get(I32Ty, ArgSize)},
449 "PrintBuffNextPtr", Brnch);
450 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n"
451 << *BufferIdx << '\n');
452 }
453 }
454 }
455
456 // erase the printf calls
457 for (auto *CI : Printfs)
458 CI->eraseFromParent();
459
460 Printfs.clear();
461 return true;
462}
463
464bool AMDGPUPrintfRuntimeBindingImpl::run(Module &M) {
465 Triple TT(M.getTargetTriple());
466 if (TT.getArch() == Triple::r600)
467 return false;
468
469 auto PrintfFunction = M.getFunction("printf");
470 if (!PrintfFunction || !PrintfFunction->isDeclaration())
471 return false;
472
473 for (auto &U : PrintfFunction->uses()) {
474 if (auto *CI = dyn_cast<CallInst>(U.getUser())) {
475 if (CI->isCallee(&U))
476 Printfs.push_back(CI);
477 }
478 }
479
480 if (Printfs.empty())
481 return false;
482
483 TD = &M.getDataLayout();
484
485 return lowerPrintfForGpu(M);
486}
487
488bool AMDGPUPrintfRuntimeBinding::runOnModule(Module &M) {
489 auto GetDT = [this](Function &F) -> DominatorTree & {
490 return this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
491 };
492 auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
493 return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
494 };
495
496 return AMDGPUPrintfRuntimeBindingImpl(GetDT, GetTLI).run(M);
497}
498
503 auto GetDT = [&FAM](Function &F) -> DominatorTree & {
505 };
506 auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
508 };
509 bool Changed = AMDGPUPrintfRuntimeBindingImpl(GetDT, GetTLI).run(M);
510 return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
511}
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static void diagnoseInvalidFormatString(const CallBase *CI)
#define DWORD_ALIGN
amdgpu printf runtime AMDGPU Printf lowering
constexpr StringLiteral NonLiteralStr("???")
static StringRef getAsConstantStr(Value *V)
amdgpu printf runtime binding
static bool shouldPrintAsStr(char Specifier, Type *OpType)
assume Assume Builder
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DEBUG(X)
Definition: Debug.h:101
hexagon bit simplify
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
IntegerType * Int32Ty
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
@ SI
Class for arbitrary precision integers.
Definition: APInt.h:75
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
This class represents a no-op cast from one type to another.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1186
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:260
const APFloat & getValueAPF() const
Definition: Constants.h:301
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:927
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
A constant pointer value that points to null.
Definition: Constants.h:538
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1698
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Diagnostic information for unsupported feature in backend.
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:279
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:314
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
This class represents an extension of floating point types.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:940
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:966
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2558
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:933
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:358
const BasicBlock * getParent() const
Definition: Instruction.h:90
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Metadata node.
Definition: Metadata.h:943
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
A single uniqued string.
Definition: Metadata.h:611
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:497
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
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
A tuple of MDNodes.
Definition: Metadata.h:1587
unsigned getNumOperands() const
Definition: Metadata.cpp:1211
void addOperand(MDNode *M)
Definition: Metadata.cpp:1221
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
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
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
An instruction for storing to memory.
Definition: Instructions.h:301
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:840
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:558
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
Definition: StringRef.h:398
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:375
static constexpr size_t npos
Definition: StringRef.h:52
Analysis pass providing the TargetLibraryInfo.
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
Provides information about what library functions are available for the current target.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static IntegerType * getInt8Ty(LLVMContext &C)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:185
static IntegerType * getInt32Ty(LLVMContext &C)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:219
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
Value * getOperand(unsigned i) const
Definition: User.h:169
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
An efficient, type-erasing, non-owning reference to a callable.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
Definition: AMDGPU.h:377
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1777
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.
char & AMDGPUPrintfRuntimeBindingID
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
ModulePass * createAMDGPUPrintfRuntimeBinding()
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:745
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DominatorTree *DT, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
void initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)