LLVM  10.0.0svn
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"
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/IR/ConstantRange.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/GlobalAlias.h"
21 #include "llvm/IR/GlobalValue.h"
22 #include "llvm/IR/GlobalVariable.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/Operator.h"
25 #include "llvm/Support/Error.h"
27 using namespace llvm;
28 
29 //===----------------------------------------------------------------------===//
30 // GlobalValue Class
31 //===----------------------------------------------------------------------===//
32 
33 // GlobalValue should be a Constant, plus a type, a module, some flags, and an
34 // intrinsic ID. Add an assert to prevent people from accidentally growing
35 // GlobalValue while adding flags.
36 static_assert(sizeof(GlobalValue) ==
37  sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned),
38  "unexpected GlobalValue size growth");
39 
40 // GlobalObject adds a comdat.
41 static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *),
42  "unexpected GlobalObject size growth");
43 
45  if (const Function *F = dyn_cast<Function>(this))
46  return F->isMaterializable();
47  return false;
48 }
50  return getParent()->materialize(this);
51 }
52 
53 /// Override destroyConstantImpl to make sure it doesn't get called on
54 /// GlobalValue's because they shouldn't be treated like other constants.
55 void GlobalValue::destroyConstantImpl() {
56  llvm_unreachable("You can't GV->destroyConstantImpl()!");
57 }
58 
59 Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
60  llvm_unreachable("Unsupported class for handleOperandChange()!");
61 }
62 
63 /// copyAttributesFrom - copy all additional attributes (those not needed to
64 /// create a GlobalValue) from the GlobalValue Src to this one.
69  setDSOLocal(Src->isDSOLocal());
70  setPartition(Src->getPartition());
71 }
72 
74  switch (getValueID()) {
75 #define HANDLE_GLOBAL_VALUE(NAME) \
76  case Value::NAME##Val: \
77  return static_cast<NAME *>(this)->removeFromParent();
78 #include "llvm/IR/Value.def"
79  default:
80  break;
81  }
82  llvm_unreachable("not a global");
83 }
84 
86  switch (getValueID()) {
87 #define HANDLE_GLOBAL_VALUE(NAME) \
88  case Value::NAME##Val: \
89  return static_cast<NAME *>(this)->eraseFromParent();
90 #include "llvm/IR/Value.def"
91  default:
92  break;
93  }
94  llvm_unreachable("not a global");
95 }
96 
97 unsigned GlobalValue::getAlignment() const {
98  if (auto *GA = dyn_cast<GlobalAlias>(this)) {
99  // In general we cannot compute this at the IR level, but we try.
100  if (const GlobalObject *GO = GA->getBaseObject())
101  return GO->getAlignment();
102 
103  // FIXME: we should also be able to handle:
104  // Alias = Global + Offset
105  // Alias = Absolute
106  return 0;
107  }
108  return cast<GlobalObject>(this)->getAlignment();
109 }
110 
112  PointerType *PtrTy = getType();
113  return PtrTy->getAddressSpace();
114 }
115 
117  setAlignment(MaybeAlign(Align));
118 }
119 
121  assert((!Align || Align <= MaximumAlignment) &&
122  "Alignment is greater than MaximumAlignment!");
123  unsigned AlignmentData = encode(Align);
124  unsigned OldData = getGlobalValueSubClassData();
125  setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
126  assert(MaybeAlign(getAlignment()) == Align &&
127  "Alignment representation error!");
128 }
129 
132  setAlignment(MaybeAlign(Src->getAlignment()));
133  setSection(Src->getSection());
134 }
135 
138  StringRef FileName) {
139 
140  // Value names may be prefixed with a binary '1' to indicate
141  // that the backend should not modify the symbols due to any platform
142  // naming convention. Do not include that '1' in the PGO profile name.
143  if (Name[0] == '\1')
144  Name = Name.substr(1);
145 
146  std::string NewName = Name;
147  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
148  // For local symbols, prepend the main file name to distinguish them.
149  // Do not include the full path in the file name since there's no guarantee
150  // that it will stay the same, e.g., if the files are checked out from
151  // version control in different locations.
152  if (FileName.empty())
153  NewName = NewName.insert(0, "<unknown>:");
154  else
155  NewName = NewName.insert(0, FileName.str() + ":");
156  }
157  return NewName;
158 }
159 
160 std::string GlobalValue::getGlobalIdentifier() const {
162  getParent()->getSourceFileName());
163 }
164 
166  if (auto *GA = dyn_cast<GlobalAlias>(this)) {
167  // In general we cannot compute this at the IR level, but we try.
168  if (const GlobalObject *GO = GA->getBaseObject())
169  return GO->getSection();
170  return "";
171  }
172  return cast<GlobalObject>(this)->getSection();
173 }
174 
176  if (auto *GA = dyn_cast<GlobalAlias>(this)) {
177  // In general we cannot compute this at the IR level, but we try.
178  if (const GlobalObject *GO = GA->getBaseObject())
179  return const_cast<GlobalObject *>(GO)->getComdat();
180  return nullptr;
181  }
182  // ifunc and its resolver are separate things so don't use resolver comdat.
183  if (isa<GlobalIFunc>(this))
184  return nullptr;
185  return cast<GlobalObject>(this)->getComdat();
186 }
187 
189  if (!hasPartition())
190  return "";
191  return getContext().pImpl->GlobalValuePartitions[this];
192 }
193 
195  // Do nothing if we're clearing the partition and it is already empty.
196  if (!hasPartition() && S.empty())
197  return;
198 
199  // Get or create a stable partition name string and put it in the table in the
200  // context.
201  if (!S.empty())
202  S = getContext().pImpl->Saver.save(S);
204 
205  // Update the HasPartition field. Setting the partition to the empty string
206  // means this global no longer has a partition.
207  HasPartition = !S.empty();
208 }
209 
210 StringRef GlobalObject::getSectionImpl() const {
211  assert(hasSection());
212  return getContext().pImpl->GlobalObjectSections[this];
213 }
214 
216  // Do nothing if we're clearing the section and it is already empty.
217  if (!hasSection() && S.empty())
218  return;
219 
220  // Get or create a stable section name string and put it in the table in the
221  // context.
222  if (!S.empty())
223  S = getContext().pImpl->Saver.save(S);
225 
226  // Update the HasSectionHashEntryBit. Setting the section to the empty string
227  // means this global no longer has a section.
228  setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
229 }
230 
232  // Globals are definitions if they have an initializer.
233  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
234  return GV->getNumOperands() == 0;
235 
236  // Functions are definitions if they have a body.
237  if (const Function *F = dyn_cast<Function>(this))
238  return F->empty() && !F->isMaterializable();
239 
240  // Aliases and ifuncs are always definitions.
241  assert(isa<GlobalIndirectSymbol>(this));
242  return false;
243 }
244 
246  // Firstly, can only increase the alignment of a global if it
247  // is a strong definition.
249  return false;
250 
251  // It also has to either not have a section defined, or, not have
252  // alignment specified. (If it is assigned a section, the global
253  // could be densely packed with other objects in the section, and
254  // increasing the alignment could cause padding issues.)
255  if (hasSection() && getAlignment() > 0)
256  return false;
257 
258  // On ELF platforms, we're further restricted in that we can't
259  // increase the alignment of any variable which might be emitted
260  // into a shared library, and which is exported. If the main
261  // executable accesses a variable found in a shared-lib, the main
262  // exe actually allocates memory for and exports the symbol ITSELF,
263  // overriding the symbol found in the library. That is, at link
264  // time, the observed alignment of the variable is copied into the
265  // executable binary. (A COPY relocation is also generated, to copy
266  // the initial data from the shadowed variable in the shared-lib
267  // into the location in the main binary, before running code.)
268  //
269  // And thus, even though you might think you are defining the
270  // global, and allocating the memory for the global in your object
271  // file, and thus should be able to set the alignment arbitrarily,
272  // that's not actually true. Doing so can cause an ABI breakage; an
273  // executable might have already been built with the previous
274  // alignment of the variable, and then assuming an increased
275  // alignment will be incorrect.
276 
277  // Conservatively assume ELF if there's no parent pointer.
278  bool isELF =
279  (!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatELF());
280  if (isELF && !isDSOLocal())
281  return false;
282 
283  return true;
284 }
285 
287  if (auto *GO = dyn_cast<GlobalObject>(this))
288  return GO;
289  if (auto *GA = dyn_cast<GlobalIndirectSymbol>(this))
290  return GA->getBaseObject();
291  return nullptr;
292 }
293 
295  auto *GO = dyn_cast<GlobalObject>(this);
296  if (!GO)
297  return false;
298 
299  return GO->getMetadata(LLVMContext::MD_absolute_symbol);
300 }
301 
303  auto *GO = dyn_cast<GlobalObject>(this);
304  if (!GO)
305  return None;
306 
307  MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
308  if (!MD)
309  return None;
310 
311  return getConstantRangeFromMetadata(*MD);
312 }
313 
315  if (!hasLinkOnceODRLinkage())
316  return false;
317 
318  // We assume that anyone who sets global unnamed_addr on a non-constant
319  // knows what they're doing.
320  if (hasGlobalUnnamedAddr())
321  return true;
322 
323  // If it is a non constant variable, it needs to be uniqued across shared
324  // objects.
325  if (auto *Var = dyn_cast<GlobalVariable>(this))
326  if (!Var->isConstant())
327  return false;
328 
330 }
331 
332 //===----------------------------------------------------------------------===//
333 // GlobalVariable Implementation
334 //===----------------------------------------------------------------------===//
335 
337  Constant *InitVal, const Twine &Name,
338  ThreadLocalMode TLMode, unsigned AddressSpace,
339  bool isExternallyInitialized)
340  : GlobalObject(Ty, Value::GlobalVariableVal,
342  InitVal != nullptr, Link, Name, AddressSpace),
343  isConstantGlobal(constant),
344  isExternallyInitializedConstant(isExternallyInitialized) {
346  "invalid type for global variable");
347  setThreadLocalMode(TLMode);
348  if (InitVal) {
349  assert(InitVal->getType() == Ty &&
350  "Initializer should be the same type as the GlobalVariable!");
351  Op<0>() = InitVal;
352  }
353 }
354 
356  LinkageTypes Link, Constant *InitVal,
357  const Twine &Name, GlobalVariable *Before,
358  ThreadLocalMode TLMode, unsigned AddressSpace,
360  : GlobalObject(Ty, Value::GlobalVariableVal,
362  InitVal != nullptr, Link, Name, AddressSpace),
363  isConstantGlobal(constant),
364  isExternallyInitializedConstant(isExternallyInitialized) {
366  "invalid type for global variable");
367  setThreadLocalMode(TLMode);
368  if (InitVal) {
369  assert(InitVal->getType() == Ty &&
370  "Initializer should be the same type as the GlobalVariable!");
371  Op<0>() = InitVal;
372  }
373 
374  if (Before)
375  Before->getParent()->getGlobalList().insert(Before->getIterator(), this);
376  else
377  M.getGlobalList().push_back(this);
378 }
379 
382 }
383 
386 }
387 
389  if (!InitVal) {
390  if (hasInitializer()) {
391  // Note, the num operands is used to compute the offset of the operand, so
392  // the order here matters. Clearing the operand then clearing the num
393  // operands ensures we have the correct offset to the operand.
394  Op<0>().set(nullptr);
396  }
397  } else {
398  assert(InitVal->getType() == getValueType() &&
399  "Initializer type must match GlobalVariable type");
400  // Note, the num operands is used to compute the offset of the operand, so
401  // the order here matters. We need to set num operands to 1 first so that
402  // we get the correct offset to the first operand when we set it.
403  if (!hasInitializer())
405  Op<0>().set(InitVal);
406  }
407 }
408 
409 /// Copy all additional attributes (those not needed to create a GlobalVariable)
410 /// from the GlobalVariable Src to this one.
416 }
417 
420  clearMetadata();
421 }
422 
423 //===----------------------------------------------------------------------===//
424 // GlobalIndirectSymbol Implementation
425 //===----------------------------------------------------------------------===//
426 
428  unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name,
429  Constant *Symbol)
430  : GlobalValue(Ty, VTy, &Op<0>(), 1, Linkage, Name, AddressSpace) {
431  Op<0>() = Symbol;
432 }
433 
434 static const GlobalObject *
436  if (auto *GO = dyn_cast<GlobalObject>(C))
437  return GO;
438  if (auto *GA = dyn_cast<GlobalAlias>(C))
439  if (Aliases.insert(GA).second)
440  return findBaseObject(GA->getOperand(0), Aliases);
441  if (auto *CE = dyn_cast<ConstantExpr>(C)) {
442  switch (CE->getOpcode()) {
443  case Instruction::Add: {
444  auto *LHS = findBaseObject(CE->getOperand(0), Aliases);
445  auto *RHS = findBaseObject(CE->getOperand(1), Aliases);
446  if (LHS && RHS)
447  return nullptr;
448  return LHS ? LHS : RHS;
449  }
450  case Instruction::Sub: {
451  if (findBaseObject(CE->getOperand(1), Aliases))
452  return nullptr;
453  return findBaseObject(CE->getOperand(0), Aliases);
454  }
455  case Instruction::IntToPtr:
456  case Instruction::PtrToInt:
457  case Instruction::BitCast:
458  case Instruction::GetElementPtr:
459  return findBaseObject(CE->getOperand(0), Aliases);
460  default:
461  break;
462  }
463  }
464  return nullptr;
465 }
466 
469  return findBaseObject(getOperand(0), Aliases);
470 }
471 
472 //===----------------------------------------------------------------------===//
473 // GlobalAlias Implementation
474 //===----------------------------------------------------------------------===//
475 
476 GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
477  const Twine &Name, Constant *Aliasee,
478  Module *ParentModule)
479  : GlobalIndirectSymbol(Ty, Value::GlobalAliasVal, AddressSpace, Link, Name,
480  Aliasee) {
481  if (ParentModule)
482  ParentModule->getAliasList().push_back(this);
483 }
484 
485 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
486  LinkageTypes Link, const Twine &Name,
487  Constant *Aliasee, Module *ParentModule) {
488  return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
489 }
490 
491 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
492  LinkageTypes Linkage, const Twine &Name,
493  Module *Parent) {
494  return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
495 }
496 
497 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
498  LinkageTypes Linkage, const Twine &Name,
499  GlobalValue *Aliasee) {
500  return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
501 }
502 
504  GlobalValue *Aliasee) {
505  PointerType *PTy = Aliasee->getType();
506  return create(PTy->getElementType(), PTy->getAddressSpace(), Link, Name,
507  Aliasee);
508 }
509 
511  return create(Aliasee->getLinkage(), Name, Aliasee);
512 }
513 
515  getParent()->getAliasList().remove(getIterator());
516 }
517 
519  getParent()->getAliasList().erase(getIterator());
520 }
521 
523  assert((!Aliasee || Aliasee->getType() == getType()) &&
524  "Alias and aliasee types should match!");
525  setIndirectSymbol(Aliasee);
526 }
527 
528 //===----------------------------------------------------------------------===//
529 // GlobalIFunc Implementation
530 //===----------------------------------------------------------------------===//
531 
532 GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
533  const Twine &Name, Constant *Resolver,
534  Module *ParentModule)
535  : GlobalIndirectSymbol(Ty, Value::GlobalIFuncVal, AddressSpace, Link, Name,
536  Resolver) {
537  if (ParentModule)
538  ParentModule->getIFuncList().push_back(this);
539 }
540 
541 GlobalIFunc *GlobalIFunc::create(Type *Ty, unsigned AddressSpace,
542  LinkageTypes Link, const Twine &Name,
543  Constant *Resolver, Module *ParentModule) {
544  return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
545 }
546 
548  getParent()->getIFuncList().remove(getIterator());
549 }
550 
552  getParent()->getIFuncList().erase(getIterator());
553 }
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:242
const NoneType None
Definition: None.h:23
AttributeSet getAttributes() const
Return the attribute set for this global.
uint64_t CallInst * C
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:109
unsigned getAlignment() const
Definition: GlobalObject.h:73
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:240
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:258
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:65
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:232
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:484
void dropAllReferences()
Drop all references to operands.
Definition: User.h:294
iterator erase(iterator where)
Definition: ilist.h:265
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:236
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool isMaterializable() const
If this function&#39;s Module is being lazily streamed in functions from disk or some other source...
Definition: Globals.cpp:44
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:743
Optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns None...
Definition: Globals.cpp:302
UniqueStringSaver Saver
Metadata node.
Definition: Metadata.h:863
F(f)
const GlobalListType & getGlobalList() const
Get the Module&#39;s list of global variables (constant).
Definition: Module.h:524
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:160
op_iterator op_begin()
Definition: User.h:229
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:314
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:330
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:518
DenseMap< const GlobalValue *, StringRef > GlobalValuePartitions
Collection of per-GlobalValue partitions used in this context.
const AliasListType & getAliasList() const
Get the Module&#39;s list of aliases (constant).
Definition: Module.h:541
void setIndirectSymbol(Constant *Symbol)
These methods set and retrieve indirect symbol.
bool hasSection() const
Definition: GlobalValue.h:273
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:388
bool isDSOLocal() const
Definition: GlobalValue.h:283
UnnamedAddr getUnnamedAddr() const
Definition: GlobalValue.h:216
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value&#39;s address is not significant in this module.
Definition: GlobalValue.h:212
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:254
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1440
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:541
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:592
static const unsigned MaximumAlignment
Definition: Value.h:655
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:271
void setPartition(StringRef Part)
Definition: Globals.cpp:194
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:551
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:467
StringRef save(const char *S)
Definition: StringSaver.h:50
LinkageTypes getLinkage() const
Definition: GlobalValue.h:460
unsigned getAlignment() const
Definition: Globals.cpp:97
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:336
Value * getOperand(unsigned i) const
Definition: User.h:169
Class to represent pointers.
Definition: DerivedTypes.h:575
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:436
bool canIncreaseAlignment() const
Definition: Globals.cpp:245
DLLStorageClassTypes getDLLStorageClass() const
Definition: GlobalValue.h:262
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:236
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important base class in LLVM.
Definition: Constant.h:41
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:1864
void setExternallyInitialized(bool Val)
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:384
unsigned getAddressSpace() const
Definition: Globals.cpp:111
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:603
self_iterator getIterator()
Definition: ilist_node.h:81
void setGlobalVariableNumOperands(unsigned NumOps)
Set the number of operands on a GlobalVariable.
Definition: User.h:207
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:164
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:49
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
StringRef getSection() const
Definition: Globals.cpp:165
void removeFromParent()
removeFromParent - This method unlinks &#39;this&#39; from the containing module, but does not delete it...
Definition: Globals.cpp:380
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:66
const IFuncListType & getIFuncList() const
Get the Module&#39;s list of ifuncs (constant).
Definition: Module.h:550
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
StringRef getPartition() const
Definition: Globals.cpp:188
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:663
BlockVerifier::State From
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias *> &Aliases)
Definition: Globals.cpp:435
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:117
Module.h This file contains the declarations for the Module class.
AddressSpace
Definition: NVPTXBaseInfo.h:21
unsigned Linkage
Definition: GlobalValue.h:94
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:203
ValueTy
Concrete subclass of this.
Definition: Value.h:465
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions.html).
Definition: GlobalValue.h:113
const Comdat * getComdat() const
Definition: Globals.cpp:175
void push_back(pointer val)
Definition: ilist.h:311
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:167
void setAttributes(AttributeSet A)
Set attribute list for this global.
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition: Globals.cpp:418
pointer remove(iterator &IT)
Definition: ilist.h:249
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:85
bool hasPartition() const
Definition: GlobalValue.h:287
iterator insert(iterator where, pointer New)
Definition: ilist.h:226
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:215
void setAlignment(MaybeAlign Align)
Definition: Globals.cpp:116
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:294
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:219
bool isStrongDefinitionForLinker() const
Returns true if this global&#39;s definition will be the one chosen by the linker.
Definition: GlobalValue.h:546
void removeFromParent()
removeFromParent - This method unlinks &#39;this&#39; from the containing module, but does not delete it...
Definition: Globals.cpp:514
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:411
Compile-time customization of User operands.
Definition: User.h:42
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:394
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
Type * getValueType() const
Definition: GlobalValue.h:279
void removeFromParent()
This method unlinks &#39;this&#39; from the containing module, but does not delete it.
Definition: Globals.cpp:547
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:231
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:286
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
bool hasInitializer() const
Definitions have initializers, declarations don&#39;t.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Symbol)
Definition: Globals.cpp:427
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Use & Op()
Definition: User.h:133
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:130
void removeFromParent()
This method unlinks &#39;this&#39; from the containing module, but does not delete it.
Definition: Globals.cpp:73
bool isExternallyInitialized() const
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:215
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:485
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:522
Type * getElementType() const
Definition: DerivedTypes.h:594
void setDSOLocal(bool Local)
Definition: GlobalValue.h:281
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:277