LLVM 17.0.0git
Globals.cpp
Go to the documentation of this file.
1//===-- Globals.cpp - Implement the GlobalValue & GlobalVariable class ----===//
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 implements the GlobalValue & GlobalVariable classes for the IR
10// library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "LLVMContextImpl.h"
16#include "llvm/IR/Constants.h"
18#include "llvm/IR/GlobalAlias.h"
19#include "llvm/IR/GlobalValue.h"
21#include "llvm/IR/Module.h"
22#include "llvm/Support/Error.h"
25using namespace llvm;
26
27//===----------------------------------------------------------------------===//
28// GlobalValue Class
29//===----------------------------------------------------------------------===//
30
31// GlobalValue should be a Constant, plus a type, a module, some flags, and an
32// intrinsic ID. Add an assert to prevent people from accidentally growing
33// GlobalValue while adding flags.
34static_assert(sizeof(GlobalValue) ==
35 sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned),
36 "unexpected GlobalValue size growth");
37
38// GlobalObject adds a comdat.
39static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *),
40 "unexpected GlobalObject size growth");
41
43 if (const Function *F = dyn_cast<Function>(this))
44 return F->isMaterializable();
45 return false;
46}
48
49/// Override destroyConstantImpl to make sure it doesn't get called on
50/// GlobalValue's because they shouldn't be treated like other constants.
51void GlobalValue::destroyConstantImpl() {
52 llvm_unreachable("You can't GV->destroyConstantImpl()!");
53}
54
55Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
56 llvm_unreachable("Unsupported class for handleOperandChange()!");
57}
58
59/// copyAttributesFrom - copy all additional attributes (those not needed to
60/// create a GlobalValue) from the GlobalValue Src to this one.
62 setVisibility(Src->getVisibility());
63 setUnnamedAddr(Src->getUnnamedAddr());
64 setThreadLocalMode(Src->getThreadLocalMode());
65 setDLLStorageClass(Src->getDLLStorageClass());
66 setDSOLocal(Src->isDSOLocal());
67 setPartition(Src->getPartition());
68 if (Src->hasSanitizerMetadata())
69 setSanitizerMetadata(Src->getSanitizerMetadata());
70 else
72}
73
75 switch (getValueID()) {
76#define HANDLE_GLOBAL_VALUE(NAME) \
77 case Value::NAME##Val: \
78 return static_cast<NAME *>(this)->removeFromParent();
79#include "llvm/IR/Value.def"
80 default:
81 break;
82 }
83 llvm_unreachable("not a global");
84}
85
87 switch (getValueID()) {
88#define HANDLE_GLOBAL_VALUE(NAME) \
89 case Value::NAME##Val: \
90 return static_cast<NAME *>(this)->eraseFromParent();
91#include "llvm/IR/Value.def"
92 default:
93 break;
94 }
95 llvm_unreachable("not a global");
96}
97
99
102 return true;
104 !isDSOLocal();
105}
106
108 // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
109 // references to a discarded local symbol from outside the group are not
110 // allowed, so avoid the local alias.
111 auto isDeduplicateComdat = [](const Comdat *C) {
112 return C && C->getSelectionKind() != Comdat::NoDeduplicate;
113 };
114 return hasDefaultVisibility() &&
116 !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
117}
118
121 "Alignment is greater than MaximumAlignment!");
122 unsigned AlignmentData = encode(Align);
123 unsigned OldData = getGlobalValueSubClassData();
124 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
125 assert(getAlign() == Align && "Alignment representation error!");
126}
127
130 "Alignment is greater than MaximumAlignment!");
131 unsigned AlignmentData = encode(Align);
132 unsigned OldData = getGlobalValueSubClassData();
133 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
134 assert(getAlign() && *getAlign() == Align &&
135 "Alignment representation error!");
136}
137
140 setAlignment(Src->getAlign());
141 setSection(Src->getSection());
142}
143
146 StringRef FileName) {
147
148 // Value names may be prefixed with a binary '1' to indicate
149 // that the backend should not modify the symbols due to any platform
150 // naming convention. Do not include that '1' in the PGO profile name.
151 if (Name[0] == '\1')
152 Name = Name.substr(1);
153
154 std::string NewName = std::string(Name);
156 // For local symbols, prepend the main file name to distinguish them.
157 // Do not include the full path in the file name since there's no guarantee
158 // that it will stay the same, e.g., if the files are checked out from
159 // version control in different locations.
160 if (FileName.empty())
161 NewName = NewName.insert(0, "<unknown>:");
162 else
163 NewName = NewName.insert(0, FileName.str() + ":");
164 }
165 return NewName;
166}
167
170 getParent()->getSourceFileName());
171}
172
174 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
175 // In general we cannot compute this at the IR level, but we try.
176 if (const GlobalObject *GO = GA->getAliaseeObject())
177 return GO->getSection();
178 return "";
179 }
180 return cast<GlobalObject>(this)->getSection();
181}
182
184 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
185 // In general we cannot compute this at the IR level, but we try.
186 if (const GlobalObject *GO = GA->getAliaseeObject())
187 return const_cast<GlobalObject *>(GO)->getComdat();
188 return nullptr;
189 }
190 // ifunc and its resolver are separate things so don't use resolver comdat.
191 if (isa<GlobalIFunc>(this))
192 return nullptr;
193 return cast<GlobalObject>(this)->getComdat();
194}
195
197 if (ObjComdat)
198 ObjComdat->removeUser(this);
199 ObjComdat = C;
200 if (C)
201 C->addUser(this);
202}
203
205 if (!hasPartition())
206 return "";
207 return getContext().pImpl->GlobalValuePartitions[this];
208}
209
211 // Do nothing if we're clearing the partition and it is already empty.
212 if (!hasPartition() && S.empty())
213 return;
214
215 // Get or create a stable partition name string and put it in the table in the
216 // context.
217 if (!S.empty())
218 S = getContext().pImpl->Saver.save(S);
220
221 // Update the HasPartition field. Setting the partition to the empty string
222 // means this global no longer has a partition.
223 HasPartition = !S.empty();
224}
225
229 assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
231}
232
236}
237
241 MetadataMap.erase(this);
242 HasSanitizerMetadata = false;
243}
244
245StringRef GlobalObject::getSectionImpl() const {
247 return getContext().pImpl->GlobalObjectSections[this];
248}
249
251 // Do nothing if we're clearing the section and it is already empty.
252 if (!hasSection() && S.empty())
253 return;
254
255 // Get or create a stable section name string and put it in the table in the
256 // context.
257 if (!S.empty())
258 S = getContext().pImpl->Saver.save(S);
260
261 // Update the HasSectionHashEntryBit. Setting the section to the empty string
262 // means this global no longer has a section.
263 setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
264}
265
266bool GlobalValue::isNobuiltinFnDef() const {
267 const Function *F = dyn_cast<Function>(this);
268 if (!F || F->empty())
269 return false;
270 return F->hasFnAttribute(Attribute::NoBuiltin);
271}
272
274 // Globals are definitions if they have an initializer.
275 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
276 return GV->getNumOperands() == 0;
277
278 // Functions are definitions if they have a body.
279 if (const Function *F = dyn_cast<Function>(this))
280 return F->empty() && !F->isMaterializable();
281
282 // Aliases and ifuncs are always definitions.
283 assert(isa<GlobalAlias>(this) || isa<GlobalIFunc>(this));
284 return false;
285}
286
288 // Firstly, can only increase the alignment of a global if it
289 // is a strong definition.
291 return false;
292
293 // It also has to either not have a section defined, or, not have
294 // alignment specified. (If it is assigned a section, the global
295 // could be densely packed with other objects in the section, and
296 // increasing the alignment could cause padding issues.)
297 if (hasSection() && getAlign())
298 return false;
299
300 // On ELF platforms, we're further restricted in that we can't
301 // increase the alignment of any variable which might be emitted
302 // into a shared library, and which is exported. If the main
303 // executable accesses a variable found in a shared-lib, the main
304 // exe actually allocates memory for and exports the symbol ITSELF,
305 // overriding the symbol found in the library. That is, at link
306 // time, the observed alignment of the variable is copied into the
307 // executable binary. (A COPY relocation is also generated, to copy
308 // the initial data from the shadowed variable in the shared-lib
309 // into the location in the main binary, before running code.)
310 //
311 // And thus, even though you might think you are defining the
312 // global, and allocating the memory for the global in your object
313 // file, and thus should be able to set the alignment arbitrarily,
314 // that's not actually true. Doing so can cause an ABI breakage; an
315 // executable might have already been built with the previous
316 // alignment of the variable, and then assuming an increased
317 // alignment will be incorrect.
318
319 // Conservatively assume ELF if there's no parent pointer.
320 bool isELF =
322 if (isELF && !isDSOLocal())
323 return false;
324
325 return true;
326}
327
328template <typename Operation>
329static const GlobalObject *
331 const Operation &Op) {
332 if (auto *GO = dyn_cast<GlobalObject>(C)) {
333 Op(*GO);
334 return GO;
335 }
336 if (auto *GA = dyn_cast<GlobalAlias>(C)) {
337 Op(*GA);
338 if (Aliases.insert(GA).second)
339 return findBaseObject(GA->getOperand(0), Aliases, Op);
340 }
341 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
342 switch (CE->getOpcode()) {
343 case Instruction::Add: {
344 auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
345 auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
346 if (LHS && RHS)
347 return nullptr;
348 return LHS ? LHS : RHS;
349 }
350 case Instruction::Sub: {
351 if (findBaseObject(CE->getOperand(1), Aliases, Op))
352 return nullptr;
353 return findBaseObject(CE->getOperand(0), Aliases, Op);
354 }
355 case Instruction::IntToPtr:
356 case Instruction::PtrToInt:
357 case Instruction::BitCast:
358 case Instruction::GetElementPtr:
359 return findBaseObject(CE->getOperand(0), Aliases, Op);
360 default:
361 break;
362 }
363 }
364 return nullptr;
365}
366
369 return findBaseObject(this, Aliases, [](const GlobalValue &) {});
370}
371
373 auto *GO = dyn_cast<GlobalObject>(this);
374 if (!GO)
375 return false;
376
377 return GO->getMetadata(LLVMContext::MD_absolute_symbol);
378}
379
380std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
381 auto *GO = dyn_cast<GlobalObject>(this);
382 if (!GO)
383 return std::nullopt;
384
385 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
386 if (!MD)
387 return std::nullopt;
388
390}
391
394 return false;
395
396 // We assume that anyone who sets global unnamed_addr on a non-constant
397 // knows what they're doing.
399 return true;
400
401 // If it is a non constant variable, it needs to be uniqued across shared
402 // objects.
403 if (auto *Var = dyn_cast<GlobalVariable>(this))
404 if (!Var->isConstant())
405 return false;
406
408}
409
410//===----------------------------------------------------------------------===//
411// GlobalVariable Implementation
412//===----------------------------------------------------------------------===//
413
415 Constant *InitVal, const Twine &Name,
416 ThreadLocalMode TLMode, unsigned AddressSpace,
417 bool isExternallyInitialized)
418 : GlobalObject(Ty, Value::GlobalVariableVal,
419 OperandTraits<GlobalVariable>::op_begin(this),
420 InitVal != nullptr, Link, Name, AddressSpace),
421 isConstantGlobal(constant),
422 isExternallyInitializedConstant(isExternallyInitialized) {
424 "invalid type for global variable");
425 setThreadLocalMode(TLMode);
426 if (InitVal) {
427 assert(InitVal->getType() == Ty &&
428 "Initializer should be the same type as the GlobalVariable!");
429 Op<0>() = InitVal;
430 }
431}
432
434 LinkageTypes Link, Constant *InitVal,
435 const Twine &Name, GlobalVariable *Before,
436 ThreadLocalMode TLMode,
437 std::optional<unsigned> AddressSpace,
438 bool isExternallyInitialized)
439 : GlobalVariable(Ty, constant, Link, InitVal, Name, TLMode,
441 ? *AddressSpace
442 : M.getDataLayout().getDefaultGlobalsAddressSpace(),
443 isExternallyInitialized) {
444 if (Before)
445 Before->getParent()->insertGlobalVariable(Before->getIterator(), this);
446 else
447 M.insertGlobalVariable(this);
448}
449
452}
453
456}
457
459 if (!InitVal) {
460 if (hasInitializer()) {
461 // Note, the num operands is used to compute the offset of the operand, so
462 // the order here matters. Clearing the operand then clearing the num
463 // operands ensures we have the correct offset to the operand.
464 Op<0>().set(nullptr);
466 }
467 } else {
468 assert(InitVal->getType() == getValueType() &&
469 "Initializer type must match GlobalVariable type");
470 // Note, the num operands is used to compute the offset of the operand, so
471 // the order here matters. We need to set num operands to 1 first so that
472 // we get the correct offset to the first operand when we set it.
473 if (!hasInitializer())
475 Op<0>().set(InitVal);
476 }
477}
478
479/// Copy all additional attributes (those not needed to create a GlobalVariable)
480/// from the GlobalVariable Src to this one.
483 setExternallyInitialized(Src->isExternallyInitialized());
484 setAttributes(Src->getAttributes());
485}
486
490}
491
492//===----------------------------------------------------------------------===//
493// GlobalAlias Implementation
494//===----------------------------------------------------------------------===//
495
496GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
497 const Twine &Name, Constant *Aliasee,
498 Module *ParentModule)
499 : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
500 AddressSpace) {
501 setAliasee(Aliasee);
502 if (ParentModule)
503 ParentModule->insertAlias(this);
504}
505
507 LinkageTypes Link, const Twine &Name,
508 Constant *Aliasee, Module *ParentModule) {
509 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
510}
511
513 LinkageTypes Linkage, const Twine &Name,
514 Module *Parent) {
515 return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
516}
517
519 LinkageTypes Linkage, const Twine &Name,
520 GlobalValue *Aliasee) {
521 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
522}
523
525 GlobalValue *Aliasee) {
526 return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
527 Aliasee);
528}
529
531 return create(Aliasee->getLinkage(), Name, Aliasee);
532}
533
535
537
539 assert((!Aliasee || Aliasee->getType() == getType()) &&
540 "Alias and aliasee types should match!");
541 Op<0>().set(Aliasee);
542}
543
546 return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
547}
548
549//===----------------------------------------------------------------------===//
550// GlobalIFunc Implementation
551//===----------------------------------------------------------------------===//
552
553GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
554 const Twine &Name, Constant *Resolver,
555 Module *ParentModule)
556 : GlobalObject(Ty, Value::GlobalIFuncVal, &Op<0>(), 1, Link, Name,
557 AddressSpace) {
558 setResolver(Resolver);
559 if (ParentModule)
560 ParentModule->insertIFunc(this);
561}
562
564 LinkageTypes Link, const Twine &Name,
565 Constant *Resolver, Module *ParentModule) {
566 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
567}
568
570
572
574 return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
575}
576
578 function_ref<void(const GlobalValue &)> Op) const {
580 findBaseObject(getResolver(), Aliases, Op);
581}
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias * > &Aliases, const Operation &Op)
Definition: Globals.cpp:330
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
PowerPC Reduce CR logical Operation
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:39
This is an important base class in LLVM.
Definition: Constant.h:41
bool erase(const KeyT &Val)
Definition: DenseMap.h:329
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:536
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:544
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:538
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:506
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:534
void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition: Globals.cpp:577
const Function * getResolverFunction() const
Definition: Globals.cpp:573
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:569
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:563
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:571
const Constant * getResolver() const
Definition: GlobalIFunc.h:70
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:79
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition: Globals.cpp:128
void setComdat(Comdat *C)
Definition: Globals.cpp:196
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:138
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:250
void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1448
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:109
bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition: Globals.cpp:287
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
Definition: GlobalValue.h:118
bool hasPartition() const
Definition: GlobalValue.h:305
const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:227
bool isDSOLocal() const
Definition: GlobalValue.h:301
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
Definition: GlobalValue.h:113
void removeSanitizerMetadata()
Definition: Globals.cpp:238
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:404
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:273
LinkageTypes getLinkage() const
Definition: GlobalValue.h:541
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:227
bool hasDefaultVisibility() const
Definition: GlobalValue.h:245
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:372
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:280
const Comdat * getComdat() const
Definition: Globals.cpp:183
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:263
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:351
unsigned getAddressSpace() const
Definition: GlobalValue.h:201
StringRef getSection() const
Definition: Globals.cpp:173
StringRef getPartition() const
Definition: Globals.cpp:204
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:367
void setDSOLocal(bool Local)
Definition: GlobalValue.h:299
std::optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns std::null...
Definition: Globals.cpp:380
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:86
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:371
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Definition: GlobalValue.h:627
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:290
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:61
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:100
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:250
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:107
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:420
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: GlobalValue.h:220
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:171
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:174
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
Definition: Globals.cpp:42
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:211
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:47
unsigned Linkage
Definition: GlobalValue.h:94
void setSanitizerMetadata(SanitizerMetadata Meta)
Definition: Globals.cpp:233
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:514
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:392
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:74
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
Definition: Globals.cpp:168
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
Type * getValueType() const
Definition: GlobalValue.h:292
void setPartition(StringRef Part)
Definition: Globals.cpp:210
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:458
bool hasInitializer() const
Definitions have initializers, declarations don't.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:450
void setAttributes(AttributeSet A)
Set attribute list for this global.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:481
void setExternallyInitialized(bool Val)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:454
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition: Globals.cpp:487
GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Linkage, Constant *Initializer=nullptr, const Twine &Name="", ThreadLocalMode=NotThreadLocal, unsigned AddressSpace=0, bool isExternallyInitialized=false)
GlobalVariable ctor - If a parent module is specified, the global is automatically inserted into the ...
Definition: Globals.cpp:414
DenseMap< const GlobalValue *, StringRef > GlobalValuePartitions
Collection of per-GlobalValue partitions used in this context.
DenseMap< const GlobalValue *, GlobalValue::SanitizerMetadata > GlobalValueSanitizerMetadata
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
UniqueStringSaver Saver
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
Metadata node.
Definition: Metadata.h:950
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition: Module.h:596
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition: Module.h:600
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:439
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
Definition: Module.cpp:648
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition: Module.h:587
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:258
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition: Module.h:598
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition: Module.h:589
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition: Module.h:548
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
Definition: Module.h:551
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition: Module.h:591
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition: Module.h:546
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:845
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2105
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:675
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:247
StringRef save(const char *S)
Definition: StringSaver.h:52
void dropAllReferences()
Drop all references to operands.
Definition: User.h:299
Use & Op()
Definition: User.h:133
void setGlobalVariableNumOperands(unsigned NumOps)
Set the number of operands on a GlobalVariable.
Definition: User.h:207
Value * getOperand(unsigned i) const
Definition: User.h:169
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
static constexpr uint64_t MaximumAlignment
Definition: Value.h:795
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:692
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1069
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
Definition: ilist_node.h:82
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:217
AddressSpace
Definition: NVPTXBaseInfo.h:21
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Compile-time customization of User operands.
Definition: User.h:42