cvsuser 03/02/08 03:50:58
Modified: . MANIFEST
languages/imcc imcc.y instructions.c optimizer.c
languages/imcc/t/imcpasm opt1.t
Added: languages/imcc/t/imcpasm cfg.t
Log:
imcc-cfg - remove some unreachable code
Revision Changes Path
1.311 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.310
retrieving revision 1.311
diff -u -w -r1.310 -r1.311
--- MANIFEST 7 Feb 2003 17:06:57 -0000 1.310
+++ MANIFEST 8 Feb 2003 11:50:30 -0000 1.311
@@ -1391,6 +1391,7 @@
languages/imcc/symreg.c
languages/imcc/symreg.h
languages/imcc/t/harness
+languages/imcc/t/imcpasm/cfg.t
languages/imcc/t/imcpasm/opt1.t
languages/imcc/t/imcpasm/opt2.t
languages/imcc/t/imcpasm/sub.t
1.43 +5 -4 parrot/languages/imcc/imcc.y
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/imcc.y,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -w -r1.42 -r1.43
--- imcc.y 7 Feb 2003 17:04:13 -0000 1.42
+++ imcc.y 8 Feb 2003 11:50:34 -0000 1.43
@@ -112,15 +112,16 @@
Instruction * INS_LABEL(SymReg * r0, int emit)
{
Instruction *i = _mk_instruction("","%s:", R1(r0), 0);
+ i->type = ITLABEL;
if (emit)
emitb(i);
- i->type = ITLABEL;
return i;
}
static Instruction * iLABEL(SymReg * r0) {
- Instruction *i = emitb(_mk_instruction("","%s:", R1(r0), 0));
+ Instruction *i = _mk_instruction("","%s:", R1(r0), 0);
i->type = ITLABEL;
+ i = emitb(i);
clear_state();
return i;
}
@@ -353,8 +354,6 @@
/* make the instruction */
ins = _mk_instruction(name, format, r, dirs);
- if (emit)
- emitb(ins);
ins->keys |= keyvec;
/* fill iin oplib's info */
ins->opnum = op;
@@ -389,6 +388,8 @@
/* XXX probably a CATCH block */
ins->type = ITADDR | IF_r1_branch | ITBRANCH;
}
+ if (emit)
+ emitb(ins);
} else {
fataly(EX_SOFTWARE, "iANY", line,"op not found '%s' (%s<%d>)\n",
fullname, name, nargs);
1.21 +25 -0 parrot/languages/imcc/instructions.c
Index: instructions.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/instructions.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -w -r1.20 -r1.21
--- instructions.c 31 Jan 2003 10:54:08 -0000 1.20
+++ instructions.c 8 Feb 2003 11:50:34 -0000 1.21
@@ -226,6 +226,8 @@
tmp->prev = ins;
tmp->next = next;
next->prev = tmp;
+ if (!tmp->line)
+ tmp->line = ins->line;
}
/* move instruction ins to to */
@@ -240,11 +242,34 @@
/* Emits the instructions buffered in 'instructions' */
Instruction * emitb(Instruction * i) {
+ Instruction *prev;
+
if (!i)
return 0;
if(!instructions)
last_ins = instructions = i;
else {
+ if ((last_ins->type & IF_goto) && !(i->type & ITLABEL)) {
+ debug(DEBUG_CFG, "unreachable ins dropped line %d op %s\n",
+ line - 1, i->op);
+ return i;
+ }
+ if ((last_ins->type & IF_goto) && (i->type & ITLABEL) &&
+ !strcmp(last_ins->op, "branch") &&
+ !strcmp(last_ins->r[0]->name, i->r[0]->name)) {
+ debug(DEBUG_CFG, "dead branch dropped line %d op %s\n",
+ line - 1, i->op);
+ prev = last_ins->prev;
+ if (!prev)
+ instructions = i;
+ else
+ prev->next = i;
+ i->prev = prev;
+ free_ins(last_ins);
+ last_ins = i;
+ i->line = line - 1;
+ return i;
+ }
last_ins->next = i;
i->prev = last_ins;
last_ins = i;
1.11 +1 -1 parrot/languages/imcc/optimizer.c
Index: optimizer.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- optimizer.c 7 Feb 2003 14:05:51 -0000 1.10
+++ optimizer.c 8 Feb 2003 11:50:34 -0000 1.11
@@ -188,7 +188,7 @@
int used;
for (last = 0, ins = instructions; ins; ins = ins->next) {
- if (ins->type & ITLABEL) {
+ if ((ins->type & ITLABEL) && *ins->r[0]->name != '_') {
SymReg * lab = ins->r[0];
used = 0;
for (ins2 = instructions; ins2; ins2 = ins2->next) {
1.2 +38 -1 parrot/languages/imcc/t/imcpasm/opt1.t
Index: opt1.t
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/opt1.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- opt1.t 10 Dec 2002 08:55:12 -0000 1.1
+++ opt1.t 8 Feb 2003 11:50:58 -0000 1.2
@@ -1,6 +1,6 @@
#!perl
use strict;
-use TestCompiler tests => 2;
+use TestCompiler tests => 5;
use Test::More qw(skip);
##############################
@@ -35,3 +35,40 @@
end
OUT
+##############################
+output_is(<<'CODE', <<'OUT', "unreachable 3");
+.sub _test
+ goto L
+ print "ok\n"
+L:
+ end
+ noop
+ noop
+.end
+CODE
+_test:
+ end
+OUT
+
+##############################
+output_is(<<'CODE', <<'OUT', "unused local label");
+.sub _main
+ branch L2
+L2: end
+.end
+CODE
+_main:
+ end
+OUT
+
+##############################
+output_is(<<'CODE', <<'OUT', "unused global label");
+.sub _main
+ branch _L2
+_L2: end
+.end
+CODE
+_main:
+_L2:
+ end
+OUT
1.1 parrot/languages/imcc/t/imcpasm/cfg.t
Index: cfg.t
===================================================================
#!perl
use strict;
use TestCompiler tests => 3;
use Test::More qw(skip);
##############################
output_is(<<'CODE', <<'OUT', "unreachable 1");
.sub _test
bsr L
print "ok\n"
end
noop
noop
L: print "sub\n"
ret
.end
CODE
_test:
bsr L
print "ok\n"
end
L:
print "sub\n"
ret
OUT
output_is(<<'CODE', <<'OUT', "unreachable 2");
.sub _test
print "ok\n"
end
noop
noop
.end
CODE
_test:
print "ok\n"
end
OUT
output_is(<<'CODE', <<'OUT', "unreachable 3");
.sub _test
goto L
print "ok\n"
L:
end
noop
noop
.end
CODE
_test:
L:
end
OUT