PreviousUpNext

15.3.139  src/lib/compiler/back/low/omit-framepointer/free-up-framepointer-in-machcode.api

## free-up-framepointer-in-machcode.api
#
# Rewrite an machcode controlflow graph to replace references to
# the (virtual) framepointer with references to the stackpointer.
#
# This transform is currently only implemented on Intel32 (x86).
# It is important on that architecture because x86 is register-
# starved, and this frees up ebp to be used as a general-purpose
# register.  (On some other architectures it might still be a small
# win just due to eliminating the compute overhead to maintain
# the framepointer.  This rewrite pass is not needed on pwrpc32
# because we never change the sp within a function on pwrpc32.)
#
# To be concrete, on x86 this increases available general-purpose
# registers from five to six. (We must dedicate esp for stack pointer
# and adi for heap-allocation pointer.)  On x86 we still wind up
# running about 15% slower than we would if we had 16-32 registers.
#
# Since the framepointer is fixed within a function call but
# the stackpointer changes during a function call as values
# are pushed and popped, this involves in essence doing a
# symbolic-execution walkthrough of the code computing at
# each instruction the offset between the (virtual) framepointer
# and the current stackpointer;  with this difference D in hand,
# we in essence just change ebp[n] to esp[n+D].
#
# See also:
#
#     MLRISC 'Omit Frame Pointer' Optimization
#     Lal George (Bell Labs)
#     2001 6p
#     http://www.smlnj.org//compiler-notes/omit-vfp.ps

# Compiled by:
#     src/lib/compiler/back/low/lib/lowhalf.lib



###               "Although I am a typical loner in daily life,
###                my consciousness of belonging to the invisible
###                community of those who strive for truth, beauty
###                and justice has preserved me from feeling isolated."
###
###                                       -- Albert Einstein





stipulate
    package rkj =  registerkinds_junk;                                          # registerkinds_junk            is from   src/lib/compiler/back/low/code/registerkinds-junk.pkg
herein

    api Free_Up_Framepointer_In_Machcode {
        #
        package mcf:  Machcode_Form;                                            # Machcode_Form                 is from   src/lib/compiler/back/low/code/machcode-form.api

        package mcg:  Machcode_Controlflow_Graph                                # Machcode_Controlflow_Graph    is from   src/lib/compiler/back/low/mcg/machcode-controlflow-graph.api
                      where
                          mcf == mcf;                                           # "mcf" == "machcode_form" (abstract machine code).


        replace_framepointer_uses_with_stackpointer_in_machcode_controlflow_graph
          :
          { virtual_framepointer:       rkj::Codetemp_Info,
            initial_fp_to_sp_delta:     Null_Or( one_word_int::Int ),                   # Initial displacement between the frame-pointer and stack-pointer if one exists, else NULL. 
            machcode_controlflow_graph: mcg::Machcode_Controlflow_Graph
          }
          -> Void;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext