Extracting MachineBasicBlock from Branch Instruction

66 Views Asked by At

The branch instruction contains labels which are the names of the basicblocks that it might jump to. Given that, is there a way to extract a MachineBasicBlock object from a branching instruction? for example:

for(MachineBasicBlock &BB : MF){
    for(MachineInstr &MI : BB){
      if(MI.isConditionalBranch()){
        MachineBasicBlock &InstBB = something(MI.getOperand(0));
      }
    }
  }
1

There are 1 best solutions below

0
On BEST ANSWER

First you cast MI's operand to BasicBlockSDNode and then use getBasicBlock(). Remember to perform the casting using LLVM cast<>() function.