[llvm] 751e681 - [SandboxIR][NFC] Create a DEF_CONST() macro in SandboxIRValues.def (#106269)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 14:22:40 PDT 2024


Author: vporpo
Date: 2024-08-27T14:22:37-07:00
New Revision: 751e681ade2b879b051e5f9f30e489f705e35bca

URL: https://github.com/llvm/llvm-project/commit/751e681ade2b879b051e5f9f30e489f705e35bca
DIFF: https://github.com/llvm/llvm-project/commit/751e681ade2b879b051e5f9f30e489f705e35bca.diff

LOG: [SandboxIR][NFC] Create a DEF_CONST() macro in SandboxIRValues.def (#106269)

This helps with Constant::classof().

Added: 
    

Modified: 
    llvm/include/llvm/SandboxIR/SandboxIR.h
    llvm/include/llvm/SandboxIR/SandboxIRValues.def

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 033b1fad52db50..b7bdf9acd2ef45 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -220,6 +220,7 @@ class Value {
   enum class ClassID : unsigned {
 #define DEF_VALUE(ID, CLASS) ID,
 #define DEF_USER(ID, CLASS) ID,
+#define DEF_CONST(ID, CLASS) ID,
 #define DEF_INSTR(ID, OPC, CLASS) ID,
 #include "llvm/SandboxIR/SandboxIRValues.def"
   };
@@ -233,6 +234,9 @@ class Value {
 #define DEF_USER(ID, CLASS)                                                    \
   case ClassID::ID:                                                            \
     return #ID;
+#define DEF_CONST(ID, CLASS)                                                   \
+  case ClassID::ID:                                                            \
+    return #ID;
 #define DEF_INSTR(ID, OPC, CLASS)                                              \
   case ClassID::ID:                                                            \
     return #ID;
@@ -515,6 +519,7 @@ class User : public Value {
 };
 
 class Constant : public sandboxir::User {
+protected:
   Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
       : sandboxir::User(ClassID::Constant, C, SBCtx) {}
   Constant(ClassID ID, llvm::Constant *C, sandboxir::Context &SBCtx)
@@ -529,9 +534,13 @@ class Constant : public sandboxir::User {
 public:
   /// For isa/dyn_cast.
   static bool classof(const sandboxir::Value *From) {
-    return From->getSubclassID() == ClassID::Constant ||
-           From->getSubclassID() == ClassID::ConstantInt ||
-           From->getSubclassID() == ClassID::Function;
+    switch (From->getSubclassID()) {
+#define DEF_CONST(ID, CLASS) case ClassID::ID:
+#include "llvm/SandboxIR/SandboxIRValues.def"
+      return true;
+    default:
+      return false;
+    }
   }
   sandboxir::Context &getParent() const { return getContext(); }
   unsigned getUseOperandNo(const Use &Use) const override {

diff  --git a/llvm/include/llvm/SandboxIR/SandboxIRValues.def b/llvm/include/llvm/SandboxIR/SandboxIRValues.def
index 27a72f21aad06d..00c1a6333c8ec4 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIRValues.def
+++ b/llvm/include/llvm/SandboxIR/SandboxIRValues.def
@@ -10,16 +10,22 @@
 #ifndef DEF_VALUE
 #define DEF_VALUE(ID, CLASS)
 #endif
-DEF_VALUE(Function, Function)
-DEF_VALUE(Argument, Argument)
 
 #ifndef DEF_USER
 #define DEF_USER(ID, CLASS)
 #endif
+
+#ifndef DEF_CONST
+#define DEF_CONST(ID, CLASS)
+#endif
+
+DEF_CONST(Function, Function)
+DEF_VALUE(Argument, Argument)
+
 DEF_USER(User, User)
 DEF_VALUE(Block, BasicBlock)
-DEF_USER(Constant, Constant)
-DEF_USER(ConstantInt, ConstantInt)
+DEF_CONST(Constant, Constant)
+DEF_CONST(ConstantInt, ConstantInt)
 
 #ifndef DEF_INSTR
 #define DEF_INSTR(ID, OPCODE, CLASS)
@@ -109,6 +115,9 @@ DEF_INSTR(Unreachable,    OP(Unreachable),    UnreachableInst)
 #ifdef DEF_USER
 #undef DEF_USER
 #endif
+#ifdef DEF_CONST
+#undef DEF_CONST
+#endif
 #ifdef DEF_INSTR
 #undef DEF_INSTR
 #endif


        


More information about the llvm-commits mailing list