Implementing frame lowering
This recipe talks about frame lowering for target architecture. Frame lowering involves emitting the prologue and epilogue of the function call.
Getting ready
Note
Two functions need to be defined for frame lowering, namely TOYFrameLowering::emitPrologue()
and TOYFrameLowering::emitEpilogue()
.
How to do it…
The following functions are defined in the TOYFrameLowering.cpp
file in the lib/Target/TOY
folder:
The
emitPrologue
function can be defined as follows:void TOYFrameLowering::emitPrologue(MachineFunction &MF) const { const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); MachineBasicBlock &MBB = MF.front(); MachineBasicBlock::iterator MBBI = MBB.begin(); DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); uint64_t StackSize = computeStackSize(MF); if (!StackSize) { return; } unsigned StackReg = TOY::SP; unsigned OffsetReg = materializeOffset(MF, MBB, MBBI, (unsigned)StackSize); if (OffsetReg) { BuildMI...