[llvm] [SandboxIR] Implement BranchInst (PR #100063)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 08:22:05 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,
+ Value *Cond, Instruction *InsertBefore,
+ Context &Ctx);
+ static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse,
+ Value *Cond, BasicBlock *InsertAtEnd, Context &Ctx);
+ /// For isa/dyn_cast.
+ static bool classof(const Value *From);
+ bool isUnconditional() const {
+ return cast<llvm::BranchInst>(Val)->isUnconditional();
+ }
+ bool isConditional() const {
+ return cast<llvm::BranchInst>(Val)->isConditional();
+ }
+ Value *getCondition() const;
+ void setCondition(Value *V) { setOperand(0, V); }
+ unsigned getNumSuccessors() const { return 1 + isConditional(); }
----------------
vporpo wrote:
I guess I could have casted it to unsigned first, but this is how it's done in `llvm::BranchInst::getNumSuccessors()` so I just copied it.
https://github.com/llvm/llvm-project/pull/100063
More information about the llvm-commits
mailing list