[llvm] [SandboxIR] Implement UnaryInstruction class (PR #101541)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 16:05:30 PDT 2024


================
@@ -836,10 +839,26 @@ class BranchInst : public Instruction {
 #endif
 };
 
-class LoadInst final : public Instruction {
+/// An abstract class, parent of unary instructions.
+class UnaryInstruction : public Instruction {
+protected:
+  UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI,
+                   Context &Ctx)
+      : Instruction(ID, Opc, LLVMI, Ctx) {}
+
+public:
+  static bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::Opcode::Load || isa<CastInst>(I);
----------------
vporpo wrote:

Indeed. There is no `CastInst` opcode, so we need `isa<CastInst>(I)`. The alternative is a large switch case with the opcodes of the sub-classes of `CastInst`. 
I guess we could use `isa<LoadInst>(I) || isa<CastInst>(I)`.

https://github.com/llvm/llvm-project/pull/101541


More information about the llvm-commits mailing list