Prologue and epilogue

Functions need a prologue and an epilogue to be complete. The former sets up the stack frame and callee-saved registers during the beginning of a function, whereas the latter cleans up the stack frame prior to function return. In our sum.bc example, when compiled for SPARC, this is how the machine instructions look like after prologue and epilogue insertion:

    %O6<def> = SAVEri %O6, -96
    %I0<def> = ADDrr %I1<kill>, %I0<kill>
    %G0<def> = RESTORErr %G0, %G0
    RETL 8, %I0<imp-use>

In this example, the SAVEri instruction is the prologue and RESTORErr is the epilogue, performing stack-frame-related setup and cleanup. Prologue and epilogue generation is target-specific and defined in the <Target>FrameLowering::emitPrologue() and ...

Get Getting Started with LLVM Core Libraries 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.