PreviousUpNext

15.3.154  src/lib/compiler/back/low/regor/solve-register-allocation-problems.api

## solve-register-allocation-problems.api                                                               "regor" is a contraction of "register allocator"
#
# The main register allocator API.
#
# This is a low-level register-allocator interface;
# for a higher-level interface see:
#
#     src/lib/compiler/back/low/regor/register-allocator.api
#
# We accept accept one machcode controlflow graph
# and typically two associated register allocation problems,
# one each for the int and floating-point registers,
# solve the allocation problems, and return the updated graph.
#
# In the interests of being machine-independent, we define the
# register allocation problems somewhat abstractly and accept
# a list of them rather than assuming there will always be
# exactly two.
#
# Comments are mainly in
#
#     src/lib/compiler/back/low/regor/solve-register-allocation-problems-by-iterated-coalescing-g.pkg

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

stipulate
    package cig =  codetemp_interference_graph;                                         # codetemp_interference_graph                   is from   src/lib/compiler/back/low/regor/codetemp-interference-graph.pkg
    package rkj =  registerkinds_junk;                                                  # registerkinds_junk                            is from   src/lib/compiler/back/low/code/registerkinds-junk.pkg
    package rwv =  rw_vector;                                                           # rw_vector                                     is from   src/lib/std/src/rw-vector.pkg
herein

    # This API is implemented (only) in:
    #
    #     src/lib/compiler/back/low/regor/solve-register-allocation-problems-by-iterated-coalescing-g.pkg
    #     src/lib/compiler/back/low/regor/solve-register-allocation-problems-by-recursive-partition-g.pkg
    #
    api Solve_Register_Allocation_Problems {
        #
        package mcf:  Machcode_Form;                                                    # Machcode_Form                                 is from   src/lib/compiler/back/low/code/machcode-form.api
        package rgk:  Registerkinds;                                                    # Registerkinds                                 is from   src/lib/compiler/back/low/code/registerkinds.api
        package flo:  Regor_View_Of_Machcode_Controlflow_Graph;                         # Regor_View_Of_Machcode_Controlflow_Graph      is from   src/lib/compiler/back/low/regor/regor-view-of-machcode-controlflow-graph.api

        sharing flo::mcf == mcf;                                                        # "mcf" == "machcode_form" (abstract machine code).
        sharing mcf::rgk == rgk;                                                        # "rgk" == "registerkinds".

        Getreg =    { preferred_registers:      List( rkj::Universal_Register_Id ),
                      register_is_taken:        rwv::Rw_Vector( Int ),
                      true_value:               Int                                     # Speedhack: register is taken iff register_is_taken[ register ] == true_value.
                    }
                    ->
                    rkj::Universal_Register_Id;

        Mode = Unt;

        Spill_To == cig::Spill_To;


        # Optimizations/options.
        # 'or' them together:

        no_optimization:       Mode;
        dead_copy_elim:        Mode;
        biased_selection:      Mode;
        spill_coloring:        Mode;
        spill_coalescing:      Mode;
        spill_propagation:     Mode;
        has_parallel_copies:   Mode; 
            #
            # The above MUST be used when spill coloring is used and
            # you have parallel copies in the program. Otherwise, phantom
            # problems involving copy temporaries may appear.



        # Define a register allocation problem.
        #
        # On today's architectures the integer and floating-point registers
        # are usually disjoint, allowing us to allot them separately,
        # so we define our interface in the expectation that usually one
        # machcode controlflow graph will have two or more associated
        # register allocation problems:
        #
        Register_Allocation_Problem
            = 
            { registerkind:             rkj::Registerkind,              # Kind of register.
              spill_prohibitions:       List( rkj::Codetemp_Info ),             # Don't spill these.
              ramregs:                  List( rkj::Codetemp_Info ),             # Memory registers.

              hardware_registers_we_may_use:    Int,                    # E.g. 6 int regs on intel32.  Number of colors for our graph-colorer -- this number is the center of our life during register allocation.

              is_globally_allocated_register_or_codetemp:       Int -> Bool,                    # Distinguishes registers globally allocated by hand (e.g., esp and edi on intel32) from those locally allocated by the register allocator.
              pick_available_hardware_register: Getreg,                 # Select among free hardware registers.
                                                                        # pick_available_hardware_register_by_round_robin_g             is from   src/lib/compiler/back/low/regor/pick-available-hardware-register-by-round-robin-g.pkg
              copy_instr:               flo::spl::Copy_Instr,           # How to make a copy.
              spill:                    flo::spl::Spill,                # Spill callback.
              spill_src:                flo::spl::Spill_Src,            # Spill callback.
              spill_copy_tmp:           flo::spl::Spill_Copy_Tmp,       # Spill callback.
              reload:                   flo::spl::Reload,               # Reload callback.
              reload_dst:               flo::spl::Reload_Dst,           # Reload callback.
              rename_src:               flo::spl::Rename_Src,           # Rename callback.
              mode:                     Mode                            # Mode.
            }; 

        solve_register_allocation_problems
            :
            List( Register_Allocation_Problem )
            ->
            flo::Machcode_Controlflow_Graph
            ->
            flo::Machcode_Controlflow_Graph;

    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext