[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 14:06:09 PDT 2024
https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/106269
>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 1/2] [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
>From 53ebc3373a8782dc9772aa114480bd72539f8fcb Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Tue, 27 Aug 2024 14:05:13 -0700
Subject: [PATCH 2/2] fixup! [SandboxIR][NFC] Create a DEF_CONST() macro in
SandboxIRValues.def
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 2 --
llvm/include/llvm/SandboxIR/SandboxIRValues.def | 5 +++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 2207d36e43a67f..b7bdf9acd2ef45 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -538,8 +538,6 @@ class Constant : public sandboxir::User {
#define DEF_CONST(ID, CLASS) case ClassID::ID:
#include "llvm/SandboxIR/SandboxIRValues.def"
return true;
- case ClassID::Function:
- return true;
default:
return false;
}
diff --git a/llvm/include/llvm/SandboxIR/SandboxIRValues.def b/llvm/include/llvm/SandboxIR/SandboxIRValues.def
index 8080f54458998b..00c1a6333c8ec4 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIRValues.def
+++ b/llvm/include/llvm/SandboxIR/SandboxIRValues.def
@@ -10,8 +10,6 @@
#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)
@@ -21,6 +19,9 @@ DEF_VALUE(Argument, Argument)
#define DEF_CONST(ID, CLASS)
#endif
+DEF_CONST(Function, Function)
+DEF_VALUE(Argument, Argument)
+
DEF_USER(User, User)
DEF_VALUE(Block, BasicBlock)
DEF_CONST(Constant, Constant)
More information about the llvm-commits
mailing list