[llvm] [SandboxIR] Implement InvokeInst (PR #100796)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 12:46:23 PDT 2024


================
@@ -1029,6 +1033,66 @@ class CallInst final : public CallBase {
 #endif
 };
 
+class InvokeInst final : public CallBase {
+  /// Use Context::createInvokeInst(). Don't call the
+  /// constructor directly.
+  InvokeInst(llvm::Instruction *I, Context &Ctx)
+      : CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
+  friend class Context; // For accessing the constructor in
+                        // create*()
+  Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
+    return getOperandUseDefault(OpIdx, Verify);
+  }
+  SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
+    return {cast<llvm::Instruction>(Val)};
+  }
+
+public:
+  static InvokeInst *create(FunctionType *FTy, Value *Func,
+                            BasicBlock *IfNormal, BasicBlock *IfException,
+                            ArrayRef<Value *> Args, BBIterator WhereIt,
+                            BasicBlock *WhereBB, Context &Ctx,
+                            const Twine &NameStr = "");
+  static InvokeInst *create(FunctionType *FTy, Value *Func,
+                            BasicBlock *IfNormal, BasicBlock *IfException,
+                            ArrayRef<Value *> Args, Instruction *InsertBefore,
+                            Context &Ctx, const Twine &NameStr = "");
+
----------------
vporpo wrote:

So the issue is that in other instructions we had just two `create()` functions, one with `InsertBefore` and one with `InsertAtEnd`. But both of these can be replaced by one create() function that takes as arguments a `BasicBlock::Iterator  WhereIt` and a `BasicBlock *WhereBB`. Anyway, it's probably OK to either keep all three variants, or keep only one. I would need to revisit them with a refactoring patch. Any preference?

But anyway, I will add the missing `create()` function with the `InsertAtEnd` parameter.

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


More information about the llvm-commits mailing list