PreviousUpNext

15.4.355  src/lib/compiler/back/low/regor/pick-available-hardware-register-by-first-available-g.pkg

## pick-available-hardware-register-by-first-available-g.pkg            "regor" == "register allocator".
#
# See background comments in:
#
#     src/lib/compiler/back/low/regor/pick-available-hardware-register.api
#
# Compare to:
#
#     src/lib/compiler/back/low/regor/pick-available-hardware-register-by-round-robin-g.pkg
#
# (The latter is better-commented because it is the package actually in use.)

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


stipulate
    package rwv =  rw_vector;                                                                   # rw_vector             is from   src/lib/std/src/rw-vector.pkg
herein

    # This generic is nowhere invoked.
    #
    generic package   pick_available_hardware_register_by_first_available_g   (
        #             =====================================================
        #
        first_register:         Int;  #  start from ``first_register'' 
        register_count:         Int;  #  start over at first_register after checking this many registers.
        available_registers:    List( Int );
    )
    : (weak)  Pick_Available_Hardware_Register                                                          # Pick_Available_Hardware_Register      is from   src/lib/compiler/back/low/regor/pick-available-hardware-register.api
    {
        exception GET_REGISTER;

        size      = first_register + register_count;

        register_is_available  = rwv::make_rw_vector (size, FALSE);

        fun reset_register_picker_state ()
            =
            ();

                                                        my _ =
        apply (\\ r = rwv::set (register_is_available, r, TRUE))
              available_registers;

        fun pick_available_hardware_register
              {
                preferred_registers,
                register_is_taken,
                true_value:                     Int
              }
            = 
            check_preferred  preferred_registers
            where       
                # Use preferred registers
                # whenever possible:
                #
                fun check_preferred []
                        =>
                        find first_register;

                    check_preferred (r ! rs)
                        => 
                        if (   rwv::get (register_is_taken, r) != true_value
                           and rwv::get (register_is_available, r)
                           )
                             r; 
                        else check_preferred rs;
                        fi;
                end 

                also
                fun find start
                    =
                    {   limit = rwv::length  register_is_available;

                        fun search r
                            = 
                            if (   rwv::get (register_is_taken, r) != true_value
                               and rwv::get (register_is_available, r)
                               )

                                 r; 
                            else
                                 r = r+1;

                                 if (r >= limit)  raise exception GET_REGISTER;
                                 else             search r;
                                 fi;
                            fi;

                        search start;
                    };
            end;

        fun pick_available_hardware_registerpair
              {
                preferred_registers,
                register_is_taken,
                true_value:                     Int
              }
            =
            raise exception GET_REGISTER;                       #  UNIMPLEMENTED.

    };
end;


## COPYRIGHT (c) 1996 Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext