cvsuser 03/03/04 02:46:48
Modified: . MANIFEST
languages/imcc imc.c symreg.h
Added: languages/imcc/t/reg spill.t
Log:
fixed spilling
Revision Changes Path
1.321 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.320
retrieving revision 1.321
diff -u -w -r1.320 -r1.321
--- MANIFEST 3 Mar 2003 17:01:54 -0000 1.320
+++ MANIFEST 4 Mar 2003 10:46:43 -0000 1.321
@@ -1407,6 +1407,7 @@
languages/imcc/t/imcpasm/opt1.t
languages/imcc/t/imcpasm/opt2.t
languages/imcc/t/imcpasm/sub.t
+languages/imcc/t/reg/spill.t
languages/imcc/t/syn/bsr.t
languages/imcc/t/syn/clash.t
languages/imcc/t/syn/const.t
1.43 +14 -6 parrot/languages/imcc/imc.c
Index: imc.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/imc.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -w -r1.42 -r1.43
--- imc.c 3 Mar 2003 09:11:02 -0000 1.42
+++ imc.c 4 Mar 2003 10:46:46 -0000 1.43
@@ -41,7 +41,7 @@
debug(DEBUG_IMC, "\n------------------------\n");
debug(DEBUG_IMC, "processing sub %s\n", function);
debug(DEBUG_IMC, "------------------------\n\n");
- if (IMCC_VERBOSE > 1 || (IMCC_DEBUG & DEBUG_IMC))
+ if (IMCC_VERBOSE || (IMCC_DEBUG & DEBUG_IMC))
imc_stat_init();
/* consecutive labels, if_branch, unused_labels ... */
@@ -89,7 +89,7 @@
compute_spilling_costs();
/* simplify until no changes can be made */
/* while (simplify()) {} */
- order_spilling(); /* puts the remaing item on stack */
+ order_spilling(); /* put the remaining items on stack */
to_spill = try_allocate();
allocated = 1;
@@ -97,6 +97,12 @@
if ( to_spill >= 0 ) {
allocated = 0;
spill(interpreter, to_spill);
+ /*
+ * TODO build the new cfg/reglist on the fly in spill() and
+ * do life analysis there for only the involved regs
+ */
+ find_basic_blocks();
+ build_cfg();
build_reglist();
life_analysis();
}
@@ -107,7 +113,7 @@
}
if (IMCC_DEBUG & DEBUG_IMC)
dump_instructions();
- if (IMCC_VERBOSE > 1 || (IMCC_DEBUG & DEBUG_IMC))
+ if (IMCC_VERBOSE || (IMCC_DEBUG & DEBUG_IMC))
print_stat();
imcstack_free(nodeStack);
}
@@ -392,7 +398,7 @@
used = 1;
break;
}
- if (used && ins->flags & ITSPILL) {
+ if (used && r->usage & U_SPILL) {
r->score = 100000;
goto done;
}
@@ -692,6 +698,7 @@
debug(DEBUG_IMC, "#Spilling [%s]:\n", reglist[spilled]->name);
new_symbol = old_symbol = reglist[spilled];
+ new_symbol->usage |= U_SPILL;
p31 = mk_pasm_reg(str_dup("P31"));
n_spilled++;
@@ -713,7 +720,7 @@
regs[1] = p31;
sprintf(buf, "%d", n_spilled);
regs[2] = mk_const(str_dup(buf), 'I');
- sprintf(buf, "%%s, %%s[%%s] #FETCH %s", new_symbol->name);
+ sprintf(buf, "%%s, %%s[%%s] #FETCH %s", old_symbol->name);
tmp = INS(interpreter, "set", buf, regs, 3, 4, 0);
tmp->bbindex = ins->bbindex;
tmp->flags |= ITSPILL;
@@ -746,12 +753,13 @@
if (needs_fetch || needs_store) {
sprintf(buf, "%s_%d", old_symbol->name, n++);
new_symbol = mk_symreg(str_dup(buf), old_symbol->set);
+ new_symbol->usage |= U_SPILL;
}
}
free(buf);
- /* update line nr info */
+ /* update index */
for(i = 0, ins = instructions; ins; ins = ins->next) {
ins->index = i++;
}
1.15 +2 -1 parrot/languages/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/symreg.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -r1.14 -r1.15
--- symreg.h 21 Feb 2003 12:26:40 -0000 1.14
+++ symreg.h 4 Mar 2003 10:46:46 -0000 1.15
@@ -40,7 +40,8 @@
enum USAGE {
U_KEYED = 1 << 0, /* array, hash, keyed */
- U_NEW = 1 << 1, /* PMS was inited */
+ U_NEW = 1 << 1, /* PMC was inited */
+ U_SPILL = 1 << 2, /* reg is spilled */
};
typedef struct _SymReg {
1.1 parrot/languages/imcc/t/reg/spill.t
Index: spill.t
===================================================================
#!perl
use strict;
use TestCompiler tests => 2;
use Test::More qw(skip);
##############################
# Test the ability of the register allocator to
# generate spills.
#
output_is(<<'CODE', <<'OUT', "allocate 1");
.sub _MAIN
$I0 = 0
$I1 = 1
$I2 = 2
$I3 = 3
$I4 = 4
$I5 = 5
$I6 = 6
$I7 = 7
$I8 = 8
$I9 = 9
$I10 = 10
$I11 = 11
$I12 = 12
$I13 = 13
$I14 = 14
$I15 = 15
$I16 = 16
$I17 = 17
$I18 = 18
$I19 = 19
$I20 = 20
$I21 = 21
$I22 = 22
$I23 = 23
$I24 = 24
$I25 = 25
$I26 = 26
$I27 = 27
$I28 = 28
$I29 = 29
$I30 = 30
$I31 = 31
$I32 = 32
$I33 = 33
$I34 = 34
$I35 = 35
$I36 = 36
$I37 = 37
$I38 = 38
$I39 = 39
$I40 = 40
print $I0
print "\n"
print $I10
print "\n"
print $I20
print "\n"
print $I30
print "\n"
print $I40
print "\n"
end
.end
CODE
0
10
20
30
40
OUT
##############################
output_is(<<'CODE', <<'OUT', "spill 1");
# Test the ability of the register allocator to
# generate spills.
#
.sub _MAIN
$I0 = 0
$I1 = 1
$I2 = 2
$I3 = 3
$I4 = 4
$I5 = 5
$I6 = 6
$I7 = 7
$I8 = 8
$I9 = 9
$I10 = 10
$I11 = 11
$I12 = 12
$I13 = 13
$I14 = 14
$I15 = 15
$I16 = 16
$I17 = 17
$I18 = 18
$I19 = 19
$I20 = 20
$I21 = 21
$I22 = 22
$I23 = 23
$I24 = 24
$I25 = 25
$I26 = 26
$I27 = 27
$I28 = 28
$I29 = 29
$I30 = 30
$I31 = 31
$I32 = 32
$I33 = 33
$I34 = 34
$I35 = 35
$I36 = 36
$I37 = 37
$I38 = 38
$I39 = 39
$I40 = $I0 + $I1
$I41 = $I2 + $I3
$I42 = $I4 + $I5
$I43 = $I6 + $I7
$I44 = $I8 + $I9
$I50 = $I10 + $I11
$I51 = $I12 + $I13
$I52 = $I14 + $I15
$I53 = $I16 + $I17
$I54 = $I18 + $I19
$I60 = $I20 + $I21
$I61 = $I22 + $I23
$I62 = $I24 + $I25
$I63 = $I26 + $I27
$I64 = $I28 + $I29
$I70 = $I30 + $I31
$I71 = $I32 + $I33
$I72 = $I34 + $I35
$I73 = $I36 + $I37
$I74 = $I38 + $I39
print $I0
print $I1
print $I2
print $I3
print $I4
print $I5
print $I6
print $I7
print $I8
print $I9
print "\n"
print $I10
print $I11
print $I12
print $I13
print $I14
print $I15
print $I16
print $I17
print $I18
print $I19
print "\n"
print $I20
print $I21
print $I22
print $I23
print $I24
print $I25
print $I26
print $I27
print $I28
print $I29
print "\n"
print $I30
print $I31
print $I32
print $I33
print $I34
print $I35
print $I36
print $I37
print $I38
print $I39
print "\n"
print $I40
print $I41
print $I42
print $I43
print $I44
print "\n"
print $I50
print $I51
print $I52
print $I53
print $I54
print "\n"
print $I60
print $I61
print $I62
print $I63
print $I64
print "\n"
print $I70
print $I71
print $I72
print $I73
print $I74
print "\n"
end
.end
CODE
0123456789
10111213141516171819
20212223242526272829
30313233343536373839
1591317
2125293337
4145495357
6165697377
OUT