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 <Target>FrameLowering::emitEpilogue()
methods (see the file <llvm_source>/lib/Target/<Target>/<Target>FrameLowering.cpp
).