--- gforth/engine/main.c 2003/05/14 07:54:54 1.109 +++ gforth/engine/main.c 2003/05/14 09:25:10 1.110 @@ -131,8 +131,9 @@ Cell last_jump=0; /* if the last prim wa static int no_super=0; /* true if compile_prim should not fuse prims */ static int no_dynamic=NO_DYNAMIC_DEFAULT; /* if true, no code is generated dynamically */ -static int print_codesize=0; /* if true, print code size on exit */ +static int print_metrics=0; /* if true, print metrics on exit */ static int static_super_number = 10000000; /* number of ss used if available */ +static int ss_greedy = 0; /* if true: use greedy, not optimal ss selection */ #ifdef HAS_DEBUG int debug=0; @@ -1073,6 +1074,19 @@ cost_lsu; cost_codesize; #endif +struct { + Costfunc *costfunc; + char *metricname; + long sum; +} cost_sums[] = { +#ifndef NO_DYNAMIC + { cost_codesize, "codesize", 0 }, +#endif + { cost_ls, "ls", 0 }, + { cost_lsu, "lsu", 0 }, + { cost_nexts, "nexts", 0 } +}; + #define MAX_BB 128 /* maximum number of instructions in BB */ /* use dynamic programming to find the shortest paths within the basic @@ -1080,23 +1094,25 @@ cost_codesize; on the shortest path to the end of the BB */ void optimize_bb(short origs[], short optimals[], int ninsts) { - int i,j; + int i,j, mincost; static int costs[MAX_BB+1]; assert(ninsts=0; i--) { optimals[i] = origs[i]; - costs[i] = costs[i+1] + ss_cost(optimals[i]); + costs[i] = mincost = costs[i+1] + ss_cost(optimals[i]); for (j=2; j<=max_super && i+j<=ninsts ; j++) { int super, jcost; super = lookup_super(origs+i,j); if (super >= 0) { jcost = costs[i+j] + ss_cost(super); - if (jcost <= costs[i]) { + if (jcost <= mincost) { optimals[i] = super; - costs[i] = jcost; + mincost = jcost; + if (!ss_greedy) + costs[i] = jcost; } } } @@ -1107,13 +1123,15 @@ void optimize_bb(short origs[], short op superinstructions in optimals */ void rewrite_bb(Cell *instps[], short *optimals, int ninsts) { - int i, nextdyn; + int i,j, nextdyn; Cell inst; for (i=0, nextdyn=0; i