[llvm] [SandboxIR] More boilerplate: Function, Argument, Constant, Instruction, OpaqueInst (PR #97343)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 10:21:48 PDT 2024
================
@@ -142,16 +172,137 @@ class User : public Value {
assert(isa<llvm::User>(Val) && "Expected User!");
}
void dumpCommonHeader(raw_ostream &OS) const final;
+ void dump(raw_ostream &OS) const override {
+ // TODO: Remove this tmp implementation once we get the Instruction classes.
+ }
+ LLVM_DUMP_METHOD void dump() const override {
+ // TODO: Remove this tmp implementation once we get the Instruction classes.
+ }
+#endif
+};
+
+class Constant : public sandboxir::User {
+public:
+ Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
+ : sandboxir::User(ClassID::Constant, C, SBCtx) {}
+ /// For isa/dyn_cast.
+ static bool classof(const sandboxir::Value *From) {
+ return From->getSubclassID() == ClassID::Constant ||
+ From->getSubclassID() == ClassID::Function;
+ }
+ sandboxir::Context &getParent() const { return getContext(); }
+#ifndef NDEBUG
+ void verify() const final {
+ assert(isa<llvm::Constant>(Val) && "Expected Constant!");
+ }
+ friend raw_ostream &operator<<(raw_ostream &OS,
+ const sandboxir::Constant &SBC) {
+ SBC.dump(OS);
+ return OS;
+ }
+ void dump(raw_ostream &OS) const override;
+ LLVM_DUMP_METHOD void dump() const override;
+#endif
+};
+
+/// A sandboxir::User with operands and opcode.
+class Instruction : public sandboxir::User {
+public:
+ enum class Opcode {
+#define DEF_VALUE(ID, CLASS)
+#define DEF_USER(ID, CLASS)
+#define OP(OPC) OPC,
+#define OPCODES(...) __VA_ARGS__
+#define DEF_INSTR(ID, OPC, CLASS) OPC
+#include "llvm/SandboxIR/SandboxIRValues.def"
+ };
+
+ Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I,
+ sandboxir::Context &SBCtx)
+ : sandboxir::User(ID, I, SBCtx), Opc(Opc) {}
+
+protected:
+ Opcode Opc;
+
+public:
+ static const char *getOpcodeName(Opcode Opc);
+#ifndef NDEBUG
+ friend raw_ostream &operator<<(raw_ostream &OS, Opcode Opc) {
+ OS << getOpcodeName(Opc);
+ return OS;
+ }
+#endif
+ /// For isa/dyn_cast.
+ static bool classof(const sandboxir::Value *From);
----------------
vporpo wrote:
I added the missing definitions and added tests that exercise them.
https://github.com/llvm/llvm-project/pull/97343
More information about the llvm-commits
mailing list