PreviousUpNext

15.4.323  src/lib/compiler/back/low/mcg/count-copies-in-machcode-controlflow-graph-g.pkg

## count-copies-in-machcode-controlflow-graph-g.pkg
#
# This module counts the number of copies (in bytes)  
# generated after register allocation.  Mainly useful for fine-tuning.

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

stipulate
    package odg =  oop_digraph;                                                         # oop_digraph                           is from   src/lib/graph/oop-digraph.pkg
    package lcc =  lowhalf_control;                                                     # lowhalf_control                       is from   src/lib/compiler/back/low/control/lowhalf-control.pkg
herein

    # This generic is nowhere invoked:
    #
    generic package   count_copies_in_machcode_controlflow_graph_g   (
        #             ===========================================
        #
        package mcg: Machcode_Controlflow_Graph;                                        # Machcode_Controlflow_Graph            is from   src/lib/compiler/back/low/mcg/machcode-controlflow-graph.api

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

        package sdj: Jump_Size_Ranges                                                   # Jump_Size_Ranges                      is from   src/lib/compiler/back/low/jmp/jump-size-ranges.api
                     where
                         mcf == mcg::mcf;                                               # "mcf" == "machcode_form" (abstract machine code).
    )
    : (weak) Machcode_Controlflow_Graph_Improver                                        # Machcode_Controlflow_Graph_Improver   is from   src/lib/compiler/back/low/mcg/machcode-controlflow-graph-improver.api
    {
        # Export to client packages:
        #
        package mcg = mcg;
        #
        improvement_name =   "count copies";

        stipulate       
            copies
                =
                lcc::make_counter ("copies", "copy count");
        herein

            fun run (mcg as odg::DIGRAPH graph)
                =
                {   blocks =  map #2 (graph.nodes ());

                    fun loc _
                        =
                        0;

                    fun count (mcg::BBLOCK { ops, ... }, n)
                        =
                        scan (*ops, n)
                        where
                            fun scan ([], n)
                                    =>
                                    n;

                                scan (i ! is, n)
                                    => 
                                    if (mu::move_instruction i)   scan (is, n + sdj::sdi_size (i, loc, 0)); 
                                    else                          scan (is, n);
                                    fi;
                            end;
                        end;

                  copies :=  *copies  +  fold_backward count 0 blocks;

                  mcg;
              };
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext