Bug Summary

File:llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
Warning:line 259, column 48
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name AMDGPUPrintfRuntimeBinding.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/lib/Target/AMDGPU -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/Target/AMDGPU -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/include -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/lib/Target/AMDGPU -fdebug-prefix-map=/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2019-12-09-002921-48462-1 -x c++ /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

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"
22#include "llvm/ADT/SmallString.h"
23#include "llvm/ADT/StringExtras.h"
24#include "llvm/ADT/Triple.h"
25#include "llvm/Analysis/InstructionSimplify.h"
26#include "llvm/Analysis/TargetLibraryInfo.h"
27#include "llvm/CodeGen/Passes.h"
28#include "llvm/IR/Constants.h"
29#include "llvm/IR/DataLayout.h"
30#include "llvm/IR/Dominators.h"
31#include "llvm/IR/GlobalVariable.h"
32#include "llvm/IR/IRBuilder.h"
33#include "llvm/IR/Instructions.h"
34#include "llvm/IR/Module.h"
35#include "llvm/IR/Type.h"
36#include "llvm/Support/CommandLine.h"
37#include "llvm/Support/Debug.h"
38#include "llvm/Support/raw_ostream.h"
39#include "llvm/Transforms/Utils/BasicBlockUtils.h"
40using namespace llvm;
41
42#define DEBUG_TYPE"printfToRuntime" "printfToRuntime"
43#define DWORD_ALIGN4 4
44
45namespace {
46class LLVM_LIBRARY_VISIBILITY__attribute__ ((visibility("hidden"))) AMDGPUPrintfRuntimeBinding final
47 : public ModulePass {
48
49public:
50 static char ID;
51
52 explicit AMDGPUPrintfRuntimeBinding();
53
54private:
55 bool runOnModule(Module &M) override;
56 void getConversionSpecifiers(SmallVectorImpl<char> &OpConvSpecifiers,
57 StringRef fmt, size_t num_ops) const;
58
59 bool shouldPrintAsStr(char Specifier, Type *OpType) const;
60 bool
61 lowerPrintfForGpu(Module &M,
62 function_ref<const TargetLibraryInfo &(Function &)> GetTLI);
63
64 void getAnalysisUsage(AnalysisUsage &AU) const override {
65 AU.addRequired<TargetLibraryInfoWrapperPass>();
66 AU.addRequired<DominatorTreeWrapperPass>();
67 }
68
69 Value *simplify(Instruction *I, const TargetLibraryInfo *TLI) {
70 return SimplifyInstruction(I, {*TD, TLI, DT});
71 }
72
73 const DataLayout *TD;
74 const DominatorTree *DT;
75 SmallVector<CallInst *, 32> Printfs;
76};
77} // namespace
78
79char AMDGPUPrintfRuntimeBinding::ID = 0;
80
81INITIALIZE_PASS_BEGIN(AMDGPUPrintfRuntimeBinding,static void *initializeAMDGPUPrintfRuntimeBindingPassOnce(PassRegistry
&Registry) {
82 "amdgpu-printf-runtime-binding", "AMDGPU Printf lowering",static void *initializeAMDGPUPrintfRuntimeBindingPassOnce(PassRegistry
&Registry) {
83 false, false)static void *initializeAMDGPUPrintfRuntimeBindingPassOnce(PassRegistry
&Registry) {
84INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)initializeTargetLibraryInfoWrapperPassPass(Registry);
85INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)initializeDominatorTreeWrapperPassPass(Registry);
86INITIALIZE_PASS_END(AMDGPUPrintfRuntimeBinding, "amdgpu-printf-runtime-binding",PassInfo *PI = new PassInfo( "AMDGPU Printf lowering", "amdgpu-printf-runtime-binding"
, &AMDGPUPrintfRuntimeBinding::ID, PassInfo::NormalCtor_t
(callDefaultCtor<AMDGPUPrintfRuntimeBinding>), false, false
); Registry.registerPass(*PI, true); return PI; } static llvm
::once_flag InitializeAMDGPUPrintfRuntimeBindingPassFlag; void
llvm::initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &
Registry) { llvm::call_once(InitializeAMDGPUPrintfRuntimeBindingPassFlag
, initializeAMDGPUPrintfRuntimeBindingPassOnce, std::ref(Registry
)); }
87 "AMDGPU Printf lowering", false, false)PassInfo *PI = new PassInfo( "AMDGPU Printf lowering", "amdgpu-printf-runtime-binding"
, &AMDGPUPrintfRuntimeBinding::ID, PassInfo::NormalCtor_t
(callDefaultCtor<AMDGPUPrintfRuntimeBinding>), false, false
); Registry.registerPass(*PI, true); return PI; } static llvm
::once_flag InitializeAMDGPUPrintfRuntimeBindingPassFlag; void
llvm::initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &
Registry) { llvm::call_once(InitializeAMDGPUPrintfRuntimeBindingPassFlag
, initializeAMDGPUPrintfRuntimeBindingPassOnce, std::ref(Registry
)); }
88
89char &llvm::AMDGPUPrintfRuntimeBindingID = AMDGPUPrintfRuntimeBinding::ID;
90
91namespace llvm {
92ModulePass *createAMDGPUPrintfRuntimeBinding() {
93 return new AMDGPUPrintfRuntimeBinding();
94}
95} // namespace llvm
96
97AMDGPUPrintfRuntimeBinding::AMDGPUPrintfRuntimeBinding()
98 : ModulePass(ID), TD(nullptr), DT(nullptr) {
99 initializeAMDGPUPrintfRuntimeBindingPass(*PassRegistry::getPassRegistry());
100}
101
102void AMDGPUPrintfRuntimeBinding::getConversionSpecifiers(
103 SmallVectorImpl<char> &OpConvSpecifiers, StringRef Fmt,
104 size_t NumOps) const {
105 // not all format characters are collected.
106 // At this time the format characters of interest
107 // are %p and %s, which use to know if we
108 // are either storing a literal string or a
109 // pointer to the printf buffer.
110 static const char ConvSpecifiers[] = "cdieEfgGaosuxXp";
111 size_t CurFmtSpecifierIdx = 0;
112 size_t PrevFmtSpecifierIdx = 0;
113
114 while ((CurFmtSpecifierIdx = Fmt.find_first_of(
115 ConvSpecifiers, CurFmtSpecifierIdx)) != StringRef::npos) {
116 bool ArgDump = false;
117 StringRef CurFmt = Fmt.substr(PrevFmtSpecifierIdx,
118 CurFmtSpecifierIdx - PrevFmtSpecifierIdx);
119 size_t pTag = CurFmt.find_last_of("%");
120 if (pTag != StringRef::npos) {
121 ArgDump = true;
122 while (pTag && CurFmt[--pTag] == '%') {
123 ArgDump = !ArgDump;
124 }
125 }
126
127 if (ArgDump)
128 OpConvSpecifiers.push_back(Fmt[CurFmtSpecifierIdx]);
129
130 PrevFmtSpecifierIdx = ++CurFmtSpecifierIdx;
131 }
132}
133
134bool AMDGPUPrintfRuntimeBinding::shouldPrintAsStr(char Specifier,
135 Type *OpType) const {
136 if (Specifier != 's')
17
Assuming the condition is false
18
Taking false branch
137 return false;
138 const PointerType *PT = dyn_cast<PointerType>(OpType);
19
Assuming 'OpType' is a 'PointerType'
139 if (!PT
19.1
'PT' is non-null, which participates in a condition later
19.1
'PT' is non-null, which participates in a condition later
|| PT->getAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
20
Assuming the condition is false
21
Taking false branch
140 return false;
141 Type *ElemType = PT->getContainedType(0);
142 if (ElemType->getTypeID() != Type::IntegerTyID)
22
Assuming the condition is false
23
Taking false branch
143 return false;
144 IntegerType *ElemIType = cast<IntegerType>(ElemType);
24
'ElemType' is a 'IntegerType'
145 return ElemIType->getBitWidth() == 8;
25
Assuming the condition is true
26
Returning the value 1, which participates in a condition later
146}
147
148bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu(
149 Module &M, function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
150 LLVMContext &Ctx = M.getContext();
151 IRBuilder<> Builder(Ctx);
152 Type *I32Ty = Type::getInt32Ty(Ctx);
153 unsigned UniqID = 0;
154 // NB: This is important for this string size to be divizable by 4
155 const char NonLiteralStr[4] = "???";
156
157 for (auto CI : Printfs) {
1
Assuming '__begin1' is not equal to '__end1'
158 unsigned NumOps = CI->getNumArgOperands();
159
160 SmallString<16> OpConvSpecifiers;
161 Value *Op = CI->getArgOperand(0);
162
163 if (auto LI = dyn_cast<LoadInst>(Op)) {
2
Assuming 'LI' is null
3
Taking false branch
164 Op = LI->getPointerOperand();
165 for (auto Use : Op->users()) {
166 if (auto SI = dyn_cast<StoreInst>(Use)) {
167 Op = SI->getValueOperand();
168 break;
169 }
170 }
171 }
172
173 if (auto I = dyn_cast<Instruction>(Op)) {
4
Assuming 'I' is null
5
Taking false branch
174 Value *Op_simplified = simplify(I, &GetTLI(*I->getFunction()));
175 if (Op_simplified)
176 Op = Op_simplified;
177 }
178
179 ConstantExpr *ConstExpr = dyn_cast<ConstantExpr>(Op);
180
181 if (ConstExpr) {
6
Assuming 'ConstExpr' is non-null
7
Taking true branch
182 GlobalVariable *GVar = dyn_cast<GlobalVariable>(ConstExpr->getOperand(0));
183
184 StringRef Str("unknown");
185 if (GVar && GVar->hasInitializer()) {
8
Assuming 'GVar' is null
186 auto Init = GVar->getInitializer();
187 if (auto CA = dyn_cast<ConstantDataArray>(Init)) {
188 if (CA->isString())
189 Str = CA->getAsCString();
190 } else if (isa<ConstantAggregateZero>(Init)) {
191 Str = "";
192 }
193 //
194 // we need this call to ascertain
195 // that we are printing a string
196 // or a pointer. It takes out the
197 // specifiers and fills up the first
198 // arg
199 getConversionSpecifiers(OpConvSpecifiers, Str, NumOps - 1);
200 }
201 // Add metadata for the string
202 std::string AStreamHolder;
203 raw_string_ostream Sizes(AStreamHolder);
204 int Sum = DWORD_ALIGN4;
205 Sizes << CI->getNumArgOperands() - 1;
206 Sizes << ':';
207 for (unsigned ArgCount = 1; ArgCount < CI->getNumArgOperands() &&
9
Assuming the condition is true
11
Loop condition is true. Entering loop body
208 ArgCount <= OpConvSpecifiers.size();
10
Assuming the condition is true
209 ArgCount++) {
210 Value *Arg = CI->getArgOperand(ArgCount);
211 Type *ArgType = Arg->getType();
212 unsigned ArgSize = TD->getTypeAllocSizeInBits(ArgType);
213 ArgSize = ArgSize / 8;
214 //
215 // ArgSize by design should be a multiple of DWORD_ALIGN,
216 // expand the arguments that do not follow this rule.
217 //
218 if (ArgSize % DWORD_ALIGN4 != 0) {
12
Assuming the condition is false
13
Taking false branch
219 llvm::Type *ResType = llvm::Type::getInt32Ty(Ctx);
220 VectorType *LLVMVecType = llvm::dyn_cast<llvm::VectorType>(ArgType);
221 int NumElem = LLVMVecType ? LLVMVecType->getNumElements() : 1;
222 if (LLVMVecType && NumElem > 1)
223 ResType = llvm::VectorType::get(ResType, NumElem);
224 Builder.SetInsertPoint(CI);
225 Builder.SetCurrentDebugLocation(CI->getDebugLoc());
226 if (OpConvSpecifiers[ArgCount - 1] == 'x' ||
227 OpConvSpecifiers[ArgCount - 1] == 'X' ||
228 OpConvSpecifiers[ArgCount - 1] == 'u' ||
229 OpConvSpecifiers[ArgCount - 1] == 'o')
230 Arg = Builder.CreateZExt(Arg, ResType);
231 else
232 Arg = Builder.CreateSExt(Arg, ResType);
233 ArgType = Arg->getType();
234 ArgSize = TD->getTypeAllocSizeInBits(ArgType);
235 ArgSize = ArgSize / 8;
236 CI->setOperand(ArgCount, Arg);
237 }
238 if (OpConvSpecifiers[ArgCount - 1] == 'f') {
14
Assuming the condition is false
15
Taking false branch
239 ConstantFP *FpCons = dyn_cast<ConstantFP>(Arg);
240 if (FpCons)
241 ArgSize = 4;
242 else {
243 FPExtInst *FpExt = dyn_cast<FPExtInst>(Arg);
244 if (FpExt && FpExt->getType()->isDoubleTy() &&
245 FpExt->getOperand(0)->getType()->isFloatTy())
246 ArgSize = 4;
247 }
248 }
249 if (shouldPrintAsStr(OpConvSpecifiers[ArgCount - 1], ArgType)) {
16
Calling 'AMDGPUPrintfRuntimeBinding::shouldPrintAsStr'
27
Returning from 'AMDGPUPrintfRuntimeBinding::shouldPrintAsStr'
28
Taking true branch
250 if (ConstantExpr *ConstExpr
29.1
'ConstExpr' is non-null
29.1
'ConstExpr' is non-null
= dyn_cast<ConstantExpr>(Arg)) {
29
Assuming 'Arg' is a 'ConstantExpr'
30
Taking true branch
251 GlobalVariable *GV =
252 dyn_cast<GlobalVariable>(ConstExpr->getOperand(0));
253 if (GV && GV->hasInitializer()) {
31
Assuming 'GV' is non-null
32
Calling 'GlobalVariable::hasInitializer'
35
Returning from 'GlobalVariable::hasInitializer'
36
Taking true branch
254 Constant *Init = GV->getInitializer();
255 ConstantDataArray *CA = dyn_cast<ConstantDataArray>(Init);
37
Assuming 'Init' is not a 'ConstantDataArray'
38
'CA' initialized to a null pointer value
256 if (Init->isZeroValue() || CA->isString()) {
39
Assuming the condition is true
257 size_t SizeStr = Init->isZeroValue()
40
Assuming the condition is false
41
'?' condition is false
258 ? 1
259 : (strlen(CA->getAsCString().data()) + 1);
42
Called C++ object pointer is null
260 size_t Rem = SizeStr % DWORD_ALIGN4;
261 size_t NSizeStr = 0;
262 LLVM_DEBUG(dbgs() << "Printf string original size = " << SizeStrdo { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf string original size = "
<< SizeStr << '\n'; } } while (false)
263 << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf string original size = "
<< SizeStr << '\n'; } } while (false)
;
264 if (Rem) {
265 NSizeStr = SizeStr + (DWORD_ALIGN4 - Rem);
266 } else {
267 NSizeStr = SizeStr;
268 }
269 ArgSize = NSizeStr;
270 }
271 } else {
272 ArgSize = sizeof(NonLiteralStr);
273 }
274 } else {
275 ArgSize = sizeof(NonLiteralStr);
276 }
277 }
278 LLVM_DEBUG(dbgs() << "Printf ArgSize (in buffer) = " << ArgSizedo { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf ArgSize (in buffer) = "
<< ArgSize << " for type: " << *ArgType <<
'\n'; } } while (false)
279 << " for type: " << *ArgType << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf ArgSize (in buffer) = "
<< ArgSize << " for type: " << *ArgType <<
'\n'; } } while (false)
;
280 Sizes << ArgSize << ':';
281 Sum += ArgSize;
282 }
283 LLVM_DEBUG(dbgs() << "Printf format string in source = " << Str.str()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf format string in source = "
<< Str.str() << '\n'; } } while (false)
284 << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf format string in source = "
<< Str.str() << '\n'; } } while (false)
;
285 for (size_t I = 0; I < Str.size(); ++I) {
286 // Rest of the C escape sequences (e.g. \') are handled correctly
287 // by the MDParser
288 switch (Str[I]) {
289 case '\a':
290 Sizes << "\\a";
291 break;
292 case '\b':
293 Sizes << "\\b";
294 break;
295 case '\f':
296 Sizes << "\\f";
297 break;
298 case '\n':
299 Sizes << "\\n";
300 break;
301 case '\r':
302 Sizes << "\\r";
303 break;
304 case '\v':
305 Sizes << "\\v";
306 break;
307 case ':':
308 // ':' cannot be scanned by Flex, as it is defined as a delimiter
309 // Replace it with it's octal representation \72
310 Sizes << "\\72";
311 break;
312 default:
313 Sizes << Str[I];
314 break;
315 }
316 }
317
318 // Insert the printf_alloc call
319 Builder.SetInsertPoint(CI);
320 Builder.SetCurrentDebugLocation(CI->getDebugLoc());
321
322 AttributeList Attr = AttributeList::get(Ctx, AttributeList::FunctionIndex,
323 Attribute::NoUnwind);
324
325 Type *SizetTy = Type::getInt32Ty(Ctx);
326
327 Type *Tys_alloc[1] = {SizetTy};
328 Type *I8Ptr = PointerType::get(Type::getInt8Ty(Ctx), 1);
329 FunctionType *FTy_alloc = FunctionType::get(I8Ptr, Tys_alloc, false);
330 FunctionCallee PrintfAllocFn =
331 M.getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);
332
333 LLVM_DEBUG(dbgs() << "Printf metadata = " << Sizes.str() << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "Printf metadata = " <<
Sizes.str() << '\n'; } } while (false)
;
334 std::string fmtstr = itostr(++UniqID) + ":" + Sizes.str().c_str();
335 MDString *fmtStrArray = MDString::get(Ctx, fmtstr);
336
337 // Instead of creating global variables, the
338 // printf format strings are extracted
339 // and passed as metadata. This avoids
340 // polluting llvm's symbol tables in this module.
341 // Metadata is going to be extracted
342 // by the backend passes and inserted
343 // into the OpenCL binary as appropriate.
344 StringRef amd("llvm.printf.fmts");
345 NamedMDNode *metaD = M.getOrInsertNamedMetadata(amd);
346 MDNode *myMD = MDNode::get(Ctx, fmtStrArray);
347 metaD->addOperand(myMD);
348 Value *sumC = ConstantInt::get(SizetTy, Sum, false);
349 SmallVector<Value *, 1> alloc_args;
350 alloc_args.push_back(sumC);
351 CallInst *pcall =
352 CallInst::Create(PrintfAllocFn, alloc_args, "printf_alloc_fn", CI);
353
354 //
355 // Insert code to split basicblock with a
356 // piece of hammock code.
357 // basicblock splits after buffer overflow check
358 //
359 ConstantPointerNull *zeroIntPtr =
360 ConstantPointerNull::get(PointerType::get(Type::getInt8Ty(Ctx), 1));
361 ICmpInst *cmp =
362 dyn_cast<ICmpInst>(Builder.CreateICmpNE(pcall, zeroIntPtr, ""));
363 if (!CI->use_empty()) {
364 Value *result =
365 Builder.CreateSExt(Builder.CreateNot(cmp), I32Ty, "printf_res");
366 CI->replaceAllUsesWith(result);
367 }
368 SplitBlock(CI->getParent(), cmp);
369 Instruction *Brnch =
370 SplitBlockAndInsertIfThen(cmp, cmp->getNextNode(), false);
371
372 Builder.SetInsertPoint(Brnch);
373
374 // store unique printf id in the buffer
375 //
376 SmallVector<Value *, 1> ZeroIdxList;
377 ConstantInt *zeroInt =
378 ConstantInt::get(Ctx, APInt(32, StringRef("0"), 10));
379 ZeroIdxList.push_back(zeroInt);
380
381 GetElementPtrInst *BufferIdx =
382 dyn_cast<GetElementPtrInst>(GetElementPtrInst::Create(
383 nullptr, pcall, ZeroIdxList, "PrintBuffID", Brnch));
384
385 Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS);
386 Value *id_gep_cast =
387 new BitCastInst(BufferIdx, idPointer, "PrintBuffIdCast", Brnch);
388
389 StoreInst *stbuff =
390 new StoreInst(ConstantInt::get(I32Ty, UniqID), id_gep_cast);
391 stbuff->insertBefore(Brnch); // to Remove unused variable warning
392
393 SmallVector<Value *, 2> FourthIdxList;
394 ConstantInt *fourInt =
395 ConstantInt::get(Ctx, APInt(32, StringRef("4"), 10));
396
397 FourthIdxList.push_back(fourInt); // 1st 4 bytes hold the printf_id
398 // the following GEP is the buffer pointer
399 BufferIdx = cast<GetElementPtrInst>(GetElementPtrInst::Create(
400 nullptr, pcall, FourthIdxList, "PrintBuffGep", Brnch));
401
402 Type *Int32Ty = Type::getInt32Ty(Ctx);
403 Type *Int64Ty = Type::getInt64Ty(Ctx);
404 for (unsigned ArgCount = 1; ArgCount < CI->getNumArgOperands() &&
405 ArgCount <= OpConvSpecifiers.size();
406 ArgCount++) {
407 Value *Arg = CI->getArgOperand(ArgCount);
408 Type *ArgType = Arg->getType();
409 SmallVector<Value *, 32> WhatToStore;
410 if (ArgType->isFPOrFPVectorTy() &&
411 (ArgType->getTypeID() != Type::VectorTyID)) {
412 Type *IType = (ArgType->isFloatTy()) ? Int32Ty : Int64Ty;
413 if (OpConvSpecifiers[ArgCount - 1] == 'f') {
414 ConstantFP *fpCons = dyn_cast<ConstantFP>(Arg);
415 if (fpCons) {
416 APFloat Val(fpCons->getValueAPF());
417 bool Lost = false;
418 Val.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
419 &Lost);
420 Arg = ConstantFP::get(Ctx, Val);
421 IType = Int32Ty;
422 } else {
423 FPExtInst *FpExt = dyn_cast<FPExtInst>(Arg);
424 if (FpExt && FpExt->getType()->isDoubleTy() &&
425 FpExt->getOperand(0)->getType()->isFloatTy()) {
426 Arg = FpExt->getOperand(0);
427 IType = Int32Ty;
428 }
429 }
430 }
431 Arg = new BitCastInst(Arg, IType, "PrintArgFP", Brnch);
432 WhatToStore.push_back(Arg);
433 } else if (ArgType->getTypeID() == Type::PointerTyID) {
434 if (shouldPrintAsStr(OpConvSpecifiers[ArgCount - 1], ArgType)) {
435 const char *S = NonLiteralStr;
436 if (ConstantExpr *ConstExpr = dyn_cast<ConstantExpr>(Arg)) {
437 GlobalVariable *GV =
438 dyn_cast<GlobalVariable>(ConstExpr->getOperand(0));
439 if (GV && GV->hasInitializer()) {
440 Constant *Init = GV->getInitializer();
441 ConstantDataArray *CA = dyn_cast<ConstantDataArray>(Init);
442 if (Init->isZeroValue() || CA->isString()) {
443 S = Init->isZeroValue() ? "" : CA->getAsCString().data();
444 }
445 }
446 }
447 size_t SizeStr = strlen(S) + 1;
448 size_t Rem = SizeStr % DWORD_ALIGN4;
449 size_t NSizeStr = 0;
450 if (Rem) {
451 NSizeStr = SizeStr + (DWORD_ALIGN4 - Rem);
452 } else {
453 NSizeStr = SizeStr;
454 }
455 if (S[0]) {
456 char *MyNewStr = new char[NSizeStr]();
457 strcpy(MyNewStr, S);
458 int NumInts = NSizeStr / 4;
459 int CharC = 0;
460 while (NumInts) {
461 int ANum = *(int *)(MyNewStr + CharC);
462 CharC += 4;
463 NumInts--;
464 Value *ANumV = ConstantInt::get(Int32Ty, ANum, false);
465 WhatToStore.push_back(ANumV);
466 }
467 delete[] MyNewStr;
468 } else {
469 // Empty string, give a hint to RT it is no NULL
470 Value *ANumV = ConstantInt::get(Int32Ty, 0xFFFFFF00, false);
471 WhatToStore.push_back(ANumV);
472 }
473 } else {
474 uint64_t Size = TD->getTypeAllocSizeInBits(ArgType);
475 assert((Size == 32 || Size == 64) && "unsupported size")(((Size == 32 || Size == 64) && "unsupported size") ?
static_cast<void> (0) : __assert_fail ("(Size == 32 || Size == 64) && \"unsupported size\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp"
, 475, __PRETTY_FUNCTION__))
;
476 Type *DstType = (Size == 32) ? Int32Ty : Int64Ty;
477 Arg = new PtrToIntInst(Arg, DstType, "PrintArgPtr", Brnch);
478 WhatToStore.push_back(Arg);
479 }
480 } else if (ArgType->getTypeID() == Type::VectorTyID) {
481 Type *IType = NULL__null;
482 uint32_t EleCount = cast<VectorType>(ArgType)->getNumElements();
483 uint32_t EleSize = ArgType->getScalarSizeInBits();
484 uint32_t TotalSize = EleCount * EleSize;
485 if (EleCount == 3) {
486 IntegerType *Int32Ty = Type::getInt32Ty(ArgType->getContext());
487 Constant *Indices[4] = {
488 ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, 1),
489 ConstantInt::get(Int32Ty, 2), ConstantInt::get(Int32Ty, 2)};
490 Constant *Mask = ConstantVector::get(Indices);
491 ShuffleVectorInst *Shuffle = new ShuffleVectorInst(Arg, Arg, Mask);
492 Shuffle->insertBefore(Brnch);
493 Arg = Shuffle;
494 ArgType = Arg->getType();
495 TotalSize += EleSize;
496 }
497 switch (EleSize) {
498 default:
499 EleCount = TotalSize / 64;
500 IType = dyn_cast<Type>(Type::getInt64Ty(ArgType->getContext()));
501 break;
502 case 8:
503 if (EleCount >= 8) {
504 EleCount = TotalSize / 64;
505 IType = dyn_cast<Type>(Type::getInt64Ty(ArgType->getContext()));
506 } else if (EleCount >= 3) {
507 EleCount = 1;
508 IType = dyn_cast<Type>(Type::getInt32Ty(ArgType->getContext()));
509 } else {
510 EleCount = 1;
511 IType = dyn_cast<Type>(Type::getInt16Ty(ArgType->getContext()));
512 }
513 break;
514 case 16:
515 if (EleCount >= 3) {
516 EleCount = TotalSize / 64;
517 IType = dyn_cast<Type>(Type::getInt64Ty(ArgType->getContext()));
518 } else {
519 EleCount = 1;
520 IType = dyn_cast<Type>(Type::getInt32Ty(ArgType->getContext()));
521 }
522 break;
523 }
524 if (EleCount > 1) {
525 IType = dyn_cast<Type>(VectorType::get(IType, EleCount));
526 }
527 Arg = new BitCastInst(Arg, IType, "PrintArgVect", Brnch);
528 WhatToStore.push_back(Arg);
529 } else {
530 WhatToStore.push_back(Arg);
531 }
532 for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) {
533 Value *TheBtCast = WhatToStore[I];
534 unsigned ArgSize =
535 TD->getTypeAllocSizeInBits(TheBtCast->getType()) / 8;
536 SmallVector<Value *, 1> BuffOffset;
537 BuffOffset.push_back(ConstantInt::get(I32Ty, ArgSize));
538
539 Type *ArgPointer = PointerType::get(TheBtCast->getType(), 1);
540 Value *CastedGEP =
541 new BitCastInst(BufferIdx, ArgPointer, "PrintBuffPtrCast", Brnch);
542 StoreInst *StBuff = new StoreInst(TheBtCast, CastedGEP, Brnch);
543 LLVM_DEBUG(dbgs() << "inserting store to printf buffer:\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "inserting store to printf buffer:\n"
<< *StBuff << '\n'; } } while (false)
544 << *StBuff << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "inserting store to printf buffer:\n"
<< *StBuff << '\n'; } } while (false)
;
545 (void)StBuff;
546 if (I + 1 == E && ArgCount + 1 == CI->getNumArgOperands())
547 break;
548 BufferIdx = dyn_cast<GetElementPtrInst>(GetElementPtrInst::Create(
549 nullptr, BufferIdx, BuffOffset, "PrintBuffNextPtr", Brnch));
550 LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "inserting gep to the printf buffer:\n"
<< *BufferIdx << '\n'; } } while (false)
551 << *BufferIdx << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("printfToRuntime")) { dbgs() << "inserting gep to the printf buffer:\n"
<< *BufferIdx << '\n'; } } while (false)
;
552 }
553 }
554 }
555 }
556
557 // erase the printf calls
558 for (auto CI : Printfs)
559 CI->eraseFromParent();
560
561 Printfs.clear();
562 return true;
563}
564
565bool AMDGPUPrintfRuntimeBinding::runOnModule(Module &M) {
566 Triple TT(M.getTargetTriple());
567 if (TT.getArch() == Triple::r600)
568 return false;
569
570 auto PrintfFunction = M.getFunction("printf");
571 if (!PrintfFunction)
572 return false;
573
574 for (auto &U : PrintfFunction->uses()) {
575 if (auto *CI = dyn_cast<CallInst>(U.getUser())) {
576 if (CI->isCallee(&U))
577 Printfs.push_back(CI);
578 }
579 }
580
581 if (Printfs.empty())
582 return false;
583
584 TD = &M.getDataLayout();
585 auto DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
586 DT = DTWP ? &DTWP->getDomTree() : nullptr;
587 auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
588 return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
589 };
590
591 return lowerPrintfForGpu(M, GetTLI);
592}

/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h

1//===-- llvm/GlobalVariable.h - GlobalVariable class ------------*- 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 file contains the declaration of the GlobalVariable class, which
10// represents a single global variable (or constant) in the VM.
11//
12// Global variables are constant pointers that refer to hunks of space that are
13// allocated by either the VM, or by the linker in a static compiler. A global
14// variable may have an initial value, which is copied into the executables .data
15// area. Global Constants are required to have initializers.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_IR_GLOBALVARIABLE_H
20#define LLVM_IR_GLOBALVARIABLE_H
21
22#include "llvm/ADT/PointerUnion.h"
23#include "llvm/ADT/Twine.h"
24#include "llvm/ADT/ilist_node.h"
25#include "llvm/IR/Attributes.h"
26#include "llvm/IR/GlobalObject.h"
27#include "llvm/IR/OperandTraits.h"
28#include "llvm/IR/Value.h"
29#include <cassert>
30#include <cstddef>
31
32namespace llvm {
33
34class Constant;
35class Module;
36
37template <typename ValueSubClass> class SymbolTableListTraits;
38class DIGlobalVariable;
39class DIGlobalVariableExpression;
40
41class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> {
42 friend class SymbolTableListTraits<GlobalVariable>;
43
44 AttributeSet Attrs;
45 bool isConstantGlobal : 1; // Is this a global constant?
46 bool isExternallyInitializedConstant : 1; // Is this a global whose value
47 // can change from its initial
48 // value before global
49 // initializers are run?
50
51public:
52 /// GlobalVariable ctor - If a parent module is specified, the global is
53 /// automatically inserted into the end of the specified modules global list.
54 GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Linkage,
55 Constant *Initializer = nullptr, const Twine &Name = "",
56 ThreadLocalMode = NotThreadLocal, unsigned AddressSpace = 0,
57 bool isExternallyInitialized = false);
58 /// GlobalVariable ctor - This creates a global and inserts it before the
59 /// specified other global.
60 GlobalVariable(Module &M, Type *Ty, bool isConstant,
61 LinkageTypes Linkage, Constant *Initializer,
62 const Twine &Name = "", GlobalVariable *InsertBefore = nullptr,
63 ThreadLocalMode = NotThreadLocal, unsigned AddressSpace = 0,
64 bool isExternallyInitialized = false);
65 GlobalVariable(const GlobalVariable &) = delete;
66 GlobalVariable &operator=(const GlobalVariable &) = delete;
67
68 ~GlobalVariable() {
69 dropAllReferences();
70 }
71
72 // allocate space for exactly one operand
73 void *operator new(size_t s) {
74 return User::operator new(s, 1);
75 }
76
77 // delete space for exactly one operand as created in the corresponding new operator
78 void operator delete(void *ptr){
79 assert(ptr != nullptr && "must not be nullptr")((ptr != nullptr && "must not be nullptr") ? static_cast
<void> (0) : __assert_fail ("ptr != nullptr && \"must not be nullptr\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h"
, 79, __PRETTY_FUNCTION__))
;
80 User *Obj = static_cast<User *>(ptr);
81 // Number of operands can be set to 0 after construction and initialization. Make sure
82 // that number of operands is reset to 1, as this is needed in User::operator delete
83 Obj->setGlobalVariableNumOperands(1);
84 User::operator delete(Obj);
85 }
86
87 /// Provide fast operand accessors
88 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
89
90 /// Definitions have initializers, declarations don't.
91 ///
92 inline bool hasInitializer() const { return !isDeclaration(); }
33
Assuming the condition is true
34
Returning the value 1, which participates in a condition later
93
94 /// hasDefinitiveInitializer - Whether the global variable has an initializer,
95 /// and any other instances of the global (this can happen due to weak
96 /// linkage) are guaranteed to have the same initializer.
97 ///
98 /// Note that if you want to transform a global, you must use
99 /// hasUniqueInitializer() instead, because of the *_odr linkage type.
100 ///
101 /// Example:
102 ///
103 /// @a = global SomeType* null - Initializer is both definitive and unique.
104 ///
105 /// @b = global weak SomeType* null - Initializer is neither definitive nor
106 /// unique.
107 ///
108 /// @c = global weak_odr SomeType* null - Initializer is definitive, but not
109 /// unique.
110 inline bool hasDefinitiveInitializer() const {
111 return hasInitializer() &&
112 // The initializer of a global variable may change to something arbitrary
113 // at link time.
114 !isInterposable() &&
115 // The initializer of a global variable with the externally_initialized
116 // marker may change at runtime before C++ initializers are evaluated.
117 !isExternallyInitialized();
118 }
119
120 /// hasUniqueInitializer - Whether the global variable has an initializer, and
121 /// any changes made to the initializer will turn up in the final executable.
122 inline bool hasUniqueInitializer() const {
123 return
124 // We need to be sure this is the definition that will actually be used
125 isStrongDefinitionForLinker() &&
126 // It is not safe to modify initializers of global variables with the
127 // external_initializer marker since the value may be changed at runtime
128 // before C++ initializers are evaluated.
129 !isExternallyInitialized();
130 }
131
132 /// getInitializer - Return the initializer for this global variable. It is
133 /// illegal to call this method if the global is external, because we cannot
134 /// tell what the value is initialized to!
135 ///
136 inline const Constant *getInitializer() const {
137 assert(hasInitializer() && "GV doesn't have initializer!")((hasInitializer() && "GV doesn't have initializer!")
? static_cast<void> (0) : __assert_fail ("hasInitializer() && \"GV doesn't have initializer!\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h"
, 137, __PRETTY_FUNCTION__))
;
138 return static_cast<Constant*>(Op<0>().get());
139 }
140 inline Constant *getInitializer() {
141 assert(hasInitializer() && "GV doesn't have initializer!")((hasInitializer() && "GV doesn't have initializer!")
? static_cast<void> (0) : __assert_fail ("hasInitializer() && \"GV doesn't have initializer!\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h"
, 141, __PRETTY_FUNCTION__))
;
142 return static_cast<Constant*>(Op<0>().get());
143 }
144 /// setInitializer - Sets the initializer for this global variable, removing
145 /// any existing initializer if InitVal==NULL. If this GV has type T*, the
146 /// initializer must have type T.
147 void setInitializer(Constant *InitVal);
148
149 /// If the value is a global constant, its value is immutable throughout the
150 /// runtime execution of the program. Assigning a value into the constant
151 /// leads to undefined behavior.
152 ///
153 bool isConstant() const { return isConstantGlobal; }
154 void setConstant(bool Val) { isConstantGlobal = Val; }
155
156 bool isExternallyInitialized() const {
157 return isExternallyInitializedConstant;
158 }
159 void setExternallyInitialized(bool Val) {
160 isExternallyInitializedConstant = Val;
161 }
162
163 /// copyAttributesFrom - copy all additional attributes (those not needed to
164 /// create a GlobalVariable) from the GlobalVariable Src to this one.
165 void copyAttributesFrom(const GlobalVariable *Src);
166
167 /// removeFromParent - This method unlinks 'this' from the containing module,
168 /// but does not delete it.
169 ///
170 void removeFromParent();
171
172 /// eraseFromParent - This method unlinks 'this' from the containing module
173 /// and deletes it.
174 ///
175 void eraseFromParent();
176
177 /// Drop all references in preparation to destroy the GlobalVariable. This
178 /// drops not only the reference to the initializer but also to any metadata.
179 void dropAllReferences();
180
181 /// Attach a DIGlobalVariableExpression.
182 void addDebugInfo(DIGlobalVariableExpression *GV);
183
184 /// Fill the vector with all debug info attachements.
185 void getDebugInfo(SmallVectorImpl<DIGlobalVariableExpression *> &GVs) const;
186
187 /// Add attribute to this global.
188 void addAttribute(Attribute::AttrKind Kind) {
189 Attrs = Attrs.addAttribute(getContext(), Kind);
190 }
191
192 /// Add attribute to this global.
193 void addAttribute(StringRef Kind, StringRef Val = StringRef()) {
194 Attrs = Attrs.addAttribute(getContext(), Kind, Val);
195 }
196
197 /// Return true if the attribute exists.
198 bool hasAttribute(Attribute::AttrKind Kind) const {
199 return Attrs.hasAttribute(Kind);
200 }
201
202 /// Return true if the attribute exists.
203 bool hasAttribute(StringRef Kind) const {
204 return Attrs.hasAttribute(Kind);
205 }
206
207 /// Return true if any attributes exist.
208 bool hasAttributes() const {
209 return Attrs.hasAttributes();
210 }
211
212 /// Return the attribute object.
213 Attribute getAttribute(Attribute::AttrKind Kind) const {
214 return Attrs.getAttribute(Kind);
215 }
216
217 /// Return the attribute object.
218 Attribute getAttribute(StringRef Kind) const {
219 return Attrs.getAttribute(Kind);
220 }
221
222 /// Return the attribute set for this global
223 AttributeSet getAttributes() const {
224 return Attrs;
225 }
226
227 /// Return attribute set as list with index.
228 /// FIXME: This may not be required once ValueEnumerators
229 /// in bitcode-writer can enumerate attribute-set.
230 AttributeList getAttributesAsList(unsigned index) const {
231 if (!hasAttributes())
232 return AttributeList();
233 std::pair<unsigned, AttributeSet> AS[1] = {{index, Attrs}};
234 return AttributeList::get(getContext(), AS);
235 }
236
237 /// Set attribute list for this global
238 void setAttributes(AttributeSet A) {
239 Attrs = A;
240 }
241
242 /// Check if section name is present
243 bool hasImplicitSection() const {
244 return getAttributes().hasAttribute("bss-section") ||
245 getAttributes().hasAttribute("data-section") ||
246 getAttributes().hasAttribute("relro-section") ||
247 getAttributes().hasAttribute("rodata-section");
248 }
249
250 // Methods for support type inquiry through isa, cast, and dyn_cast:
251 static bool classof(const Value *V) {
252 return V->getValueID() == Value::GlobalVariableVal;
253 }
254};
255
256template <>
257struct OperandTraits<GlobalVariable> :
258 public OptionalOperandTraits<GlobalVariable> {
259};
260
261DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalVariable, Value)GlobalVariable::op_iterator GlobalVariable::op_begin() { return
OperandTraits<GlobalVariable>::op_begin(this); } GlobalVariable
::const_op_iterator GlobalVariable::op_begin() const { return
OperandTraits<GlobalVariable>::op_begin(const_cast<
GlobalVariable*>(this)); } GlobalVariable::op_iterator GlobalVariable
::op_end() { return OperandTraits<GlobalVariable>::op_end
(this); } GlobalVariable::const_op_iterator GlobalVariable::op_end
() const { return OperandTraits<GlobalVariable>::op_end
(const_cast<GlobalVariable*>(this)); } Value *GlobalVariable
::getOperand(unsigned i_nocapture) const { ((i_nocapture <
OperandTraits<GlobalVariable>::operands(this) &&
"getOperand() out of range!") ? static_cast<void> (0) :
__assert_fail ("i_nocapture < OperandTraits<GlobalVariable>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h"
, 261, __PRETTY_FUNCTION__)); return cast_or_null<Value>
( OperandTraits<GlobalVariable>::op_begin(const_cast<
GlobalVariable*>(this))[i_nocapture].get()); } void GlobalVariable
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { ((
i_nocapture < OperandTraits<GlobalVariable>::operands
(this) && "setOperand() out of range!") ? static_cast
<void> (0) : __assert_fail ("i_nocapture < OperandTraits<GlobalVariable>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include/llvm/IR/GlobalVariable.h"
, 261, __PRETTY_FUNCTION__)); OperandTraits<GlobalVariable
>::op_begin(this)[i_nocapture] = Val_nocapture; } unsigned
GlobalVariable::getNumOperands() const { return OperandTraits
<GlobalVariable>::operands(this); } template <int Idx_nocapture
> Use &GlobalVariable::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &GlobalVariable::Op() const { return this->
OpFrom<Idx_nocapture>(this); }
262
263} // end namespace llvm
264
265#endif // LLVM_IR_GLOBALVARIABLE_H