[llvm] [SandboxIR][NFC] Create a DEF_CONST() macro in SandboxIRValues.def (PR #106269)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 11:38:37 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/106269
This helps with Constant::classof().
>From b76d7cf502930fd72337895259fa3f704a0d3f25 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Fri, 16 Aug 2024 12:34:38 -0700
Subject: [PATCH] [SandboxIR][NFC] Create a DEF_CONST() macro in
SandboxIRValues.def
This helps with Constant::classof().
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 17 ++++++++++++++---
llvm/include/llvm/SandboxIR/SandboxIRValues.def | 12 ++++++++++--
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 033b1fad52db50..2207d36e43a67f 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,15 @@ 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;
+ case ClassID::Function:
+ 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..8080f54458998b 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIRValues.def
+++ b/llvm/include/llvm/SandboxIR/SandboxIRValues.def
@@ -16,10 +16,15 @@ DEF_VALUE(Argument, Argument)
#ifndef DEF_USER
#define DEF_USER(ID, CLASS)
#endif
+
+#ifndef DEF_CONST
+#define DEF_CONST(ID, CLASS)
+#endif
+
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 +114,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