1 /* $Id: ra_profits.c,v 1.12 1994/06/24 10:28:03 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 /* R E G I S T E R A L L O C A T I O N
8 * R A _ P R O F I T S . C
13 #include "../share/types.h"
14 #include "../share/debug.h"
15 #include "../share/lset.h"
16 #include "../share/global.h"
19 #include "ra_profits.h"
21 STATIC bool test_cond(cond,val)
29 return val >= -128 && val < 128;
31 return val >= 0 && val <= 63;
33 return val >= 0 && val <= 8;
37 STATIC short map_value(tab,val,time)
38 struct cond_tab tab[];
44 for (p = &tab[0]; ; p++) {
45 if (test_cond(p->mc_cond,val)) {
46 return (time ? p->mc_tval : p->mc_sval);
52 STATIC short index_value(tab,n,time)
53 struct cond_tab tab[];
60 return (time ? p->mc_tval : p->mc_sval);
64 allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out)
65 short itemtyp, localtyp,totyp,size;
67 short *time_out, *space_out;
69 cond_p m = (cond_p) 0;
71 if (localtyp == reg_loop) localtyp = reg_any;
72 if (size == ws || size ==ps && totyp == reg_pointer) {
75 m = alocaltab[localtyp][totyp];
78 if (use_any_as_pointer || totyp == reg_pointer)
79 m = alocaddrtab[localtyp][totyp];
88 if (use_any_as_pointer || totyp == reg_pointer)
92 if (use_any_as_pointer || totyp == reg_pointer)
97 *time_out = (m == (cond_p) 0 ? -1 : map_value(m,off,TRUE));
98 *space_out = (m == (cond_p) 0 ? -1 : map_value(m,off,FALSE));
100 fprintf(stderr,"itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off);
101 fprintf(stderr,"ALLOCSCORE = (%d,%d)\n",*time_out,*space_out);
105 opening_cost(itemtyp,localtyp,off,time_out,space_out)
106 short itemtyp, localtyp;
108 short *time_out, *space_out;
112 if (localtyp == reg_loop) localtyp = reg_any;
115 m = olocaltab[localtyp];
118 m = olocaddrtab[localtyp];
133 *time_out = (m == (cond_p) 0 ? 1000 : map_value(m,off,TRUE));
134 *space_out = (m == (cond_p) 0 ? 1000 : map_value(m,off,FALSE));
136 fprintf(stderr,"itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off);
137 fprintf(stderr,"OPEN_COST = (%d,%d)\n",*time_out,*space_out);
144 regsave_cost(regs,time_out,space_out)
145 short regs[], *time_out, *space_out;
147 /* Estimate the costs of saving and restoring the registers
148 * The array regs contains the number of registers of every
152 short n = regs[reg_any] + regs[reg_pointer] + regs[reg_float];
155 *time_out = index_value(regsav_cost,n,TRUE);
156 *space_out = index_value(regsav_cost,n,FALSE);
158 fprintf(stderr,"REGSAVE COST, n=%d, (%d,%d)\n",n,*time_out,*space_out);
164 STATIC short dyn_inits(inits)
171 for (i = Lfirst(inits); i != (Lindex) 0; i = Lnext(i,inits)) {
172 b = (bblock_p) Lelem(i);
173 sum += loop_scale(Lnrelems(b->b_loops));
180 compute_profits(alloclist,time_opt)
184 /* Compute the profits attribute of every allocation.
185 * If the item of an allocation may be put in several types
186 * of register, we choose only the most advanteagous one.
189 register alloc_p alloc;
190 short s,t,rtyp,maxsc;
197 for (alloc = alloclist; alloc != (alloc_p) 0; alloc = alloc->al_next) {
199 item = alloc->al_item;
200 switch(item->it_type) {
205 off = item->i_t.it_off;
210 for (rtyp = item->it_regtype; ; rtyp = reg_any) {
211 allocscore( item->it_type,
218 opening_cost( item->it_type,
223 nr_inits = Lnrelems(alloc->al_inits);
224 s = alloc->al_susecount * space -
227 if (!alloc->al_isloop && nr_inits > 0) {
228 /* might lead to increase of execution time */
233 cnt = alloc->al_dusecount;
235 t = cnt * time - dyn_inits(alloc->al_inits) * otime;
236 sc = (time_opt ? t : s);
238 fprintf(stderr, "cnt: %d time: %d otime: %d t: %d s: %d score: %d\n", cnt, time, otime, t, s, sc);
242 alloc->al_regtype = rtyp;
243 alloc->al_profits = sc;
245 if (rtyp == reg_any) break;