Similar to basic blocks in the LLVM IR, a MachineBasicBlock
class has a set of machine instructions in sequential order. Mostly, a MachineBasicBlock
class maps to a single LLVM IR basic block. However, there can be cases where multiple MachineBasicBlocks
classes map to a single LLVM IR basic block. The MachineBasicBlock
class has a method, called getBasicBlock()
, that returns the IR basic block to which it is mapping.
The following steps show how machine basic blocks are added:
getBasicBlock
method will return only the current basic block:const BasicBlock *getBasicBlock() const { return BB; }
std::vector<MachineBasicBlock *> Predecessors; std::vector<MachineBasicBlock *> Successors;
insert
function should be added to insert a machine instruction into the basic block:MachineBasicBlock::insert(instr_iterator I, MachineInstr *MI) { assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && "Cannot insert instruction with bundle flags"); if (I != instr_end() && I->isBundledWithPred()) { MI->setFlag(MachineInstr::BundledPred); MI->setFlag(MachineInstr::BundledSucc); } return Insts.insert(I, MI); }
SplitCriticalEdge()
splits the critical edges from this block to the given successor block, and returns the newly created block, or null if splitting is not possible. This function updates the LiveVariables
, MachineDominatorTree
, and MachineLoopInfo
classes:MachineBasicBlock * MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { … … … }
As listed previously, several representative functions of different categories form the interface definition of the MachineBasicBlock
class. The MachineBasicBlock
class keeps a list of machine instructions such as typedef ilist<MachineInstr>
instructions, instructions Insts
, and the original LLVM BB (basic block). It also provides methods for purposes such as these:
getBasicBlock()
and setHasAddressTaken()
)moveBefore()
, moveAfter()
, and addSuccessor()
)push_back()
, insertAfter()
, and so on)18.217.199.122