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

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 20:24:53 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);
+  }
+  static bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
----------------
tschuett wrote:

Probably, it was a common pattern to use isa + cast. Then the manual was updated: please use dyn_cast, but not all occurrences of isa +cast were converted to dyn_cast. That is why you find this pattern in many places.

I contribute to:
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h
We try to model LLVM-IR, but we are forced to deviations. There is also some freedom, i.e., ExtOrTrunc.
My point is : we use switches.

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


More information about the llvm-commits mailing list