PreviousUpNext

15.4.371  src/lib/compiler/back/low/regor/solve-register-allocation-problems-by-recursive-partition-g.pkg

## solve-register-allocation-problems-by-recursive-partition-g.pkg                                                      "regor" is a contraction of "register allocator"
#
# Most register allocators choke and die if given
# a controlflow graph which is too large.
#
# The idea here is to take graphs which are "too large"
# and break them down into manageable-sized pieces
# which can then be register-allocated individually.

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


# This generic is nowhere invoked.

generic package   solve_register_allocation_problems_by_recursive_partition_g
    #             ===========================================================
    #
    # This is the vanilla register allocator:
    #
    (ra:  Solve_Register_Allocation_Problems)                                   # Solve_Register_Allocation_Problems    is from   src/lib/compiler/back/low/regor/solve-register-allocation-problems.api


    # This is the controlflow-graph partitioner:
    #
    #     partition_machcode_controlflow_graph_and_register_allocate_by_partition_g                                     is from   src/lib/compiler/back/low/regor/partition-machcode-controlflow-graph-and-register-allocate-by-partition-g.pkg
    #     Partition_Machcode_Controlflow_Graph_And_Register_Allocate_By_Partition                                       is from   src/lib/compiler/back/low/regor/partition-machcode-controlflow-graph-and-register-allocate-by-partition.api
    (fp:  Partition_Machcode_Controlflow_Graph_And_Register_Allocate_By_Partition
          where
               rgk == ra::rgk                                                   # "rgk" == "registerkinds".
          also Machcode_Controlflow_Graph == ra::flo::Machcode_Controlflow_Graph
    )
: (weak)  Solve_Register_Allocation_Problems                                    # Solve_Register_Allocation_Problems    is from   src/lib/compiler/back/low/regor/solve-register-allocation-problems.api
{
    # Exported to client packages:
    #
    package flo =  ra::flo;
    package mcf =  flo::mcf;                                                    # "mcf" == "machcode_form" (abstract machine code).
    package rgk =  mcf::rgk;                                                    # "rgk" == "registerkinds".
    #
    include ra;

    stipulate
        package cig = iterated_register_coalescing::cig;                        # iterated_register_coalescing          is from   src/lib/compiler/back/low/regor/iterated-register-coalescing.pkg
    herein
        max_blocks
            =
            lowhalf_control::make_int ("ra-max-blocks", "max block count for region-based RA");


        # Main entry point.  
        # All the magic is actually done in
        # partition_machcode_controlflow_graph_and_register_allocate_by_partition_g                                     is from   src/lib/compiler/back/low/regor/partition-machcode-controlflow-graph-and-register-allocate-by-partition-g.pkg
        #
        fun solve_register_allocation_problems
                #
                (register_allocation_problems:  List(Register_Allocation_Problem))
                #
                mcg                                                             # "mcg" == "machcode_controflow_graph".
            =
            if (fp::number_of_basic_blocks_in mcg <= *max_blocks)
                #
                ra::solve_register_allocation_problems  register_allocation_problems  mcg;
            else
                apply  ra  register_allocation_problems
                where
                    fun ra (register_allocation_problem as { registerkind, ... } )
                        = 
                        fp::partition_machcode_controlflow_graph_and_register_allocate_by_partition
                            #
                            mcg
                            #
                            registerkind
                            #
                            (ra::solve_register_allocation_problems [ register_allocation_problem ])
                            ;
                end;

                mcg;
            fi;
    end;
};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext