Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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...