Implementing frame lowering

Frame lowering involves emitting function prologue and epilogue. The prologue happens at the beginning of a function. It sets up the stack frame of the called function. The epilogue happens last in a function, it restores the stack frame of the calling (parent) function.

The "stack" serves several purposes in the execution of a program, as follows:

  • Keeping track of return address, when calling a function
  • Storage of local variables in the context of a function call
  • Passing arguments from the caller to the callee.

Thus there are 2 main functions that need to be defined when implementing frame lowering – emitPrologue() and emitEpilogue().

The emitPrologue() function can be defined as follows:

void TOYFrameLowering::emitPrologue(MachineFunction ...

Get LLVM Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.