LLVM 24.0.0git
AMDGPUEmitPrintf.cpp
Go to the documentation of this file.
1//===- AMDGPUEmitPrintf.cpp -----------------------------------------------===//
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// Utility function to lower a printf call into a series of device
10// library calls on the AMDGPU target.
11//
12// WARNING: This file knows about certain library functions. It recognizes them
13// by name, and hardwires knowledge of their semantics.
14//
15//===----------------------------------------------------------------------===//
16
21#include "llvm/IR/Module.h"
24#include "llvm/Support/MD5.h"
26
27using namespace llvm;
28
29#define DEBUG_TYPE "amdgpu-emit-printf"
30
31static Value *fitArgInto64Bits(IRBuilder<> &Builder, Value *Arg) {
32 auto Int64Ty = Builder.getInt64Ty();
33 auto Ty = Arg->getType();
34
35 if (auto IntTy = dyn_cast<IntegerType>(Ty)) {
36 switch (IntTy->getBitWidth()) {
37 case 32:
38 return Builder.CreateZExt(Arg, Int64Ty);
39 case 64:
40 return Arg;
41 }
42 }
43
44 if (Ty->getTypeID() == Type::DoubleTyID) {
45 return Builder.CreateBitCast(Arg, Int64Ty);
46 }
47
48 if (isa<PointerType>(Ty)) {
49 return Builder.CreatePtrToInt(Arg, Int64Ty);
50 }
51
52 llvm_unreachable("unexpected type");
53}
54
55static Value *callPrintfBegin(IRBuilder<> &Builder, Value *Version) {
56 auto Int64Ty = Builder.getInt64Ty();
57 auto M = Builder.getModule();
58 auto Fn = M->getOrInsertFunction("__ockl_printf_begin", Int64Ty, Int64Ty);
59 return Builder.CreateCall(Fn, Version);
60}
61
62static Value *callAppendArgs(IRBuilder<> &Builder, Value *Desc, int NumArgs,
63 Value *Arg0, Value *Arg1, Value *Arg2, Value *Arg3,
64 Value *Arg4, Value *Arg5, Value *Arg6,
65 bool IsLast) {
66 auto Int64Ty = Builder.getInt64Ty();
67 auto Int32Ty = Builder.getInt32Ty();
68 auto M = Builder.getModule();
69 auto Fn = M->getOrInsertFunction("__ockl_printf_append_args", Int64Ty,
70 Int64Ty, Int32Ty, Int64Ty, Int64Ty, Int64Ty,
71 Int64Ty, Int64Ty, Int64Ty, Int64Ty, Int32Ty);
72 auto IsLastValue = Builder.getInt32(IsLast);
73 auto NumArgsValue = Builder.getInt32(NumArgs);
74 return Builder.CreateCall(Fn, {Desc, NumArgsValue, Arg0, Arg1, Arg2, Arg3,
75 Arg4, Arg5, Arg6, IsLastValue});
76}
77
78static Value *appendArg(IRBuilder<> &Builder, Value *Desc, Value *Arg,
79 bool IsLast) {
80 auto Arg0 = fitArgInto64Bits(Builder, Arg);
81 auto Zero = Builder.getInt64(0);
82 return callAppendArgs(Builder, Desc, 1, Arg0, Zero, Zero, Zero, Zero, Zero,
83 Zero, IsLast);
84}
85
86// The device library does not provide strlen, so we build our own loop
87// here. While we are at it, we also include the terminating null in the length.
88static Value *getStrlenWithNull(IRBuilder<> &Builder, Value *Str) {
89 auto *Prev = Builder.GetInsertBlock();
90 Module *M = Prev->getModule();
91
92 auto CharZero = Builder.getInt8(0);
93 auto One = Builder.getInt64(1);
94 auto Zero = Builder.getInt64(0);
95 auto Int64Ty = Builder.getInt64Ty();
96
97 // The length is either zero for a null pointer, or the computed value for an
98 // actual string. We need a join block for a phi that represents the final
99 // value.
100 //
101 // Strictly speaking, the zero does not matter since
102 // __ockl_printf_append_string_n ignores the length if the pointer is null.
103 BasicBlock *Join = nullptr;
104 if (Prev->hasTerminator()) {
105 Join = Prev->splitBasicBlock(Builder.GetInsertPoint(),
106 "strlen.join");
108 } else {
109 Join = BasicBlock::Create(M->getContext(), "strlen.join",
110 Prev->getParent());
111 }
112 BasicBlock *While =
113 BasicBlock::Create(M->getContext(), "strlen.while",
114 Prev->getParent(), Join);
115 BasicBlock *WhileDone = BasicBlock::Create(
116 M->getContext(), "strlen.while.done",
117 Prev->getParent(), Join);
118
119 // Emit an early return for when the pointer is null.
120 Builder.SetInsertPoint(Prev);
121 auto CmpNull =
122 Builder.CreateICmpEQ(Str, Constant::getNullValue(Str->getType()));
123 Builder.CreateCondBr(CmpNull, Join, While);
124
125 // Entry to the while loop.
126 Builder.SetInsertPoint(While);
127
128 auto PtrPhi = Builder.CreatePHI(Str->getType(), 2);
129 PtrPhi->addIncoming(Str, Prev);
130 auto PtrNext = Builder.CreateGEP(Builder.getInt8Ty(), PtrPhi, One);
131 PtrPhi->addIncoming(PtrNext, While);
132
133 // Condition for the while loop.
134 auto Data = Builder.CreateLoad(Builder.getInt8Ty(), PtrPhi);
135 auto Cmp = Builder.CreateICmpEQ(Data, CharZero);
136 Builder.CreateCondBr(Cmp, WhileDone, While);
137
138 // Add one to the computed length.
139 Builder.SetInsertPoint(WhileDone->begin());
140 auto Len = Builder.CreatePtrDiff(PtrPhi, Str);
141 Len = Builder.CreateZExt(Len, Int64Ty);
142 Len = Builder.CreateAdd(Len, One);
143
144 // Final join.
145 UncondBrInst::Create(Join, WhileDone);
146 Builder.SetInsertPoint(Join->begin());
147 auto LenPhi = Builder.CreatePHI(Len->getType(), 2);
148 LenPhi->addIncoming(Len, WhileDone);
149 LenPhi->addIncoming(Zero, Prev);
150
151 return LenPhi;
152}
153
155 Value *Length, bool isLast) {
156 auto Int64Ty = Builder.getInt64Ty();
157 auto IsLastInt32 = Builder.getInt32(isLast);
158 auto M = Builder.getModule();
159 auto Fn = M->getOrInsertFunction("__ockl_printf_append_string_n", Int64Ty,
160 Desc->getType(), Str->getType(),
161 Length->getType(), IsLastInt32->getType());
162 return Builder.CreateCall(Fn, {Desc, Str, Length, IsLastInt32});
163}
164
165static Value *appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg,
166 bool IsLast) {
167 auto Length = getStrlenWithNull(Builder, Arg);
168 return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
169}
170
171static Value *processArg(IRBuilder<> &Builder, Value *Desc, Value *Arg,
172 bool SpecIsCString, bool IsLast) {
173 if (SpecIsCString && isa<PointerType>(Arg->getType())) {
174 return appendString(Builder, Desc, Arg, IsLast);
175 }
176 // If the format specifies a string but the argument is not, the frontend will
177 // have printed a warning. We just rely on undefined behaviour and send the
178 // argument anyway.
179 return appendArg(Builder, Desc, Arg, IsLast);
180}
181
182// Scan the format string to locate all specifiers, and mark the ones that
183// specify a string, i.e, the "%s" specifier with optional '*' characters.
185 static const char ConvSpecifiers[] = "diouxXfFeEgGaAcspn";
186 // Skip the first argument, the format string.
187 unsigned ArgIdx = 1;
188
189 size_t SpecPos;
190 while ((SpecPos = Str.find('%')) != StringRef::npos) {
191 Str = Str.drop_front(SpecPos + 1);
192 // "%%" prints a '%' and takes no argument.
193 if (Str.consume_front("%"))
194 continue;
195 size_t SpecEnd = Str.find_first_of(ConvSpecifiers);
196 if (SpecEnd == StringRef::npos)
197 return;
198 // Each '*' in the specifier takes an argument of its own.
199 ArgIdx += Str.take_front(SpecEnd).count('*');
200 if (Str[SpecEnd] == 's')
201 BV.set(ArgIdx);
202 Str = Str.drop_front(SpecEnd + 1);
203 ++ArgIdx;
204 }
205}
206
208 MD5 Hasher;
209 MD5::MD5Result Hash;
210 Hasher.update(Fmt);
211 Hasher.final(Hash);
212 return Hash.low();
213}
214
216 // Try sticking to llvm.printf.fmts format, although we are not going to
217 // use the ID and argument size fields while printing,
218 return "0:0:" +
219 llvm::utohexstr(getAMDGPUPrintfFormatHash(Fmt), /*LowerCase=*/true) +
220 "," + Fmt.str();
221}
222
225 std::string Str(S.str() + '\0');
226
227 DataExtractor Extractor(Str, /*IsLittleEndian=*/true);
229 while (Offset && Offset.tell() < Str.size()) {
230 const uint64_t ReadSize = 4;
231 uint64_t ReadNow = std::min(ReadSize, Str.size() - Offset.tell());
232 uint64_t ReadBytes = 0;
233 switch (ReadNow) {
234 default:
235 llvm_unreachable("min(4, X) > 4?");
236 case 1:
237 ReadBytes = Extractor.getU8(Offset);
238 break;
239 case 2:
240 ReadBytes = Extractor.getU16(Offset);
241 break;
242 case 3:
243 ReadBytes = Extractor.getU24(Offset);
244 break;
245 case 4:
246 ReadBytes = Extractor.getU32(Offset);
247 break;
248 }
249 cantFail(Offset.takeError(), "failed to read bytes from constant array");
250 Words.push_back(static_cast<uint32_t>(ReadBytes));
251 }
252 // Additional padding for 8 byte alignment
253 int Rem = (Str.size() % 8);
254 if (Rem > 0 && Rem <= 4)
255 Words.push_back(0);
256}
257
258// helper struct to package the string related data
261 Value *RealSize = nullptr;
262 Value *AlignedSize = nullptr;
263 bool IsConst = true;
264
265 StringData(StringRef ST, Value *RS, Value *AS, bool IC)
266 : Str(ST), RealSize(RS), AlignedSize(AS), IsConst(IC) {}
267};
268
269// Calculates frame size required for current printf expansion and allocates
270// space on printf buffer. Printf frame includes following contents
271// [ ControlDWord , format string/Hash , Arguments (each aligned to 8 byte) ]
273 IRBuilder<> &Builder, ArrayRef<Value *> Args, Value *Fmt,
274 bool isConstFmtStr, SparseBitVector<8> &SpecIsCString,
275 SmallVectorImpl<StringData> &StringContents, Value *&ArgSize) {
276 Module *M = Builder.getModule();
277 Value *NonConstStrLen = nullptr;
278 Value *LenWithNull = nullptr;
279 Value *LenWithNullAligned = nullptr;
280 Value *TempAdd = nullptr;
281
282 // First 4 bytes to be reserved for control dword
283 size_t BufSize = 4;
284 if (isConstFmtStr)
285 // First 8 bytes of MD5 hash
286 BufSize += 8;
287 else {
288 LenWithNull = getStrlenWithNull(Builder, Fmt);
289
290 // Align the computed length to next 8 byte boundary
291 TempAdd = Builder.CreateAdd(LenWithNull,
292 ConstantInt::get(LenWithNull->getType(), 7U));
293 NonConstStrLen = Builder.CreateAnd(
294 TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
295
296 StringContents.push_back(
297 StringData(StringRef(), LenWithNull, NonConstStrLen, false));
298 }
299
300 for (size_t i = 1; i < Args.size(); i++) {
301 if (SpecIsCString.test(i)) {
302 StringRef ArgStr;
303 if (getConstantStringInfo(Args[i], ArgStr)) {
304 auto alignedLen = alignTo(ArgStr.size() + 1, 8);
305 StringContents.push_back(StringData(
306 ArgStr,
307 /*RealSize*/ nullptr, /*AlignedSize*/ nullptr, /*IsConst*/ true));
308 BufSize += alignedLen;
309 } else {
310 LenWithNull = getStrlenWithNull(Builder, Args[i]);
311
312 // Align the computed length to next 8 byte boundary
313 TempAdd = Builder.CreateAdd(
314 LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
315 LenWithNullAligned = Builder.CreateAnd(
316 TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
317
318 if (NonConstStrLen) {
319 auto Val = Builder.CreateAdd(LenWithNullAligned, NonConstStrLen,
320 "cumulativeAdd");
321 NonConstStrLen = Val;
322 } else
323 NonConstStrLen = LenWithNullAligned;
324
325 StringContents.push_back(
326 StringData(StringRef(), LenWithNull, LenWithNullAligned, false));
327 }
328 } else {
329 int AllocSize = M->getDataLayout().getTypeAllocSize(Args[i]->getType());
330 // We end up expanding non string arguments to 8 bytes
331 // (args smaller than 8 bytes)
332 BufSize += std::max(AllocSize, 8);
333 }
334 }
335
336 // calculate final size value to be passed to printf_alloc
337 Value *SizeToReserve = ConstantInt::get(Builder.getInt64Ty(), BufSize, false);
338 SmallVector<Value *, 1> Alloc_args;
339 if (NonConstStrLen)
340 SizeToReserve = Builder.CreateAdd(NonConstStrLen, SizeToReserve);
341
342 ArgSize = Builder.CreateTrunc(SizeToReserve, Builder.getInt32Ty());
343 Alloc_args.push_back(ArgSize);
344
345 // call the printf_alloc function
346 AttributeList Attr = AttributeList::get(
347 Builder.getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind);
348
349 Type *Tys_alloc[1] = {Builder.getInt32Ty()};
350 Type *PtrTy =
351 Builder.getPtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
352 FunctionType *FTy_alloc = FunctionType::get(PtrTy, Tys_alloc, false);
353 auto PrintfAllocFn =
354 M->getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);
355
356 return Builder.CreateCall(PrintfAllocFn, Alloc_args, "printf_alloc_fn");
357}
358
359// Prepare constant string argument to push onto the buffer
361 SmallVectorImpl<Value *> &WhatToStore) {
364 for (uint32_t Word : Words)
365 WhatToStore.push_back(Builder.getInt32(Word));
366}
367
369 const DataLayout &DL = Builder.getDataLayout();
370 auto Ty = Arg->getType();
371
372 if (auto IntTy = dyn_cast<IntegerType>(Ty)) {
373 if (IntTy->getBitWidth() < 64) {
374 return Builder.CreateZExt(Arg, Builder.getInt64Ty());
375 }
376 }
377
378 if (Ty->isFloatingPointTy()) {
379 if (DL.getTypeAllocSize(Ty) < 8) {
380 return Builder.CreateFPExt(Arg, Builder.getDoubleTy());
381 }
382 }
383
384 return Arg;
385}
386
387static void
389 Value *PtrToStore, SparseBitVector<8> &SpecIsCString,
390 SmallVectorImpl<StringData> &StringContents,
391 bool IsConstFmtStr) {
392 Module *M = Builder.getModule();
393 const DataLayout &DL = M->getDataLayout();
394 auto StrIt = StringContents.begin();
395 size_t i = IsConstFmtStr ? 1 : 0;
396 for (; i < Args.size(); i++) {
397 SmallVector<Value *, 32> WhatToStore;
398 if ((i == 0) || SpecIsCString.test(i)) {
399 if (StrIt->IsConst) {
400 processConstantStringArg(StrIt, Builder, WhatToStore);
401 StrIt++;
402 } else {
403 // This copies the contents of the string, however the next offset
404 // is at aligned length, the extra space that might be created due
405 // to alignment padding is not populated with any specific value
406 // here. This would be safe as long as runtime is sync with
407 // the offsets.
408 Builder.CreateMemCpy(PtrToStore, /*DstAlign*/ Align(1), Args[i],
409 /*SrcAlign*/ Args[i]->getPointerAlignment(DL),
410 StrIt->RealSize);
411
412 PtrToStore =
413 Builder.CreateInBoundsGEP(Builder.getInt8Ty(), PtrToStore,
414 {StrIt->AlignedSize}, "PrintBuffNextPtr");
415 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:"
416 << *PtrToStore << '\n');
417
418 // done with current argument, move to next
419 StrIt++;
420 continue;
421 }
422 } else {
423 WhatToStore.push_back(processNonStringArg(Args[i], Builder));
424 }
425
426 for (Value *toStore : WhatToStore) {
427 StoreInst *StBuff = Builder.CreateStore(toStore, PtrToStore);
428 LLVM_DEBUG(dbgs() << "inserting store to printf buffer:" << *StBuff
429 << '\n');
430 (void)StBuff;
431 PtrToStore = Builder.CreateConstInBoundsGEP1_32(
432 Builder.getInt8Ty(), PtrToStore,
433 M->getDataLayout().getTypeAllocSize(toStore->getType()),
434 "PrintBuffNextPtr");
435 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:" << *PtrToStore
436 << '\n');
437 }
438 }
439}
440
442 bool IsBuffered) {
443 auto NumOps = Args.size();
444 assert(NumOps >= 1);
445
446 auto Fmt = Args[0];
447 SparseBitVector<8> SpecIsCString;
448 StringRef FmtStr;
449
450 if (getConstantStringInfo(Fmt, FmtStr))
451 locateAMDGPUPrintfCStrings(SpecIsCString, FmtStr);
452
453 if (IsBuffered) {
454 SmallVector<StringData, 8> StringContents;
455 Module *M = Builder.getModule();
456 LLVMContext &Ctx = Builder.getContext();
457 auto Int8Ty = Builder.getInt8Ty();
458 auto Int32Ty = Builder.getInt32Ty();
459 bool IsConstFmtStr = !FmtStr.empty();
460
461 Value *ArgSize = nullptr;
462 Value *Ptr =
463 callBufferedPrintfStart(Builder, Args, Fmt, IsConstFmtStr,
464 SpecIsCString, StringContents, ArgSize);
465
466 // The buffered version still follows OpenCL printf standards for
467 // printf return value, i.e 0 on success, -1 on failure.
468 ConstantPointerNull *zeroIntPtr =
470
471 auto *Cmp = cast<ICmpInst>(Builder.CreateICmpNE(Ptr, zeroIntPtr, ""));
472
473 BasicBlock *End = BasicBlock::Create(Ctx, "end.block",
474 Builder.GetInsertBlock()->getParent());
476 Ctx, "argpush.block", Builder.GetInsertBlock()->getParent());
477
478 CondBrInst::Create(Cmp, ArgPush, End, Builder.GetInsertBlock());
479 Builder.SetInsertPoint(ArgPush);
480
481 // Create controlDWord and store as the first entry, format as follows
482 // Bit 0 (LSB) -> stream (1 if stderr, 0 if stdout, printf always outputs to
483 // stdout) Bit 1 -> constant format string (1 if constant) Bits 2-31 -> size
484 // of printf data frame
485 auto ConstantTwo = Builder.getInt32(2);
486 auto ControlDWord = Builder.CreateShl(ArgSize, ConstantTwo);
487 if (IsConstFmtStr)
488 ControlDWord = Builder.CreateOr(ControlDWord, ConstantTwo);
489
490 Builder.CreateStore(ControlDWord, Ptr);
491
492 Ptr = Builder.CreateConstInBoundsGEP1_32(Int8Ty, Ptr, 4);
493
494 // Create MD5 hash for constant format string, push low 64 bits of the
495 // same onto buffer and metadata.
496 NamedMDNode *metaD = M->getOrInsertNamedMetadata("llvm.printf.fmts");
497 if (IsConstFmtStr) {
498 MDString *fmtStrArray =
500 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
501 metaD->addOperand(myMD);
502
503 Builder.CreateStore(Builder.getInt64(getAMDGPUPrintfFormatHash(FmtStr)),
504 Ptr);
505 Ptr = Builder.CreateConstInBoundsGEP1_32(Int8Ty, Ptr, 8);
506 } else {
507 // Include a dummy metadata instance in case of only non constant
508 // format string usage, This might be an absurd usecase but needs to
509 // be done for completeness
510 if (metaD->getNumOperands() == 0) {
511 MDString *fmtStrArray =
513 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
514 metaD->addOperand(myMD);
515 }
516 }
517
518 // Push The printf arguments onto buffer
519 callBufferedPrintfArgPush(Builder, Args, Ptr, SpecIsCString, StringContents,
520 IsConstFmtStr);
521
522 // End block, returns -1 on failure
523 UncondBrInst::Create(End, ArgPush);
524 Builder.SetInsertPoint(End);
525 return Builder.CreateSExt(Builder.CreateNot(Cmp), Int32Ty, "printf_result");
526 }
527
528 auto Desc = callPrintfBegin(Builder, Builder.getIntN(64, 0));
529 Desc = appendString(Builder, Desc, Fmt, NumOps == 1);
530
531 // FIXME: This invokes hostcall once for each argument. We can pack up to
532 // seven scalar printf arguments in a single hostcall. See the signature of
533 // callAppendArgs().
534 for (unsigned int i = 1; i != NumOps; ++i) {
535 bool IsLast = i == NumOps - 1;
536 bool IsCString = SpecIsCString.test(i);
537 Desc = processArg(Builder, Desc, Args[i], IsCString, IsLast);
538 }
539
540 return Builder.CreateTrunc(Desc, Builder.getInt32Ty());
541}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Value * appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg, bool IsLast)
static void callBufferedPrintfArgPush(IRBuilder<> &Builder, ArrayRef< Value * > Args, Value *PtrToStore, SparseBitVector< 8 > &SpecIsCString, SmallVectorImpl< StringData > &StringContents, bool IsConstFmtStr)
static void processConstantStringArg(StringData *SD, IRBuilder<> &Builder, SmallVectorImpl< Value * > &WhatToStore)
static Value * callBufferedPrintfStart(IRBuilder<> &Builder, ArrayRef< Value * > Args, Value *Fmt, bool isConstFmtStr, SparseBitVector< 8 > &SpecIsCString, SmallVectorImpl< StringData > &StringContents, Value *&ArgSize)
static Value * callAppendArgs(IRBuilder<> &Builder, Value *Desc, int NumArgs, Value *Arg0, Value *Arg1, Value *Arg2, Value *Arg3, Value *Arg4, Value *Arg5, Value *Arg6, bool IsLast)
static Value * callPrintfBegin(IRBuilder<> &Builder, Value *Version)
static Value * fitArgInto64Bits(IRBuilder<> &Builder, Value *Arg)
static Value * callAppendStringN(IRBuilder<> &Builder, Value *Desc, Value *Str, Value *Length, bool isLast)
static Value * appendArg(IRBuilder<> &Builder, Value *Desc, Value *Arg, bool IsLast)
static Value * processNonStringArg(Value *Arg, IRBuilder<> &Builder)
static Value * processArg(IRBuilder<> &Builder, Value *Desc, Value *Arg, bool SpecIsCString, bool IsLast)
static Value * getStrlenWithNull(IRBuilder<> &Builder, Value *Str)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Module.h This file contains the declarations for the Module class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
This file defines the SparseBitVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:440
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
static CondBrInst * Create(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse, InsertPosition InsertBefore=nullptr)
A constant pointer value that points to null.
Definition Constants.h:716
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2947
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition MD5.cpp:188
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition MD5.cpp:233
Metadata node.
Definition Metadata.h:1081
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
A single uniqued string.
Definition Metadata.h:733
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:597
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A tuple of MDNodes.
Definition Metadata.h:1797
LLVM_ABI unsigned getNumOperands() const
LLVM_ABI void addOperand(MDNode *M)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void set(unsigned Idx)
bool test(unsigned Idx) const
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
LLVM_ABI std::string getAMDGPUPrintfFormatMetadata(StringRef Fmt)
Returns the llvm.printf.fmts entry that maps the ID of the constant format string Fmt back to the str...
Op::Description Desc
LLVM_ABI Value * emitAMDGPUPrintfCall(IRBuilder<> &Builder, ArrayRef< Value * > Args, bool isBuffered)
LLVM_ABI uint64_t getAMDGPUPrintfFormatHash(StringRef Fmt)
Returns the ID that buffered printf stores in place of the constant format string Fmt the low 64 bits...
LLVM_ABI void locateAMDGPUPrintfCStrings(SparseBitVector< 8 > &BV, StringRef Fmt)
Marks the printf arguments that the format string Fmt specifies as strings, i.e.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
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...
Definition Casting.h:547
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
LLVM_ABI void packAMDGPUPrintfConstantString(StringRef Str, SmallVectorImpl< uint32_t > &Words)
Splits the constant string argument Str, including its terminating NUL, into the little-endian 32-bit...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
constexpr StringLiteral AMDGPUPrintfNonConstFormatMetadata
The llvm.printf.fmts entry added when a module only uses buffered printf with non-constant format str...
StringData(StringRef ST, Value *RS, Value *AS, bool IC)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
uint64_t low() const
Definition MD5.h:47