@@ -127,6 +127,7 @@ class BlockAddress;
127127class DSOLocalEquivalent ;
128128class ConstantTokenNone ;
129129class GlobalValue ;
130+ class GlobalObject ;
130131class Context ;
131132class Function ;
132133class Instruction ;
@@ -330,6 +331,7 @@ class Value {
330331 friend class BlockAddress ; // For `Val`.
331332 friend class GlobalValue ; // For `Val`.
332333 friend class DSOLocalEquivalent ; // For `Val`.
334+ friend class GlobalObject ; // For `Val`.
333335
334336 // / All values point to the context.
335337 Context &Ctx;
@@ -1124,14 +1126,8 @@ class GlobalValue : public Constant {
11241126 GlobalValue (ClassID ID, llvm::GlobalValue *C, Context &Ctx)
11251127 : Constant(ID, C, Ctx) {}
11261128 friend class Context ; // For constructor.
1127- Use getOperandUseInternal (unsigned OpIdx, bool Verify) const override {
1128- return getOperandUseDefault (OpIdx, Verify);
1129- }
11301129
11311130public:
1132- unsigned getUseOperandNo (const Use &Use) const override {
1133- return getUseOperandNoDefault (Use);
1134- }
11351131 // / For isa/dyn_cast.
11361132 static bool classof (const sandboxir::Value *From) {
11371133 switch (From->getSubclassID ()) {
@@ -1193,6 +1189,102 @@ class GlobalValue : public Constant {
11931189 // TODO: Add missing functions.
11941190};
11951191
1192+ class GlobalObject : public GlobalValue {
1193+ protected:
1194+ GlobalObject (ClassID ID, llvm::GlobalObject *C, Context &Ctx)
1195+ : GlobalValue(ID, C, Ctx) {}
1196+ friend class Context ; // For constructor.
1197+ Use getOperandUseInternal (unsigned OpIdx, bool Verify) const final {
1198+ return getOperandUseDefault (OpIdx, Verify);
1199+ }
1200+
1201+ public:
1202+ unsigned getUseOperandNo (const Use &Use) const final {
1203+ return getUseOperandNoDefault (Use);
1204+ }
1205+ // / For isa/dyn_cast.
1206+ static bool classof (const sandboxir::Value *From) {
1207+ switch (From->getSubclassID ()) {
1208+ case ClassID::Function:
1209+ case ClassID::GlobalVariable:
1210+ case ClassID::GlobalIFunc:
1211+ return true ;
1212+ default :
1213+ return false ;
1214+ }
1215+ }
1216+
1217+ // / FIXME: Remove this function once transition to Align is over.
1218+ uint64_t getAlignment () const {
1219+ return cast<llvm::GlobalObject>(Val)->getAlignment ();
1220+ }
1221+
1222+ // / Returns the alignment of the given variable or function.
1223+ // /
1224+ // / Note that for functions this is the alignment of the code, not the
1225+ // / alignment of a function pointer.
1226+ MaybeAlign getAlign () const {
1227+ return cast<llvm::GlobalObject>(Val)->getAlign ();
1228+ }
1229+
1230+ // TODO: Add missing: setAlignment(Align)
1231+
1232+ // / Sets the alignment attribute of the GlobalObject.
1233+ // / This method will be deprecated as the alignment property should always be
1234+ // / defined.
1235+ void setAlignment (MaybeAlign Align);
1236+
1237+ unsigned getGlobalObjectSubClassData () const {
1238+ return cast<llvm::GlobalObject>(Val)->getGlobalObjectSubClassData ();
1239+ }
1240+
1241+ void setGlobalObjectSubClassData (unsigned V);
1242+
1243+ // / Check if this global has a custom object file section.
1244+ // /
1245+ // / This is more efficient than calling getSection() and checking for an empty
1246+ // / string.
1247+ bool hasSection () const {
1248+ return cast<llvm::GlobalObject>(Val)->hasSection ();
1249+ }
1250+
1251+ // / Get the custom section of this global if it has one.
1252+ // /
1253+ // / If this global does not have a custom section, this will be empty and the
1254+ // / default object file section (.text, .data, etc) will be used.
1255+ StringRef getSection () const {
1256+ return cast<llvm::GlobalObject>(Val)->getSection ();
1257+ }
1258+
1259+ // / Change the section for this global.
1260+ // /
1261+ // / Setting the section to the empty string tells LLVM to choose an
1262+ // / appropriate default object file section.
1263+ void setSection (StringRef S);
1264+
1265+ bool hasComdat () const { return cast<llvm::GlobalObject>(Val)->hasComdat (); }
1266+
1267+ // TODO: implement get/setComdat(), etc. once we have a sandboxir::Comdat.
1268+
1269+ // TODO: We currently don't support Metadata in sandboxir so all
1270+ // Metadata-related functions are missing.
1271+
1272+ using VCallVisibility = llvm::GlobalObject::VCallVisibility;
1273+
1274+ VCallVisibility getVCallVisibility () const {
1275+ return cast<llvm::GlobalObject>(Val)->getVCallVisibility ();
1276+ }
1277+
1278+ // / Returns true if the alignment of the value can be unilaterally
1279+ // / increased.
1280+ // /
1281+ // / Note that for functions this is the alignment of the code, not the
1282+ // / alignment of a function pointer.
1283+ bool canIncreaseAlignment () const {
1284+ return cast<llvm::GlobalObject>(Val)->canIncreaseAlignment ();
1285+ }
1286+ };
1287+
11961288class BlockAddress final : public Constant {
11971289 BlockAddress (llvm::BlockAddress *C, Context &Ctx)
11981290 : Constant(ClassID::BlockAddress, C, Ctx) {}
@@ -4127,7 +4219,7 @@ class Context {
41274219 size_t getNumValues () const { return LLVMValueToValueMap.size (); }
41284220};
41294221
4130- class Function : public Constant {
4222+ class Function : public GlobalObject {
41314223 // / Helper for mapped_iterator.
41324224 struct LLVMBBToBB {
41334225 Context &Ctx;
@@ -4138,7 +4230,7 @@ class Function : public Constant {
41384230 };
41394231 // / Use Context::createFunction() instead.
41404232 Function (llvm::Function *F, sandboxir::Context &Ctx)
4141- : Constant (ClassID::Function, F, Ctx) {}
4233+ : GlobalObject (ClassID::Function, F, Ctx) {}
41424234 friend class Context ; // For constructor.
41434235
41444236public:
0 commit comments