CodeHoarder
CodeHoarder

Reputation: 280

Extracting MachineBasicBlock from Branch Instruction

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));
      }
    }
  }

Upvotes: 1

Views: 83

Answers (1)

arrowd
arrowd

Reputation: 34401

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

Upvotes: 1

Related Questions