File indexing completed on 2026-05-10 08:44:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_IR_GLOBALOBJECT_H
0015 #define LLVM_IR_GLOBALOBJECT_H
0016
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/IR/GlobalValue.h"
0019 #include "llvm/IR/Value.h"
0020 #include "llvm/Support/Alignment.h"
0021
0022 namespace llvm {
0023
0024 class Comdat;
0025 class Metadata;
0026
0027 class GlobalObject : public GlobalValue {
0028 public:
0029
0030
0031
0032 enum VCallVisibility {
0033
0034 VCallVisibilityPublic = 0,
0035
0036
0037 VCallVisibilityLinkageUnit = 1,
0038
0039 VCallVisibilityTranslationUnit = 2,
0040 };
0041
0042 protected:
0043 GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage,
0044 const Twine &Name, unsigned AddressSpace = 0)
0045 : GlobalValue(Ty, VTy, AllocInfo, Linkage, Name, AddressSpace) {
0046 setGlobalValueSubClassData(0);
0047 }
0048 ~GlobalObject();
0049
0050 Comdat *ObjComdat = nullptr;
0051 enum {
0052 LastAlignmentBit = 5,
0053 LastCodeModelBit = 8,
0054 HasSectionHashEntryBit,
0055
0056 GlobalObjectBits,
0057 };
0058 static const unsigned GlobalObjectSubClassDataBits =
0059 GlobalValueSubClassDataBits - GlobalObjectBits;
0060
0061 private:
0062 static const unsigned AlignmentBits = LastAlignmentBit + 1;
0063 static const unsigned AlignmentMask = (1 << AlignmentBits) - 1;
0064 static const unsigned GlobalObjectMask = (1 << GlobalObjectBits) - 1;
0065
0066 public:
0067 GlobalObject(const GlobalObject &) = delete;
0068
0069
0070 uint64_t getAlignment() const {
0071 MaybeAlign Align = getAlign();
0072 return Align ? Align->value() : 0;
0073 }
0074
0075
0076
0077
0078
0079 MaybeAlign getAlign() const {
0080 unsigned Data = getGlobalValueSubClassData();
0081 unsigned AlignmentData = Data & AlignmentMask;
0082 return decodeMaybeAlign(AlignmentData);
0083 }
0084
0085
0086 void setAlignment(Align Align);
0087
0088
0089
0090
0091 void setAlignment(MaybeAlign Align);
0092
0093 unsigned getGlobalObjectSubClassData() const {
0094 unsigned ValueData = getGlobalValueSubClassData();
0095 return ValueData >> GlobalObjectBits;
0096 }
0097
0098 void setGlobalObjectSubClassData(unsigned Val) {
0099 unsigned OldData = getGlobalValueSubClassData();
0100 setGlobalValueSubClassData((OldData & GlobalObjectMask) |
0101 (Val << GlobalObjectBits));
0102 assert(getGlobalObjectSubClassData() == Val && "representation error");
0103 }
0104
0105
0106
0107
0108
0109 bool hasSection() const {
0110 return getGlobalValueSubClassData() & (1 << HasSectionHashEntryBit);
0111 }
0112
0113
0114
0115
0116
0117 StringRef getSection() const {
0118 return hasSection() ? getSectionImpl() : StringRef();
0119 }
0120
0121
0122
0123
0124
0125 void setSection(StringRef S);
0126
0127 bool hasComdat() const { return getComdat() != nullptr; }
0128 const Comdat *getComdat() const { return ObjComdat; }
0129 Comdat *getComdat() { return ObjComdat; }
0130 void setComdat(Comdat *C);
0131
0132 using Value::addMetadata;
0133 using Value::clearMetadata;
0134 using Value::eraseMetadata;
0135 using Value::eraseMetadataIf;
0136 using Value::getAllMetadata;
0137 using Value::getMetadata;
0138 using Value::hasMetadata;
0139 using Value::setMetadata;
0140
0141
0142 void copyMetadata(const GlobalObject *Src, unsigned Offset);
0143
0144 void addTypeMetadata(unsigned Offset, Metadata *TypeID);
0145 void setVCallVisibilityMetadata(VCallVisibility Visibility);
0146 VCallVisibility getVCallVisibility() const;
0147
0148
0149
0150
0151
0152
0153 bool canIncreaseAlignment() const;
0154
0155 protected:
0156 void copyAttributesFrom(const GlobalObject *Src);
0157
0158 public:
0159
0160 static bool classof(const Value *V) {
0161 return V->getValueID() == Value::FunctionVal ||
0162 V->getValueID() == Value::GlobalVariableVal ||
0163 V->getValueID() == Value::GlobalIFuncVal;
0164 }
0165
0166 private:
0167 void setGlobalObjectFlag(unsigned Bit, bool Val) {
0168 unsigned Mask = 1 << Bit;
0169 setGlobalValueSubClassData((~Mask & getGlobalValueSubClassData()) |
0170 (Val ? Mask : 0u));
0171 }
0172
0173 StringRef getSectionImpl() const;
0174 };
0175
0176 }
0177
0178 #endif