Skip to content

Commit 751e681

Browse files
authored
[SandboxIR][NFC] Create a DEF_CONST() macro in SandboxIRValues.def (#106269)
This helps with Constant::classof().
1 parent 377257f commit 751e681

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class Value {
220220
enum class ClassID : unsigned {
221221
#define DEF_VALUE(ID, CLASS) ID,
222222
#define DEF_USER(ID, CLASS) ID,
223+
#define DEF_CONST(ID, CLASS) ID,
223224
#define DEF_INSTR(ID, OPC, CLASS) ID,
224225
#include "llvm/SandboxIR/SandboxIRValues.def"
225226
};
@@ -233,6 +234,9 @@ class Value {
233234
#define DEF_USER(ID, CLASS) \
234235
case ClassID::ID: \
235236
return #ID;
237+
#define DEF_CONST(ID, CLASS) \
238+
case ClassID::ID: \
239+
return #ID;
236240
#define DEF_INSTR(ID, OPC, CLASS) \
237241
case ClassID::ID: \
238242
return #ID;
@@ -515,6 +519,7 @@ class User : public Value {
515519
};
516520

517521
class Constant : public sandboxir::User {
522+
protected:
518523
Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
519524
: sandboxir::User(ClassID::Constant, C, SBCtx) {}
520525
Constant(ClassID ID, llvm::Constant *C, sandboxir::Context &SBCtx)
@@ -529,9 +534,13 @@ class Constant : public sandboxir::User {
529534
public:
530535
/// For isa/dyn_cast.
531536
static bool classof(const sandboxir::Value *From) {
532-
return From->getSubclassID() == ClassID::Constant ||
533-
From->getSubclassID() == ClassID::ConstantInt ||
534-
From->getSubclassID() == ClassID::Function;
537+
switch (From->getSubclassID()) {
538+
#define DEF_CONST(ID, CLASS) case ClassID::ID:
539+
#include "llvm/SandboxIR/SandboxIRValues.def"
540+
return true;
541+
default:
542+
return false;
543+
}
535544
}
536545
sandboxir::Context &getParent() const { return getContext(); }
537546
unsigned getUseOperandNo(const Use &Use) const override {

llvm/include/llvm/SandboxIR/SandboxIRValues.def

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010
#ifndef DEF_VALUE
1111
#define DEF_VALUE(ID, CLASS)
1212
#endif
13-
DEF_VALUE(Function, Function)
14-
DEF_VALUE(Argument, Argument)
1513

1614
#ifndef DEF_USER
1715
#define DEF_USER(ID, CLASS)
1816
#endif
17+
18+
#ifndef DEF_CONST
19+
#define DEF_CONST(ID, CLASS)
20+
#endif
21+
22+
DEF_CONST(Function, Function)
23+
DEF_VALUE(Argument, Argument)
24+
1925
DEF_USER(User, User)
2026
DEF_VALUE(Block, BasicBlock)
21-
DEF_USER(Constant, Constant)
22-
DEF_USER(ConstantInt, ConstantInt)
27+
DEF_CONST(Constant, Constant)
28+
DEF_CONST(ConstantInt, ConstantInt)
2329

2430
#ifndef DEF_INSTR
2531
#define DEF_INSTR(ID, OPCODE, CLASS)
@@ -109,6 +115,9 @@ DEF_INSTR(Unreachable, OP(Unreachable), UnreachableInst)
109115
#ifdef DEF_USER
110116
#undef DEF_USER
111117
#endif
118+
#ifdef DEF_CONST
119+
#undef DEF_CONST
120+
#endif
112121
#ifdef DEF_INSTR
113122
#undef DEF_INSTR
114123
#endif

0 commit comments

Comments
 (0)