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  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
118  assert(Align <= MaximumAlignment &&
119  "Alignment is greater than MaximumAlignment!");
120  unsigned AlignmentData = Log2_32(Align) + 1;
121  unsigned OldData = getGlobalValueSubClassData();
122  setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
123  assert(getAlignment() == Align && "Alignment representation error!");
124 }
125 
128  setAlignment(Src->getAlignment());
129  setSection(Src->getSection());
130 }
131 
134  StringRef FileName) {
135 
136  // Value names may be prefixed with a binary '1' to indicate
137  // that the backend should not modify the symbols due to any platform
138  // naming convention. Do not include that '1' in the PGO profile name.
139  if (Name[0] == '\1')
140  Name = Name.substr(1);
141 
142  std::string NewName = Name;
143  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
144  // For local symbols, prepend the main file name to distinguish them.
145  // Do not include the full path in the file name since there's no guarantee
146  // that it will stay the same, e.g., if the files are checked out from
147  // version control in different locations.
148  if (FileName.empty())
149  NewName = NewName.insert(0, "<unknown>:");
150  else
151  NewName = NewName.insert(0, FileName.str() + ":");
152  }
153  return NewName;
154 }
155 
156 std::string GlobalValue::getGlobalIdentifier() const {
158  getParent()->getSourceFileName());
159 }
160 
162  if (auto *GA = dyn_cast<GlobalAlias>(this)) {
163  // In general we cannot compute this at the IR level, but we try.
164  if (const GlobalObject *GO = GA->getBaseObject())
165  return GO->getSection();
166  return "";
167  }
168  return cast<GlobalObject>(this)->getSection();
169 }
170 
172  if (auto *GA = dyn_cast<GlobalAlias>(this)) {
173  // In general we cannot compute this at the IR level, but we try.
174  if (const GlobalObject *GO = GA->getBaseObject())
175  return const_cast<GlobalObject *>(GO)->getComdat();
176  return nullptr;
177  }
178  // ifunc and its resolver are separate things so don't use resolver comdat.
179  if (isa<GlobalIFunc>(this))
180  return nullptr;
181  return cast<GlobalObject>(this)->getComdat();
182 }
183 
185  if (!hasPartition())
186  return "";
187  return getContext().pImpl->GlobalValuePartitions[this];
188 }
189 
191  // Do nothing if we're clearing the partition and it is already empty.
192  if (!hasPartition() && S.empty())
193  return;
194 
195  // Get or create a stable partition name string and put it in the table in the
196  // context.
197  if (!S.empty())
198  S = getContext().pImpl->Saver.save(S);
200 
201  // Update the HasPartition field. Setting the partition to the empty string
202  // means this global no longer has a partition.
203  HasPartition = !S.empty();
204 }
205 
206 StringRef GlobalObject::getSectionImpl() const {
207  assert(hasSection());
208  return getContext().pImpl->GlobalObjectSections[this];
209 }
210 
212  // Do nothing if we're clearing the section and it is already empty.
213  if (!hasSection() && S.empty())
214  return;
215 
216  // Get or create a stable section name string and put it in the table in the
217  // context.
218  if (!S.empty())
219  S = getContext().pImpl->Saver.save(S);
221 
222  // Update the HasSectionHashEntryBit. Setting the section to the empty string
223  // means this global no longer has a section.
224  setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
225 }
226 
228  // Globals are definitions if they have an initializer.
229  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
230  return GV->getNumOperands() == 0;
231 
232  // Functions are definitions if they have a body.
233  if (const Function *F = dyn_cast<Function>(this))
234  return F->empty() && !F->isMaterializable();
235 
236  // Aliases and ifuncs are always definitions.
237  assert(isa<GlobalIndirectSymbol>(this));
238  return false;
239 }
240 
242  // Firstly, can only increase the alignment of a global if it
243  // is a strong definition.
245  return false;
246 
247  // It also has to either not have a section defined, or, not have
248  // alignment specified. (If it is assigned a section, the global
249  // could be densely packed with other objects in the section, and
250  // increasing the alignment could cause padding issues.)
251  if (hasSection() && getAlignment() > 0)
252  return false;
253 
254  // On ELF platforms, we're further restricted in that we can't
255  // increase the alignment of any variable which might be emitted
256  // into a shared library, and which is exported. If the main
257  // executable accesses a variable found in a shared-lib, the main
258  // exe actually allocates memory for and exports the symbol ITSELF,
259  // overriding the symbol found in the library. That is, at link
260  // time, the observed alignment of the variable is copied into the
261  // executable binary. (A COPY relocation is also generated, to copy
262  // the initial data from the shadowed variable in the shared-lib
263  // into the location in the main binary, before running code.)
264  //
265  // And thus, even though you might think you are defining the
266  // global, and allocating the memory for the global in your object
267  // file, and thus should be able to set the alignment arbitrarily,
268  // that's not actually true. Doing so can cause an ABI breakage; an
269  // executable might have already been built with the previous
270  // alignment of the variable, and then assuming an increased
271  // alignment will be incorrect.
272 
273  // Conservatively assume ELF if there's no parent pointer.
274  bool isELF =
275  (!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatELF());
276  if (isELF && !isDSOLocal())
277  return false;
278 
279  return true;
280 }
281 
283  if (auto *GO = dyn_cast<GlobalObject>(this))
284  return GO;
285  if (auto *GA = dyn_cast<GlobalIndirectSymbol>(this))
286  return GA->getBaseObject();
287  return nullptr;
288 }
289 
291  auto *GO = dyn_cast<GlobalObject>(this);
292  if (!GO)
293  return false;
294 
296 }
297 
299  auto *GO = dyn_cast<GlobalObject>(this);
300  if (!GO)
301  return None;
302 
303  MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
304  if (!MD)
305  return None;
306 
307  return getConstantRangeFromMetadata(*MD);
308 }
309 
311  if (!hasLinkOnceODRLinkage())
312  return false;
313 
314  // We assume that anyone who sets global unnamed_addr on a non-constant
315  // knows what they're doing.
316  if (hasGlobalUnnamedAddr())
317  return true;
318 
319  // If it is a non constant variable, it needs to be uniqued across shared
320  // objects.
321  if (auto *Var = dyn_cast<GlobalVariable>(this))
322  if (!Var->isConstant())
323  return false;
324 
326 }
327 
328 //===----------------------------------------------------------------------===//
329 // GlobalVariable Implementation
330 //===----------------------------------------------------------------------===//
331 
333  Constant *InitVal, const Twine &Name,
334  ThreadLocalMode TLMode, unsigned AddressSpace,
335  bool isExternallyInitialized)
336  : GlobalObject(Ty, Value::GlobalVariableVal,
338  InitVal != nullptr, Link, Name, AddressSpace),
339  isConstantGlobal(constant),
340  isExternallyInitializedConstant(isExternallyInitialized) {
342  "invalid type for global variable");
343  setThreadLocalMode(TLMode);
344  if (InitVal) {
345  assert(InitVal->getType() == Ty &&
346  "Initializer should be the same type as the GlobalVariable!");
347  Op<0>() = InitVal;
348  }
349 }
350 
352  LinkageTypes Link, Constant *InitVal,
353  const Twine &Name, GlobalVariable *Before,
354  ThreadLocalMode TLMode, unsigned AddressSpace,
356  : GlobalObject(Ty, Value::GlobalVariableVal,
358  InitVal != nullptr, Link, Name, AddressSpace),
359  isConstantGlobal(constant),
360  isExternallyInitializedConstant(isExternallyInitialized) {
362  "invalid type for global variable");
363  setThreadLocalMode(TLMode);
364  if (InitVal) {
365  assert(InitVal->getType() == Ty &&
366  "Initializer should be the same type as the GlobalVariable!");
367  Op<0>() = InitVal;
368  }
369 
370  if (Before)
371  Before->getParent()->getGlobalList().insert(Before->getIterator(), this);
372  else
373  M.getGlobalList().push_back(this);
374 }
375 
378 }
379 
382 }
383 
385  if (!InitVal) {
386  if (hasInitializer()) {
387  // Note, the num operands is used to compute the offset of the operand, so
388  // the order here matters. Clearing the operand then clearing the num
389  // operands ensures we have the correct offset to the operand.
390  Op<0>().set(nullptr);
392  }
393  } else {
394  assert(InitVal->getType() == getValueType() &&
395  "Initializer type must match GlobalVariable type");
396  // Note, the num operands is used to compute the offset of the operand, so
397  // the order here matters. We need to set num operands to 1 first so that
398  // we get the correct offset to the first operand when we set it.
399  if (!hasInitializer())
401  Op<0>().set(InitVal);
402  }
403 }
404 
405 /// Copy all additional attributes (those not needed to create a GlobalVariable)
406 /// from the GlobalVariable Src to this one.
412 }
413 
416  clearMetadata();
417 }
418 
419 //===----------------------------------------------------------------------===//
420 // GlobalIndirectSymbol Implementation
421 //===----------------------------------------------------------------------===//
422 
424  unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name,
425  Constant *Symbol)
426  : GlobalValue(Ty, VTy, &Op<0>(), 1, Linkage, Name, AddressSpace) {
427  Op<0>() = Symbol;
428 }
429 
430 
431 //===----------------------------------------------------------------------===//
432 // GlobalAlias Implementation
433 //===----------------------------------------------------------------------===//
434 
435 GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
436  const Twine &Name, Constant *Aliasee,
437  Module *ParentModule)
438  : GlobalIndirectSymbol(Ty, Value::GlobalAliasVal, AddressSpace, Link, Name,
439  Aliasee) {
440  if (ParentModule)
441  ParentModule->getAliasList().push_back(this);
442 }
443 
444 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
445  LinkageTypes Link, const Twine &Name,
446  Constant *Aliasee, Module *ParentModule) {
447  return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
448 }
449 
450 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
451  LinkageTypes Linkage, const Twine &Name,
452  Module *Parent) {
453  return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
454 }
455 
456 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
457  LinkageTypes Linkage, const Twine &Name,
458  GlobalValue *Aliasee) {
459  return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
460 }
461 
463  GlobalValue *Aliasee) {
464  PointerType *PTy = Aliasee->getType();
465  return create(PTy->getElementType(), PTy->getAddressSpace(), Link, Name,
466  Aliasee);
467 }
468 
470  return create(Aliasee->getLinkage(), Name, Aliasee);
471 }
472 
474  getParent()->getAliasList().remove(getIterator());
475 }
476 
478  getParent()->getAliasList().erase(getIterator());
479 }
480 
482  assert((!Aliasee || Aliasee->getType() == getType()) &&
483  "Alias and aliasee types should match!");
484  setIndirectSymbol(Aliasee);
485 }
486 
487 //===----------------------------------------------------------------------===//
488 // GlobalIFunc Implementation
489 //===----------------------------------------------------------------------===//
490 
491 GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
492  const Twine &Name, Constant *Resolver,
493  Module *ParentModule)
494  : GlobalIndirectSymbol(Ty, Value::GlobalIFuncVal, AddressSpace, Link, Name,
495  Resolver) {
496  if (ParentModule)
497  ParentModule->getIFuncList().push_back(this);
498 }
499 
500 GlobalIFunc *GlobalIFunc::create(Type *Ty, unsigned AddressSpace,
501  LinkageTypes Link, const Twine &Name,
502  Constant *Resolver, Module *ParentModule) {
503  return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
504 }
505 
507  getParent()->getIFuncList().remove(getIterator());
508 }
509 
511  getParent()->getIFuncList().erase(getIterator());
512 }
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.
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:89
unsigned getAlignment() const
Definition: GlobalObject.h:58
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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:218
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:463
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
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
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:732
Optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns None...
Definition: Globals.cpp:298
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:156
void setAlignment(unsigned Align)
Definition: Globals.cpp:116
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:310
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:477
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:384
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:500
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:578
static const unsigned MaximumAlignment
Definition: Value.h:635
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:271
void setPartition(StringRef Part)
Definition: Globals.cpp:190
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:510
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:332
Class to represent pointers.
Definition: DerivedTypes.h:544
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:436
bool canIncreaseAlignment() const
Definition: Globals.cpp:241
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:45
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:1856
void setExternallyInitialized(bool Val)
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:380
unsigned getAddressSpace() const
Definition: Globals.cpp:111
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:572
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:161
void removeFromParent()
removeFromParent - This method unlinks &#39;this&#39; from the containing module, but does not delete it...
Definition: Globals.cpp:376
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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:184
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:658
BlockVerifier::State From
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:444
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions.html).
Definition: GlobalValue.h:113
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:538
const Comdat * getComdat() const
Definition: Globals.cpp:171
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:414
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:214
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:290
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:473
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:407
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:506
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:227
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:282
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:72
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:423
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:126
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:211
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:444
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:481
Type * getElementType() const
Definition: DerivedTypes.h:563
void setDSOLocal(bool Local)
Definition: GlobalValue.h:281
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:277