Inserting the prologue-epilogue code
Inserting the prologue-epilogue code involves stack unwinding, finalizing the function layout, saving callee-saved registers and emitting the prologue and epilogue code. It also replaces abstract frame indexes with appropriate references. This pass runs after the register allocation phase.
How to do it…
The skeleton and the important functions defined in the PrologueEpilogueInserter
class are as follows:
The prologue epilogue inserter pass runs on a machine function, hence it inherits the
MachineFunctionPass
class. Its constructor initializes the pass:class PEI : public MachineFunctionPass { public: static char ID; PEI() : MachineFunctionPass(ID) { initializePEIPass(*PassRegistry::getPassRegistry()); }
There are various helper functions defined in this class that help insert the prologue and epilogue code:
void calculateSets(MachineFunction &Fn); void calculateCallsInformation(MachineFunction &Fn); void calculateCalleeSavedRegisters...