@@ -127,6 +127,7 @@ class BlockAddress;
127
127
class DSOLocalEquivalent ;
128
128
class ConstantTokenNone ;
129
129
class GlobalValue ;
130
+ class GlobalObject ;
130
131
class Context ;
131
132
class Function ;
132
133
class Instruction ;
@@ -330,6 +331,7 @@ class Value {
330
331
friend class BlockAddress ; // For `Val`.
331
332
friend class GlobalValue ; // For `Val`.
332
333
friend class DSOLocalEquivalent ; // For `Val`.
334
+ friend class GlobalObject ; // For `Val`.
333
335
334
336
// / All values point to the context.
335
337
Context &Ctx;
@@ -1124,14 +1126,8 @@ class GlobalValue : public Constant {
1124
1126
GlobalValue (ClassID ID, llvm::GlobalValue *C, Context &Ctx)
1125
1127
: Constant(ID, C, Ctx) {}
1126
1128
friend class Context ; // For constructor.
1127
- Use getOperandUseInternal (unsigned OpIdx, bool Verify) const override {
1128
- return getOperandUseDefault (OpIdx, Verify);
1129
- }
1130
1129
1131
1130
public:
1132
- unsigned getUseOperandNo (const Use &Use) const override {
1133
- return getUseOperandNoDefault (Use);
1134
- }
1135
1131
// / For isa/dyn_cast.
1136
1132
static bool classof (const sandboxir::Value *From) {
1137
1133
switch (From->getSubclassID ()) {
@@ -1193,6 +1189,102 @@ class GlobalValue : public Constant {
1193
1189
// TODO: Add missing functions.
1194
1190
};
1195
1191
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
+
1196
1288
class BlockAddress final : public Constant {
1197
1289
BlockAddress (llvm::BlockAddress *C, Context &Ctx)
1198
1290
: Constant(ClassID::BlockAddress, C, Ctx) {}
@@ -4127,7 +4219,7 @@ class Context {
4127
4219
size_t getNumValues () const { return LLVMValueToValueMap.size (); }
4128
4220
};
4129
4221
4130
- class Function : public Constant {
4222
+ class Function : public GlobalObject {
4131
4223
// / Helper for mapped_iterator.
4132
4224
struct LLVMBBToBB {
4133
4225
Context &Ctx;
@@ -4138,7 +4230,7 @@ class Function : public Constant {
4138
4230
};
4139
4231
// / Use Context::createFunction() instead.
4140
4232
Function (llvm::Function *F, sandboxir::Context &Ctx)
4141
- : Constant (ClassID::Function, F, Ctx) {}
4233
+ : GlobalObject (ClassID::Function, F, Ctx) {}
4142
4234
friend class Context ; // For constructor.
4143
4235
4144
4236
public:
0 commit comments