Implementing the MachineBasicBlock class
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.
How to do it…
The following steps show how machine basic blocks are added:
The
getBasicBlock
method will return only the current basic block:const BasicBlock *getBasicBlock() const { return BB; }
The basic blocks have successor as well as predecessor basic blocks. To keep track of those, vectors are defined as follows:
std::vector<MachineBasicBlock *> Predecessors; std::vector<MachineBasicBlock *> Successors;
An
insert
function should be added to insert a machine instruction into the basic block:MachineBasicBlock::insert(instr_iterator...