LLVM  3.7.0
GlobalObject.h
Go to the documentation of this file.
1 //===-- llvm/GlobalObject.h - Class to represent global objects -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This represents an independent object. That is, a function or a global
11 // variable, but not an alias.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_GLOBALOBJECT_H
16 #define LLVM_IR_GLOBALOBJECT_H
17 
18 #include "llvm/IR/Constant.h"
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/GlobalValue.h"
21 
22 namespace llvm {
23 class Comdat;
24 class Module;
25 
26 class GlobalObject : public GlobalValue {
27  GlobalObject(const GlobalObject &) = delete;
28 
29 protected:
30  GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
32  : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name), ObjComdat(nullptr) {
34  }
35 
36  std::string Section; // Section to emit this into, empty means default
38  static const unsigned AlignmentBits = 5;
39  static const unsigned GlobalObjectSubClassDataBits =
41 
42 private:
43  static const unsigned AlignmentMask = (1 << AlignmentBits) - 1;
44 
45 public:
46  unsigned getAlignment() const {
47  unsigned Data = getGlobalValueSubClassData();
48  unsigned AlignmentData = Data & AlignmentMask;
49  return (1u << AlignmentData) >> 1;
50  }
51  void setAlignment(unsigned Align);
52 
53  unsigned getGlobalObjectSubClassData() const;
54  void setGlobalObjectSubClassData(unsigned Val);
55 
56  bool hasSection() const { return !StringRef(getSection()).empty(); }
57  const char *getSection() const { return Section.c_str(); }
58  void setSection(StringRef S);
59 
60  bool hasComdat() const { return getComdat() != nullptr; }
61  const Comdat *getComdat() const { return ObjComdat; }
62  Comdat *getComdat() { return ObjComdat; }
63  void setComdat(Comdat *C) { ObjComdat = C; }
64 
65  void copyAttributesFrom(const GlobalValue *Src) override;
66 
67  // Methods for support type inquiry through isa, cast, and dyn_cast:
68  static inline bool classof(const Value *V) {
69  return V->getValueID() == Value::FunctionVal ||
70  V->getValueID() == Value::GlobalVariableVal;
71  }
72 };
73 
74 } // End llvm namespace
75 
76 #endif
bool hasComdat() const
Definition: GlobalObject.h:60
void setAlignment(unsigned Align)
Definition: Globals.cpp:77
unsigned getGlobalObjectSubClassData() const
Definition: Globals.cpp:87
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
static const unsigned GlobalObjectSubClassDataBits
Definition: GlobalObject.h:39
LinkageTypes Linkage
Definition: GlobalValue.h:79
unsigned getAlignment() const
Definition: GlobalObject.h:46
void setComdat(Comdat *C)
Definition: GlobalObject.h:63
PointerType - Class to represent pointers.
Definition: DerivedTypes.h:449
bool hasSection() const
Definition: GlobalObject.h:56
Comdat * getComdat()
Definition: GlobalObject.h:62
const Comdat * getComdat() const
Definition: GlobalObject.h:61
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:362
const char * getSection() const
Definition: GlobalObject.h:57
std::string Section
Definition: GlobalObject.h:36
void copyAttributesFrom(const GlobalValue *Src) override
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:99
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
ValueTy
Concrete subclass of this.
Definition: Value.h:343
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:39
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:109
static bool classof(const Value *V)
Definition: GlobalObject.h:68
static const unsigned GlobalValueSubClassDataBits
Definition: GlobalValue.h:86
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:106
static const unsigned AlignmentBits
Definition: GlobalObject.h:38
LLVM Value Representation.
Definition: Value.h:69
GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, LinkageTypes Linkage, const Twine &Name)
Definition: GlobalObject.h:30
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
void setSection(StringRef S)
Definition: Globals.cpp:126
void setGlobalObjectSubClassData(unsigned Val)
Definition: Globals.cpp:92
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110