PreviousUpNext

15.4.322  src/lib/compiler/back/low/mcg/compile-register-moves-phase-g.pkg

## compile-register-moves-phase-g.pkg
#
# This compiler phase expands all parallel copies into normal instructions
# It essentially a wrapper around (depending on target architecture) one of:
#
#     src/lib/compiler/back/low/intel32/code/compile-register-moves-intel32-g.pkg
#     src/lib/compiler/back/low/pwrpc32/code/compile-register-moves-pwrpc32-g.pkg
#     src/lib/compiler/back/low/sparc32/code/compile-register-moves-sparc32-g.pkg
#
# all of which are in turn essentially wrappers for
#
#     src/lib/compiler/back/low/code/compile-register-moves-g.pkg

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






stipulate
    package lem =  lowhalf_error_message;                                       # lowhalf_error_message                 is from   src/lib/compiler/back/low/control/lowhalf-error-message.pkg
    package odg =  oop_digraph;                                                 # oop_digraph                           is from   src/lib/graph/oop-digraph.pkg
    package pp  =  standard_prettyprinter;                                      # standard_prettyprinter                is from   src/lib/prettyprint/big/src/standard-prettyprinter.pkg
    package cv  =  compiler_verbosity;                                          # compiler_verbosity                    is from   src/lib/compiler/front/basics/main/compiler-verbosity.pkg
    package rkj =  registerkinds_junk;                                          # registerkinds_junk                    is from   src/lib/compiler/back/low/code/registerkinds-junk.pkg

    Npp = pp::Npp;                                                              # Null_Or(pp::Prettyprinter)
herein

    # This generic is invoked in:
    #
    #     src/lib/compiler/back/low/main/main/backend-lowhalf-g.pkg
    #
    generic package   compile_register_moves_phase_g   (
        #             ==============================
        #
        package mcg: Machcode_Controlflow_Graph;                                # Machcode_Controlflow_Graph            is from   src/lib/compiler/back/low/mcg/machcode-controlflow-graph.api

        package crm
              : Compile_Register_Moves                                          # Compile_Register_Moves                is from   src/lib/compiler/back/low/code/compile-register-moves.api
                where
                    mcf == mcg::mcf;                                            # "mcf" == "machcode_form" (abstract machine code).
    )
    : (weak) Compile_Register_Moves_Phase                                       # Compile_Register_Moves_Phase          is from   src/lib/compiler/back/low/mcg/compile-register-moves-phase.api
    {
        # Export to client packages:
        #
        package mcg =  mcg;

        stipulate
            package mcf = mcg::mcf;                                             # "mcf" == "machcode_form" (abstract machine code).
        herein

            # This fun is called (only) from:
            #
            #     src/lib/compiler/back/low/main/main/backend-lowhalf-g.pkg
            #
            fun compile_register_moves  (npp:Npp, cv: cv::Compiler_Verbosity)  (mcg  as  odg::DIGRAPH graph)
                =
                {   graph.forall_nodes  expand_ops;
                    #
                    mcg;
                }
                where
                    fun expand (mcf::COPY { kind,  dst, src, tmp, ... } )
                            =>
                            shuffle { dst, src, tmp }
                            where
                                shuffle
                                    = 
                                    case kind
                                        #
                                        rkj::INT_REGISTER   => crm::compile_int_register_moves; 
                                        rkj::FLOAT_REGISTER => crm::compile_float_register_moves;
                                        _                   =>  lem::error ("cfg_expand_copies", "shuffle");
                                    esac;
                            end;

                        expand (mcf::NOTE { op, note } )
                            => 
                            map (\\ op = mcf::NOTE { op, note })
                                (expand op);

                        expand i => [i];
                    end;

                    fun expand_ops (_, mcg::BBLOCK { ops, ... } )
                        = 
                        ops := list::fold_backward 
                                   (\\ (i, rest) =  list::reverse_and_prepend (expand (i), rest))
                                   []
                                   *ops;


                end;
        end;
    };
end;

## COPYRIGHT (c) 2001 Bell Labs, Lucent Technologies
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext