Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -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 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-12/lib/clang/12.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/build-llvm/lib/Target/AMDGPU -I /build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/lib/Target/AMDGPU -I /build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/build-llvm/include -I /build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/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-12/lib/clang/12.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-12~++20200917111122+b03c2b8395b/build-llvm/lib/Target/AMDGPU -fdebug-prefix-map=/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b=. -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-09-17-195756-12974-1 -x c++ /build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

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

/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h

1//===- llvm/Type.h - Classes for handling data types ------------*- 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 Type class. For more "Type"
10// stuff, look in DerivedTypes.h.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_TYPE_H
15#define LLVM_IR_TYPE_H
16
17#include "llvm/ADT/APFloat.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/SmallPtrSet.h"
20#include "llvm/Support/CBindingWrapping.h"
21#include "llvm/Support/Casting.h"
22#include "llvm/Support/Compiler.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/TypeSize.h"
25#include <cassert>
26#include <cstdint>
27#include <iterator>
28
29namespace llvm {
30
31template<class GraphType> struct GraphTraits;
32class IntegerType;
33class LLVMContext;
34class PointerType;
35class raw_ostream;
36class StringRef;
37
38/// The instances of the Type class are immutable: once they are created,
39/// they are never changed. Also note that only one instance of a particular
40/// type is ever created. Thus seeing if two types are equal is a matter of
41/// doing a trivial pointer comparison. To enforce that no two equal instances
42/// are created, Type instances can only be created via static factory methods
43/// in class Type and in derived classes. Once allocated, Types are never
44/// free'd.
45///
46class Type {
47public:
48 //===--------------------------------------------------------------------===//
49 /// Definitions of all of the base types for the Type system. Based on this
50 /// value, you can cast to a class defined in DerivedTypes.h.
51 /// Note: If you add an element to this, you need to add an element to the
52 /// Type::getPrimitiveType function, or else things will break!
53 /// Also update LLVMTypeKind and LLVMGetTypeKind () in the C binding.
54 ///
55 enum TypeID {
56 // PrimitiveTypes
57 HalfTyID = 0, ///< 16-bit floating point type
58 BFloatTyID, ///< 16-bit floating point type (7-bit significand)
59 FloatTyID, ///< 32-bit floating point type
60 DoubleTyID, ///< 64-bit floating point type
61 X86_FP80TyID, ///< 80-bit floating point type (X87)
62 FP128TyID, ///< 128-bit floating point type (112-bit significand)
63 PPC_FP128TyID, ///< 128-bit floating point type (two 64-bits, PowerPC)
64 VoidTyID, ///< type with no size
65 LabelTyID, ///< Labels
66 MetadataTyID, ///< Metadata
67 X86_MMXTyID, ///< MMX vectors (64 bits, X86 specific)
68 TokenTyID, ///< Tokens
69
70 // Derived types... see DerivedTypes.h file.
71 IntegerTyID, ///< Arbitrary bit width integers
72 FunctionTyID, ///< Functions
73 PointerTyID, ///< Pointers
74 StructTyID, ///< Structures
75 ArrayTyID, ///< Arrays
76 FixedVectorTyID, ///< Fixed width SIMD vector type
77 ScalableVectorTyID ///< Scalable SIMD vector type
78 };
79
80private:
81 /// This refers to the LLVMContext in which this type was uniqued.
82 LLVMContext &Context;
83
84 TypeID ID : 8; // The current base type of this type.
85 unsigned SubclassData : 24; // Space for subclasses to store data.
86 // Note that this should be synchronized with
87 // MAX_INT_BITS value in IntegerType class.
88
89protected:
90 friend class LLVMContextImpl;
91
92 explicit Type(LLVMContext &C, TypeID tid)
93 : Context(C), ID(tid), SubclassData(0) {}
94 ~Type() = default;
95
96 unsigned getSubclassData() const { return SubclassData; }
97
98 void setSubclassData(unsigned val) {
99 SubclassData = val;
100 // Ensure we don't have any accidental truncation.
101 assert(getSubclassData() == val && "Subclass data too large for field")((getSubclassData() == val && "Subclass data too large for field"
) ? static_cast<void> (0) : __assert_fail ("getSubclassData() == val && \"Subclass data too large for field\""
, "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 101, __PRETTY_FUNCTION__))
;
102 }
103
104 /// Keeps track of how many Type*'s there are in the ContainedTys list.
105 unsigned NumContainedTys = 0;
106
107 /// A pointer to the array of Types contained by this Type. For example, this
108 /// includes the arguments of a function type, the elements of a structure,
109 /// the pointee of a pointer, the element type of an array, etc. This pointer
110 /// may be 0 for types that don't contain other types (Integer, Double,
111 /// Float).
112 Type * const *ContainedTys = nullptr;
113
114public:
115 /// Print the current type.
116 /// Omit the type details if \p NoDetails == true.
117 /// E.g., let %st = type { i32, i16 }
118 /// When \p NoDetails is true, we only print %st.
119 /// Put differently, \p NoDetails prints the type as if
120 /// inlined with the operands when printing an instruction.
121 void print(raw_ostream &O, bool IsForDebug = false,
122 bool NoDetails = false) const;
123
124 void dump() const;
125
126 /// Return the LLVMContext in which this type was uniqued.
127 LLVMContext &getContext() const { return Context; }
128
129 //===--------------------------------------------------------------------===//
130 // Accessors for working with types.
131 //
132
133 /// Return the type id for the type. This will return one of the TypeID enum
134 /// elements defined above.
135 TypeID getTypeID() const { return ID; }
136
137 /// Return true if this is 'void'.
138 bool isVoidTy() const { return getTypeID() == VoidTyID; }
139
140 /// Return true if this is 'half', a 16-bit IEEE fp type.
141 bool isHalfTy() const { return getTypeID() == HalfTyID; }
142
143 /// Return true if this is 'bfloat', a 16-bit bfloat type.
144 bool isBFloatTy() const { return getTypeID() == BFloatTyID; }
145
146 /// Return true if this is 'float', a 32-bit IEEE fp type.
147 bool isFloatTy() const { return getTypeID() == FloatTyID; }
148
149 /// Return true if this is 'double', a 64-bit IEEE fp type.
150 bool isDoubleTy() const { return getTypeID() == DoubleTyID; }
151
152 /// Return true if this is x86 long double.
153 bool isX86_FP80Ty() const { return getTypeID() == X86_FP80TyID; }
154
155 /// Return true if this is 'fp128'.
156 bool isFP128Ty() const { return getTypeID() == FP128TyID; }
157
158 /// Return true if this is powerpc long double.
159 bool isPPC_FP128Ty() const { return getTypeID() == PPC_FP128TyID; }
160
161 /// Return true if this is one of the six floating-point types
162 bool isFloatingPointTy() const {
163 return getTypeID() == HalfTyID || getTypeID() == BFloatTyID ||
23
Assuming the condition is false
24
Assuming the condition is false
30
Returning zero, which participates in a condition later
164 getTypeID() == FloatTyID || getTypeID() == DoubleTyID ||
25
Assuming the condition is false
26
Assuming the condition is false
165 getTypeID() == X86_FP80TyID || getTypeID() == FP128TyID ||
27
Assuming the condition is false
28
Assuming the condition is false
166 getTypeID() == PPC_FP128TyID;
29
Assuming the condition is false
167 }
168
169 const fltSemantics &getFltSemantics() const {
170 switch (getTypeID()) {
171 case HalfTyID: return APFloat::IEEEhalf();
172 case BFloatTyID: return APFloat::BFloat();
173 case FloatTyID: return APFloat::IEEEsingle();
174 case DoubleTyID: return APFloat::IEEEdouble();
175 case X86_FP80TyID: return APFloat::x87DoubleExtended();
176 case FP128TyID: return APFloat::IEEEquad();
177 case PPC_FP128TyID: return APFloat::PPCDoubleDouble();
178 default: llvm_unreachable("Invalid floating type")::llvm::llvm_unreachable_internal("Invalid floating type", "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 178)
;
179 }
180 }
181
182 /// Return true if this is X86 MMX.
183 bool isX86_MMXTy() const { return getTypeID() == X86_MMXTyID; }
184
185 /// Return true if this is a FP type or a vector of FP.
186 bool isFPOrFPVectorTy() const { return getScalarType()->isFloatingPointTy(); }
22
Calling 'Type::isFloatingPointTy'
31
Returning from 'Type::isFloatingPointTy'
32
Returning zero, which participates in a condition later
187
188 /// Return true if this is 'label'.
189 bool isLabelTy() const { return getTypeID() == LabelTyID; }
190
191 /// Return true if this is 'metadata'.
192 bool isMetadataTy() const { return getTypeID() == MetadataTyID; }
193
194 /// Return true if this is 'token'.
195 bool isTokenTy() const { return getTypeID() == TokenTyID; }
196
197 /// True if this is an instance of IntegerType.
198 bool isIntegerTy() const { return getTypeID() == IntegerTyID; }
199
200 /// Return true if this is an IntegerType of the given width.
201 bool isIntegerTy(unsigned Bitwidth) const;
202
203 /// Return true if this is an integer type or a vector of integer types.
204 bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); }
205
206 /// Return true if this is an integer type or a vector of integer types of
207 /// the given width.
208 bool isIntOrIntVectorTy(unsigned BitWidth) const {
209 return getScalarType()->isIntegerTy(BitWidth);
210 }
211
212 /// Return true if this is an integer type or a pointer type.
213 bool isIntOrPtrTy() const { return isIntegerTy() || isPointerTy(); }
214
215 /// True if this is an instance of FunctionType.
216 bool isFunctionTy() const { return getTypeID() == FunctionTyID; }
217
218 /// True if this is an instance of StructType.
219 bool isStructTy() const { return getTypeID() == StructTyID; }
220
221 /// True if this is an instance of ArrayType.
222 bool isArrayTy() const { return getTypeID() == ArrayTyID; }
223
224 /// True if this is an instance of PointerType.
225 bool isPointerTy() const { return getTypeID() == PointerTyID; }
226
227 /// Return true if this is a pointer type or a vector of pointer types.
228 bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); }
229
230 /// True if this is an instance of VectorType.
231 inline bool isVectorTy() const {
232 return getTypeID() == ScalableVectorTyID || getTypeID() == FixedVectorTyID;
233 }
234
235 /// Return true if this type could be converted with a lossless BitCast to
236 /// type 'Ty'. For example, i8* to i32*. BitCasts are valid for types of the
237 /// same size only where no re-interpretation of the bits is done.
238 /// Determine if this type could be losslessly bitcast to Ty
239 bool canLosslesslyBitCastTo(Type *Ty) const;
240
241 /// Return true if this type is empty, that is, it has no elements or all of
242 /// its elements are empty.
243 bool isEmptyTy() const;
244
245 /// Return true if the type is "first class", meaning it is a valid type for a
246 /// Value.
247 bool isFirstClassType() const {
248 return getTypeID() != FunctionTyID && getTypeID() != VoidTyID;
249 }
250
251 /// Return true if the type is a valid type for a register in codegen. This
252 /// includes all first-class types except struct and array types.
253 bool isSingleValueType() const {
254 return isFloatingPointTy() || isX86_MMXTy() || isIntegerTy() ||
255 isPointerTy() || isVectorTy();
256 }
257
258 /// Return true if the type is an aggregate type. This means it is valid as
259 /// the first operand of an insertvalue or extractvalue instruction. This
260 /// includes struct and array types, but does not include vector types.
261 bool isAggregateType() const {
262 return getTypeID() == StructTyID || getTypeID() == ArrayTyID;
263 }
264
265 /// Return true if it makes sense to take the size of this type. To get the
266 /// actual size for a particular target, it is reasonable to use the
267 /// DataLayout subsystem to do this.
268 bool isSized(SmallPtrSetImpl<Type*> *Visited = nullptr) const {
269 // If it's a primitive, it is always sized.
270 if (getTypeID() == IntegerTyID || isFloatingPointTy() ||
271 getTypeID() == PointerTyID ||
272 getTypeID() == X86_MMXTyID)
273 return true;
274 // If it is not something that can have a size (e.g. a function or label),
275 // it doesn't have a size.
276 if (getTypeID() != StructTyID && getTypeID() != ArrayTyID && !isVectorTy())
277 return false;
278 // Otherwise we have to try harder to decide.
279 return isSizedDerivedType(Visited);
280 }
281
282 /// Return the basic size of this type if it is a primitive type. These are
283 /// fixed by LLVM and are not target-dependent.
284 /// This will return zero if the type does not have a size or is not a
285 /// primitive type.
286 ///
287 /// If this is a scalable vector type, the scalable property will be set and
288 /// the runtime size will be a positive integer multiple of the base size.
289 ///
290 /// Note that this may not reflect the size of memory allocated for an
291 /// instance of the type or the number of bytes that are written when an
292 /// instance of the type is stored to memory. The DataLayout class provides
293 /// additional query functions to provide this information.
294 ///
295 TypeSize getPrimitiveSizeInBits() const LLVM_READONLY__attribute__((__pure__));
296
297 /// If this is a vector type, return the getPrimitiveSizeInBits value for the
298 /// element type. Otherwise return the getPrimitiveSizeInBits value for this
299 /// type.
300 unsigned getScalarSizeInBits() const LLVM_READONLY__attribute__((__pure__));
301
302 /// Return the width of the mantissa of this type. This is only valid on
303 /// floating-point types. If the FP type does not have a stable mantissa (e.g.
304 /// ppc long double), this method returns -1.
305 int getFPMantissaWidth() const;
306
307 /// If this is a vector type, return the element type, otherwise return
308 /// 'this'.
309 inline Type *getScalarType() const {
310 if (isVectorTy())
311 return getContainedType(0);
312 return const_cast<Type *>(this);
313 }
314
315 //===--------------------------------------------------------------------===//
316 // Type Iteration support.
317 //
318 using subtype_iterator = Type * const *;
319
320 subtype_iterator subtype_begin() const { return ContainedTys; }
321 subtype_iterator subtype_end() const { return &ContainedTys[NumContainedTys];}
322 ArrayRef<Type*> subtypes() const {
323 return makeArrayRef(subtype_begin(), subtype_end());
324 }
325
326 using subtype_reverse_iterator = std::reverse_iterator<subtype_iterator>;
327
328 subtype_reverse_iterator subtype_rbegin() const {
329 return subtype_reverse_iterator(subtype_end());
330 }
331 subtype_reverse_iterator subtype_rend() const {
332 return subtype_reverse_iterator(subtype_begin());
333 }
334
335 /// This method is used to implement the type iterator (defined at the end of
336 /// the file). For derived types, this returns the types 'contained' in the
337 /// derived type.
338 Type *getContainedType(unsigned i) const {
339 assert(i < NumContainedTys && "Index out of range!")((i < NumContainedTys && "Index out of range!") ? static_cast
<void> (0) : __assert_fail ("i < NumContainedTys && \"Index out of range!\""
, "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 339, __PRETTY_FUNCTION__))
;
340 return ContainedTys[i];
341 }
342
343 /// Return the number of types in the derived type.
344 unsigned getNumContainedTypes() const { return NumContainedTys; }
345
346 //===--------------------------------------------------------------------===//
347 // Helper methods corresponding to subclass methods. This forces a cast to
348 // the specified subclass and calls its accessor. "getArrayNumElements" (for
349 // example) is shorthand for cast<ArrayType>(Ty)->getNumElements(). This is
350 // only intended to cover the core methods that are frequently used, helper
351 // methods should not be added here.
352
353 inline unsigned getIntegerBitWidth() const;
354
355 inline Type *getFunctionParamType(unsigned i) const;
356 inline unsigned getFunctionNumParams() const;
357 inline bool isFunctionVarArg() const;
358
359 inline StringRef getStructName() const;
360 inline unsigned getStructNumElements() const;
361 inline Type *getStructElementType(unsigned N) const;
362
363 inline uint64_t getArrayNumElements() const;
364
365 Type *getArrayElementType() const {
366 assert(getTypeID() == ArrayTyID)((getTypeID() == ArrayTyID) ? static_cast<void> (0) : __assert_fail
("getTypeID() == ArrayTyID", "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 366, __PRETTY_FUNCTION__))
;
367 return ContainedTys[0];
368 }
369
370 Type *getPointerElementType() const {
371 assert(getTypeID() == PointerTyID)((getTypeID() == PointerTyID) ? static_cast<void> (0) :
__assert_fail ("getTypeID() == PointerTyID", "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 371, __PRETTY_FUNCTION__))
;
372 return ContainedTys[0];
373 }
374
375 /// Given an integer or vector type, change the lane bitwidth to NewBitwidth,
376 /// whilst keeping the old number of lanes.
377 inline Type *getWithNewBitWidth(unsigned NewBitWidth) const;
378
379 /// Given scalar/vector integer type, returns a type with elements twice as
380 /// wide as in the original type. For vectors, preserves element count.
381 inline Type *getExtendedType() const;
382
383 /// Get the address space of this pointer or pointer vector type.
384 inline unsigned getPointerAddressSpace() const;
385
386 //===--------------------------------------------------------------------===//
387 // Static members exported by the Type class itself. Useful for getting
388 // instances of Type.
389 //
390
391 /// Return a type based on an identifier.
392 static Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber);
393
394 //===--------------------------------------------------------------------===//
395 // These are the builtin types that are always available.
396 //
397 static Type *getVoidTy(LLVMContext &C);
398 static Type *getLabelTy(LLVMContext &C);
399 static Type *getHalfTy(LLVMContext &C);
400 static Type *getBFloatTy(LLVMContext &C);
401 static Type *getFloatTy(LLVMContext &C);
402 static Type *getDoubleTy(LLVMContext &C);
403 static Type *getMetadataTy(LLVMContext &C);
404 static Type *getX86_FP80Ty(LLVMContext &C);
405 static Type *getFP128Ty(LLVMContext &C);
406 static Type *getPPC_FP128Ty(LLVMContext &C);
407 static Type *getX86_MMXTy(LLVMContext &C);
408 static Type *getTokenTy(LLVMContext &C);
409 static IntegerType *getIntNTy(LLVMContext &C, unsigned N);
410 static IntegerType *getInt1Ty(LLVMContext &C);
411 static IntegerType *getInt8Ty(LLVMContext &C);
412 static IntegerType *getInt16Ty(LLVMContext &C);
413 static IntegerType *getInt32Ty(LLVMContext &C);
414 static IntegerType *getInt64Ty(LLVMContext &C);
415 static IntegerType *getInt128Ty(LLVMContext &C);
416 template <typename ScalarTy> static Type *getScalarTy(LLVMContext &C) {
417 int noOfBits = sizeof(ScalarTy) * CHAR_BIT8;
418 if (std::is_integral<ScalarTy>::value) {
419 return (Type*) Type::getIntNTy(C, noOfBits);
420 } else if (std::is_floating_point<ScalarTy>::value) {
421 switch (noOfBits) {
422 case 32:
423 return Type::getFloatTy(C);
424 case 64:
425 return Type::getDoubleTy(C);
426 }
427 }
428 llvm_unreachable("Unsupported type in Type::getScalarTy")::llvm::llvm_unreachable_internal("Unsupported type in Type::getScalarTy"
, "/build/llvm-toolchain-snapshot-12~++20200917111122+b03c2b8395b/llvm/include/llvm/IR/Type.h"
, 428)
;
429 }
430
431 //===--------------------------------------------------------------------===//
432 // Convenience methods for getting pointer types with one of the above builtin
433 // types as pointee.
434 //
435 static PointerType *getHalfPtrTy(LLVMContext &C, unsigned AS = 0);
436 static PointerType *getBFloatPtrTy(LLVMContext &C, unsigned AS = 0);
437 static PointerType *getFloatPtrTy(LLVMContext &C, unsigned AS = 0);
438 static PointerType *getDoublePtrTy(LLVMContext &C, unsigned AS = 0);
439 static PointerType *getX86_FP80PtrTy(LLVMContext &C, unsigned AS = 0);
440 static PointerType *getFP128PtrTy(LLVMContext &C, unsigned AS = 0);
441 static PointerType *getPPC_FP128PtrTy(LLVMContext &C, unsigned AS = 0);
442 static PointerType *getX86_MMXPtrTy(LLVMContext &C, unsigned AS = 0);
443 static PointerType *getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS = 0);
444 static PointerType *getInt1PtrTy(LLVMContext &C, unsigned AS = 0);
445 static PointerType *getInt8PtrTy(LLVMContext &C, unsigned AS = 0);
446 static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
447 static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
448 static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
449
450 /// Return a pointer to the current type. This is equivalent to
451 /// PointerType::get(Foo, AddrSpace).
452 PointerType *getPointerTo(unsigned AddrSpace = 0) const;
453
454private:
455 /// Derived types like structures and arrays are sized iff all of the members
456 /// of the type are sized as well. Since asking for their size is relatively
457 /// uncommon, move this operation out-of-line.
458 bool isSizedDerivedType(SmallPtrSetImpl<Type*> *Visited = nullptr) const;
459};
460
461// Printing of types.
462inline raw_ostream &operator<<(raw_ostream &OS, const Type &T) {
463 T.print(OS);
464 return OS;
465}
466
467// allow isa<PointerType>(x) to work without DerivedTypes.h included.
468template <> struct isa_impl<PointerType, Type> {
469 static inline bool doit(const Type &Ty) {
470 return Ty.getTypeID() == Type::PointerTyID;
471 }
472};
473
474// Create wrappers for C Binding types (see CBindingWrapping.h).
475DEFINE_ISA_CONVERSION_FUNCTIONS(Type, LLVMTypeRef)inline Type *unwrap(LLVMTypeRef P) { return reinterpret_cast<
Type*>(P); } inline LLVMTypeRef wrap(const Type *P) { return
reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(
P)); } template<typename T> inline T *unwrap(LLVMTypeRef
P) { return cast<T>(unwrap(P)); }
476
477/* Specialized opaque type conversions.
478 */
479inline Type **unwrap(LLVMTypeRef* Tys) {
480 return reinterpret_cast<Type**>(Tys);
481}
482
483inline LLVMTypeRef *wrap(Type **Tys) {
484 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
485}
486
487} // end namespace llvm
488
489#endif // LLVM_IR_TYPE_H

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