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"
23#include "llvm/Support/MD5.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE "amdgpu-emit-printf"
29
30static Value *fitArgInto64Bits(IRBuilder<> &Builder, Value *Arg) {
31 auto Int64Ty = Builder.getInt64Ty();
32 auto Ty = Arg->getType();
33
34 if (auto IntTy = dyn_cast<IntegerType>(Ty)) {
35 switch (IntTy->getBitWidth()) {
36 case 32:
37 return Builder.CreateZExt(Arg, Int64Ty);
38 case 64:
39 return Arg;
40 }
41 }
42
43 if (Ty->getTypeID() == Type::DoubleTyID) {
44 return Builder.CreateBitCast(Arg, Int64Ty);
45 }
46
47 if (isa<PointerType>(Ty)) {
48 return Builder.CreatePtrToInt(Arg, Int64Ty);
49 }
50
51 llvm_unreachable("unexpected type");
52}
53
54static Value *callPrintfBegin(IRBuilder<> &Builder, Value *Version) {
55 auto Int64Ty = Builder.getInt64Ty();
56 auto M = Builder.getModule();
57 auto Fn = M->getOrInsertFunction("__ockl_printf_begin", Int64Ty, Int64Ty);
58 return Builder.CreateCall(Fn, Version);
59}
60
61static Value *callAppendArgs(IRBuilder<> &Builder, Value *Desc, int NumArgs,
62 Value *Arg0, Value *Arg1, Value *Arg2, Value *Arg3,
63 Value *Arg4, Value *Arg5, Value *Arg6,
64 bool IsLast) {
65 auto Int64Ty = Builder.getInt64Ty();
66 auto Int32Ty = Builder.getInt32Ty();
67 auto M = Builder.getModule();
68 auto Fn = M->getOrInsertFunction("__ockl_printf_append_args", Int64Ty,
69 Int64Ty, Int32Ty, Int64Ty, Int64Ty, Int64Ty,
70 Int64Ty, Int64Ty, Int64Ty, Int64Ty, Int32Ty);
71 auto IsLastValue = Builder.getInt32(IsLast);
72 auto NumArgsValue = Builder.getInt32(NumArgs);
73 return Builder.CreateCall(Fn, {Desc, NumArgsValue, Arg0, Arg1, Arg2, Arg3,
74 Arg4, Arg5, Arg6, IsLastValue});
75}
76
77static Value *appendArg(IRBuilder<> &Builder, Value *Desc, Value *Arg,
78 bool IsLast) {
79 auto Arg0 = fitArgInto64Bits(Builder, Arg);
80 auto Zero = Builder.getInt64(0);
81 return callAppendArgs(Builder, Desc, 1, Arg0, Zero, Zero, Zero, Zero, Zero,
82 Zero, IsLast);
83}
84
85// The device library does not provide strlen, so we build our own loop
86// here. While we are at it, we also include the terminating null in the length.
87static Value *getStrlenWithNull(IRBuilder<> &Builder, Value *Str) {
88 auto *Prev = Builder.GetInsertBlock();
89 Module *M = Prev->getModule();
90
91 auto CharZero = Builder.getInt8(0);
92 auto One = Builder.getInt64(1);
93 auto Zero = Builder.getInt64(0);
94 auto Int64Ty = Builder.getInt64Ty();
95
96 // The length is either zero for a null pointer, or the computed value for an
97 // actual string. We need a join block for a phi that represents the final
98 // value.
99 //
100 // Strictly speaking, the zero does not matter since
101 // __ockl_printf_append_string_n ignores the length if the pointer is null.
102 BasicBlock *Join = nullptr;
103 if (Prev->hasTerminator()) {
104 Join = Prev->splitBasicBlock(Builder.GetInsertPoint(),
105 "strlen.join");
107 } else {
108 Join = BasicBlock::Create(M->getContext(), "strlen.join",
109 Prev->getParent());
110 }
111 BasicBlock *While =
112 BasicBlock::Create(M->getContext(), "strlen.while",
113 Prev->getParent(), Join);
114 BasicBlock *WhileDone = BasicBlock::Create(
115 M->getContext(), "strlen.while.done",
116 Prev->getParent(), Join);
117
118 // Emit an early return for when the pointer is null.
119 Builder.SetInsertPoint(Prev);
120 auto CmpNull =
121 Builder.CreateICmpEQ(Str, Constant::getNullValue(Str->getType()));
122 Builder.CreateCondBr(CmpNull, Join, While);
123
124 // Entry to the while loop.
125 Builder.SetInsertPoint(While);
126
127 auto PtrPhi = Builder.CreatePHI(Str->getType(), 2);
128 PtrPhi->addIncoming(Str, Prev);
129 auto PtrNext = Builder.CreateGEP(Builder.getInt8Ty(), PtrPhi, One);
130 PtrPhi->addIncoming(PtrNext, While);
131
132 // Condition for the while loop.
133 auto Data = Builder.CreateLoad(Builder.getInt8Ty(), PtrPhi);
134 auto Cmp = Builder.CreateICmpEQ(Data, CharZero);
135 Builder.CreateCondBr(Cmp, WhileDone, While);
136
137 // Add one to the computed length.
138 Builder.SetInsertPoint(WhileDone->begin());
139 auto Len = Builder.CreatePtrDiff(PtrPhi, Str);
140 Len = Builder.CreateZExt(Len, Int64Ty);
141 Len = Builder.CreateAdd(Len, One);
142
143 // Final join.
144 UncondBrInst::Create(Join, WhileDone);
145 Builder.SetInsertPoint(Join->begin());
146 auto LenPhi = Builder.CreatePHI(Len->getType(), 2);
147 LenPhi->addIncoming(Len, WhileDone);
148 LenPhi->addIncoming(Zero, Prev);
149
150 return LenPhi;
151}
152
154 Value *Length, bool isLast) {
155 auto Int64Ty = Builder.getInt64Ty();
156 auto IsLastInt32 = Builder.getInt32(isLast);
157 auto M = Builder.getModule();
158 auto Fn = M->getOrInsertFunction("__ockl_printf_append_string_n", Int64Ty,
159 Desc->getType(), Str->getType(),
160 Length->getType(), IsLastInt32->getType());
161 return Builder.CreateCall(Fn, {Desc, Str, Length, IsLastInt32});
162}
163
164static Value *appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg,
165 bool IsLast) {
166 auto Length = getStrlenWithNull(Builder, Arg);
167 return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
168}
169
170static Value *processArg(IRBuilder<> &Builder, Value *Desc, Value *Arg,
171 bool SpecIsCString, bool IsLast) {
172 if (SpecIsCString && isa<PointerType>(Arg->getType())) {
173 return appendString(Builder, Desc, Arg, IsLast);
174 }
175 // If the format specifies a string but the argument is not, the frontend will
176 // have printed a warning. We just rely on undefined behaviour and send the
177 // argument anyway.
178 return appendArg(Builder, Desc, Arg, IsLast);
179}
180
181// Scan the format string to locate all specifiers, and mark the ones that
182// specify a string, i.e, the "%s" specifier with optional '*' characters.
184 static const char ConvSpecifiers[] = "diouxXfFeEgGaAcspn";
185 // Skip the first argument, the format string.
186 unsigned ArgIdx = 1;
187
188 size_t SpecPos;
189 while ((SpecPos = Str.find('%')) != StringRef::npos) {
190 Str = Str.drop_front(SpecPos + 1);
191 // "%%" prints a '%' and takes no argument.
192 if (Str.consume_front("%"))
193 continue;
194 size_t SpecEnd = Str.find_first_of(ConvSpecifiers);
195 if (SpecEnd == StringRef::npos)
196 return;
197 // Each '*' in the specifier takes an argument of its own.
198 ArgIdx += Str.take_front(SpecEnd).count('*');
199 if (Str[SpecEnd] == 's')
200 BV.set(ArgIdx);
201 Str = Str.drop_front(SpecEnd + 1);
202 ++ArgIdx;
203 }
204}
205
206// helper struct to package the string related data
209 Value *RealSize = nullptr;
210 Value *AlignedSize = nullptr;
211 bool IsConst = true;
212
213 StringData(StringRef ST, Value *RS, Value *AS, bool IC)
214 : Str(ST), RealSize(RS), AlignedSize(AS), IsConst(IC) {}
215};
216
217// Calculates frame size required for current printf expansion and allocates
218// space on printf buffer. Printf frame includes following contents
219// [ ControlDWord , format string/Hash , Arguments (each aligned to 8 byte) ]
221 IRBuilder<> &Builder, ArrayRef<Value *> Args, Value *Fmt,
222 bool isConstFmtStr, SparseBitVector<8> &SpecIsCString,
223 SmallVectorImpl<StringData> &StringContents, Value *&ArgSize) {
224 Module *M = Builder.getModule();
225 Value *NonConstStrLen = nullptr;
226 Value *LenWithNull = nullptr;
227 Value *LenWithNullAligned = nullptr;
228 Value *TempAdd = nullptr;
229
230 // First 4 bytes to be reserved for control dword
231 size_t BufSize = 4;
232 if (isConstFmtStr)
233 // First 8 bytes of MD5 hash
234 BufSize += 8;
235 else {
236 LenWithNull = getStrlenWithNull(Builder, Fmt);
237
238 // Align the computed length to next 8 byte boundary
239 TempAdd = Builder.CreateAdd(LenWithNull,
240 ConstantInt::get(LenWithNull->getType(), 7U));
241 NonConstStrLen = Builder.CreateAnd(
242 TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
243
244 StringContents.push_back(
245 StringData(StringRef(), LenWithNull, NonConstStrLen, false));
246 }
247
248 for (size_t i = 1; i < Args.size(); i++) {
249 if (SpecIsCString.test(i)) {
250 StringRef ArgStr;
251 if (getConstantStringInfo(Args[i], ArgStr)) {
252 auto alignedLen = alignTo(ArgStr.size() + 1, 8);
253 StringContents.push_back(StringData(
254 ArgStr,
255 /*RealSize*/ nullptr, /*AlignedSize*/ nullptr, /*IsConst*/ true));
256 BufSize += alignedLen;
257 } else {
258 LenWithNull = getStrlenWithNull(Builder, Args[i]);
259
260 // Align the computed length to next 8 byte boundary
261 TempAdd = Builder.CreateAdd(
262 LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
263 LenWithNullAligned = Builder.CreateAnd(
264 TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
265
266 if (NonConstStrLen) {
267 auto Val = Builder.CreateAdd(LenWithNullAligned, NonConstStrLen,
268 "cumulativeAdd");
269 NonConstStrLen = Val;
270 } else
271 NonConstStrLen = LenWithNullAligned;
272
273 StringContents.push_back(
274 StringData(StringRef(), LenWithNull, LenWithNullAligned, false));
275 }
276 } else {
277 int AllocSize = M->getDataLayout().getTypeAllocSize(Args[i]->getType());
278 // We end up expanding non string arguments to 8 bytes
279 // (args smaller than 8 bytes)
280 BufSize += std::max(AllocSize, 8);
281 }
282 }
283
284 // calculate final size value to be passed to printf_alloc
285 Value *SizeToReserve = ConstantInt::get(Builder.getInt64Ty(), BufSize, false);
286 SmallVector<Value *, 1> Alloc_args;
287 if (NonConstStrLen)
288 SizeToReserve = Builder.CreateAdd(NonConstStrLen, SizeToReserve);
289
290 ArgSize = Builder.CreateTrunc(SizeToReserve, Builder.getInt32Ty());
291 Alloc_args.push_back(ArgSize);
292
293 // call the printf_alloc function
294 AttributeList Attr = AttributeList::get(
295 Builder.getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind);
296
297 Type *Tys_alloc[1] = {Builder.getInt32Ty()};
298 Type *PtrTy =
299 Builder.getPtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
300 FunctionType *FTy_alloc = FunctionType::get(PtrTy, Tys_alloc, false);
301 auto PrintfAllocFn =
302 M->getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);
303
304 return Builder.CreateCall(PrintfAllocFn, Alloc_args, "printf_alloc_fn");
305}
306
307// Prepare constant string argument to push onto the buffer
309 SmallVectorImpl<Value *> &WhatToStore) {
310 std::string Str(SD->Str.str() + '\0');
311
312 DataExtractor Extractor(Str, /*IsLittleEndian=*/true);
314 while (Offset && Offset.tell() < Str.size()) {
315 const uint64_t ReadSize = 4;
316 uint64_t ReadNow = std::min(ReadSize, Str.size() - Offset.tell());
317 uint64_t ReadBytes = 0;
318 switch (ReadNow) {
319 default:
320 llvm_unreachable("min(4, X) > 4?");
321 case 1:
322 ReadBytes = Extractor.getU8(Offset);
323 break;
324 case 2:
325 ReadBytes = Extractor.getU16(Offset);
326 break;
327 case 3:
328 ReadBytes = Extractor.getU24(Offset);
329 break;
330 case 4:
331 ReadBytes = Extractor.getU32(Offset);
332 break;
333 }
334 cantFail(Offset.takeError(), "failed to read bytes from constant array");
335
336 APInt IntVal(8 * ReadSize, ReadBytes);
337
338 // TODO: Should not bother aligning up.
339 if (ReadNow < ReadSize)
340 IntVal = IntVal.zext(8 * ReadSize);
341
342 Type *IntTy = Type::getIntNTy(Builder.getContext(), IntVal.getBitWidth());
343 WhatToStore.push_back(ConstantInt::get(IntTy, IntVal));
344 }
345 // Additional padding for 8 byte alignment
346 int Rem = (Str.size() % 8);
347 if (Rem > 0 && Rem <= 4)
348 WhatToStore.push_back(ConstantInt::get(Builder.getInt32Ty(), 0));
349}
350
352 const DataLayout &DL = Builder.getDataLayout();
353 auto Ty = Arg->getType();
354
355 if (auto IntTy = dyn_cast<IntegerType>(Ty)) {
356 if (IntTy->getBitWidth() < 64) {
357 return Builder.CreateZExt(Arg, Builder.getInt64Ty());
358 }
359 }
360
361 if (Ty->isFloatingPointTy()) {
362 if (DL.getTypeAllocSize(Ty) < 8) {
363 return Builder.CreateFPExt(Arg, Builder.getDoubleTy());
364 }
365 }
366
367 return Arg;
368}
369
370static void
372 Value *PtrToStore, SparseBitVector<8> &SpecIsCString,
373 SmallVectorImpl<StringData> &StringContents,
374 bool IsConstFmtStr) {
375 Module *M = Builder.getModule();
376 const DataLayout &DL = M->getDataLayout();
377 auto StrIt = StringContents.begin();
378 size_t i = IsConstFmtStr ? 1 : 0;
379 for (; i < Args.size(); i++) {
380 SmallVector<Value *, 32> WhatToStore;
381 if ((i == 0) || SpecIsCString.test(i)) {
382 if (StrIt->IsConst) {
383 processConstantStringArg(StrIt, Builder, WhatToStore);
384 StrIt++;
385 } else {
386 // This copies the contents of the string, however the next offset
387 // is at aligned length, the extra space that might be created due
388 // to alignment padding is not populated with any specific value
389 // here. This would be safe as long as runtime is sync with
390 // the offsets.
391 Builder.CreateMemCpy(PtrToStore, /*DstAlign*/ Align(1), Args[i],
392 /*SrcAlign*/ Args[i]->getPointerAlignment(DL),
393 StrIt->RealSize);
394
395 PtrToStore =
396 Builder.CreateInBoundsGEP(Builder.getInt8Ty(), PtrToStore,
397 {StrIt->AlignedSize}, "PrintBuffNextPtr");
398 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:"
399 << *PtrToStore << '\n');
400
401 // done with current argument, move to next
402 StrIt++;
403 continue;
404 }
405 } else {
406 WhatToStore.push_back(processNonStringArg(Args[i], Builder));
407 }
408
409 for (Value *toStore : WhatToStore) {
410 StoreInst *StBuff = Builder.CreateStore(toStore, PtrToStore);
411 LLVM_DEBUG(dbgs() << "inserting store to printf buffer:" << *StBuff
412 << '\n');
413 (void)StBuff;
414 PtrToStore = Builder.CreateConstInBoundsGEP1_32(
415 Builder.getInt8Ty(), PtrToStore,
416 M->getDataLayout().getTypeAllocSize(toStore->getType()),
417 "PrintBuffNextPtr");
418 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:" << *PtrToStore
419 << '\n');
420 }
421 }
422}
423
425 bool IsBuffered) {
426 auto NumOps = Args.size();
427 assert(NumOps >= 1);
428
429 auto Fmt = Args[0];
430 SparseBitVector<8> SpecIsCString;
431 StringRef FmtStr;
432
433 if (getConstantStringInfo(Fmt, FmtStr))
434 locateCStrings(SpecIsCString, FmtStr);
435
436 if (IsBuffered) {
437 SmallVector<StringData, 8> StringContents;
438 Module *M = Builder.getModule();
439 LLVMContext &Ctx = Builder.getContext();
440 auto Int8Ty = Builder.getInt8Ty();
441 auto Int32Ty = Builder.getInt32Ty();
442 bool IsConstFmtStr = !FmtStr.empty();
443
444 Value *ArgSize = nullptr;
445 Value *Ptr =
446 callBufferedPrintfStart(Builder, Args, Fmt, IsConstFmtStr,
447 SpecIsCString, StringContents, ArgSize);
448
449 // The buffered version still follows OpenCL printf standards for
450 // printf return value, i.e 0 on success, -1 on failure.
451 ConstantPointerNull *zeroIntPtr =
453
454 auto *Cmp = cast<ICmpInst>(Builder.CreateICmpNE(Ptr, zeroIntPtr, ""));
455
456 BasicBlock *End = BasicBlock::Create(Ctx, "end.block",
457 Builder.GetInsertBlock()->getParent());
459 Ctx, "argpush.block", Builder.GetInsertBlock()->getParent());
460
461 CondBrInst::Create(Cmp, ArgPush, End, Builder.GetInsertBlock());
462 Builder.SetInsertPoint(ArgPush);
463
464 // Create controlDWord and store as the first entry, format as follows
465 // Bit 0 (LSB) -> stream (1 if stderr, 0 if stdout, printf always outputs to
466 // stdout) Bit 1 -> constant format string (1 if constant) Bits 2-31 -> size
467 // of printf data frame
468 auto ConstantTwo = Builder.getInt32(2);
469 auto ControlDWord = Builder.CreateShl(ArgSize, ConstantTwo);
470 if (IsConstFmtStr)
471 ControlDWord = Builder.CreateOr(ControlDWord, ConstantTwo);
472
473 Builder.CreateStore(ControlDWord, Ptr);
474
475 Ptr = Builder.CreateConstInBoundsGEP1_32(Int8Ty, Ptr, 4);
476
477 // Create MD5 hash for constant format string, push low 64 bits of the
478 // same onto buffer and metadata.
479 NamedMDNode *metaD = M->getOrInsertNamedMetadata("llvm.printf.fmts");
480 if (IsConstFmtStr) {
481 MD5 Hasher;
482 MD5::MD5Result Hash;
483 Hasher.update(FmtStr);
484 Hasher.final(Hash);
485
486 // Try sticking to llvm.printf.fmts format, although we are not going to
487 // use the ID and argument size fields while printing,
488 std::string MetadataStr =
489 "0:0:" + llvm::utohexstr(Hash.low(), /*LowerCase=*/true) + "," +
490 FmtStr.str();
491 MDString *fmtStrArray = MDString::get(Ctx, MetadataStr);
492 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
493 metaD->addOperand(myMD);
494
495 Builder.CreateStore(Builder.getInt64(Hash.low()), Ptr);
496 Ptr = Builder.CreateConstInBoundsGEP1_32(Int8Ty, Ptr, 8);
497 } else {
498 // Include a dummy metadata instance in case of only non constant
499 // format string usage, This might be an absurd usecase but needs to
500 // be done for completeness
501 if (metaD->getNumOperands() == 0) {
502 MDString *fmtStrArray =
503 MDString::get(Ctx, "0:0:ffffffff,\"Non const format string\"");
504 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
505 metaD->addOperand(myMD);
506 }
507 }
508
509 // Push The printf arguments onto buffer
510 callBufferedPrintfArgPush(Builder, Args, Ptr, SpecIsCString, StringContents,
511 IsConstFmtStr);
512
513 // End block, returns -1 on failure
514 UncondBrInst::Create(End, ArgPush);
515 Builder.SetInsertPoint(End);
516 return Builder.CreateSExt(Builder.CreateNot(Cmp), Int32Ty, "printf_result");
517 }
518
519 auto Desc = callPrintfBegin(Builder, Builder.getIntN(64, 0));
520 Desc = appendString(Builder, Desc, Fmt, NumOps == 1);
521
522 // FIXME: This invokes hostcall once for each argument. We can pack up to
523 // seven scalar printf arguments in a single hostcall. See the signature of
524 // callAppendArgs().
525 for (unsigned int i = 1; i != NumOps; ++i) {
526 bool IsLast = i == NumOps - 1;
527 bool IsCString = SpecIsCString.test(i);
528 Desc = processArg(Builder, Desc, Args[i], IsCString, IsLast);
529 }
530
531 return Builder.CreateTrunc(Desc, Builder.getInt32Ty());
532}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
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 void locateCStrings(SparseBitVector< 8 > &BV, StringRef Str)
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
Class for arbitrary precision integers.
Definition APInt.h:78
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:446
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:2918
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:71
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 LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:303
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)
Op::Description Desc
LLVM_ABI Value * emitAMDGPUPrintfCall(IRBuilder<> &Builder, ArrayRef< Value * > Args, bool isBuffered)
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
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:267
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