[llvm] [SandboxIR] Implement BranchInst (PR #100063)

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 11:14:54 PDT 2024


================
@@ -617,6 +628,100 @@ class SelectInst : public Instruction {
 #endif
 };
 
+class BranchInst : public Instruction {
+  /// Use Context::createBranchInst(). Don't call the constructor directly.
+  BranchInst(llvm::BranchInst *BI, Context &Ctx)
+      : Instruction(ClassID::Br, Opcode::Br, BI, Ctx) {}
+  friend Context; // for BranchInst()
+  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:
+  unsigned getUseOperandNo(const Use &Use) const final {
+    return getUseOperandNoDefault(Use);
+  }
+  unsigned getNumOfIRInstrs() const final { return 1u; }
+  static BranchInst *create(BasicBlock *IfTrue, Instruction *InsertBefore,
+                            Context &Ctx);
+  static BranchInst *create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd,
+                            Context &Ctx);
+  static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse,
----------------
tmsri wrote:

Why can't IfFalse == nullptr be the one that creates the instruction with only the true branch?  That way you save creating two functions or put it as a default parameter.

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


More information about the llvm-commits mailing list