ref: a5b54d2ac3f54b4a1ad3b736c7c599fff1607f79
parent: a4c149a1f8d9256f4aad6625b5868874e1f512ee
author: Ori Bernstein <ori@eigenstate.org>
date: Mon May 7 21:28:51 EDT 2012
Fix loop conditions.
- Set the loop initializer correctly
- Fix the optimization for jumping
- Don't pass NULL as the operand of the Oasn
--- a/8/insns.def
+++ b/8/insns.def
@@ -16,6 +16,7 @@
*/
/* Note, the mov instruction is specified in an overly general manner. */
+Insn(Inone, "BAD_INSN", 0)
Insn(Imov, "\tmov%t %x,%x\n", 0)
Insn(Imovz, "\tmovz%0t%1t %x,%x\n", 0)
Insn(Imovs, "\tmovs%0t%1t %x,%x\n", 0)
@@ -26,8 +27,8 @@
Insn(Ior, "\tor%d %r,%x\n", 0)
Insn(Ixor, "\txor%d %r,%x\n", 0)
-Insn(Itest, "\ttest%t %r,%r", 0)
-Insn(Icmp, "\tcmp%t %r,%r", 0)
+Insn(Itest, "\ttest%t %r,%r\n", 0)
+Insn(Icmp, "\tcmp%t %r,%r\n", 0)
Insn(Ipush, "\tpush%t %r\n", 0)
Insn(Ipop, "\tpop%t %r\n", 0)
--- a/8/isel.c
+++ b/8/isel.c
@@ -156,7 +156,7 @@
case Lbool: loclit(&l, v->lit.boolval); break;
case Lint: loclit(&l, v->lit.intval); break;
default:
- die("Literal type %s should be blob", litstr(v->lit.littype));+ die("Literal type %s should be blob", litstr(v->lit.littype));}
break;
default:
@@ -176,24 +176,24 @@
Loc l;
Reg crtab[][Nmode + 1] = {- [Ral] = {Ral, Rax, Reax},- [Rcl] = {Rcl, Rcx, Recx},- [Rdl] = {Rdl, Rdx, Redx},- [Rbl] = {Rbl, Rbx, Rebx},+ [Ral] = {Rnone, Ral, Rax, Reax},+ [Rcl] = {Rnone, Rcl, Rcx, Recx},+ [Rdl] = {Rnone, Rdl, Rdx, Redx},+ [Rbl] = {Rnone, Rbl, Rbx, Rebx},- [Rax] = {Ral, Rax, Reax},- [Rcx] = {Rcl, Rcx, Recx},- [Rdx] = {Rdl, Rdx, Redx},- [Rbx] = {Rbl, Rbx, Rebx},- [Rsi] = {0, Rsi, Resi},- [Rdi] = {0, Rdi, Redi},+ [Rax] = {Rnone, Ral, Rax, Reax},+ [Rcx] = {Rnone, Rcl, Rcx, Recx},+ [Rdx] = {Rnone, Rdl, Rdx, Redx},+ [Rbx] = {Rnone, Rbl, Rbx, Rebx},+ [Rsi] = {Rnone, Rnone, Rsi, Resi},+ [Rdi] = {Rnone, Rnone, Rdi, Redi},- [Reax] = {Ral, Rax, Reax},- [Recx] = {Rcl, Rcx, Recx},- [Redx] = {Rdl, Rdx, Redx},- [Rebx] = {Rbl, Rbx, Rebx},- [Resi] = {0, Rsi, Resi},- [Redi] = {0, Rdi, Redi},+ [Reax] = {Rnone, Ral, Rax, Reax},+ [Recx] = {Rnone, Rcl, Rcx, Recx},+ [Redx] = {Rnone, Rdl, Rdx, Redx},+ [Rebx] = {Rnone, Rbl, Rbx, Rebx},+ [Resi] = {Rnone, Rnone, Rsi, Resi},+ [Redi] = {Rnone, Rnone, Rdi, Redi},};
if (r.type != Locreg)
die("Non-reg passed to coreg()");@@ -214,7 +214,7 @@
}
}
for (i = 0; i < Nmode; i++)
- s->rtaken[reginterferes[l.reg][i]] = 1;
+ s->rtaken[reginterferes[l.reg][i]] = 1;
return l;
}
@@ -227,7 +227,7 @@
if (s->rtaken[r])
die("Reg %s is already taken", regnames[r]);for (i = 0; i < Nmode; i++)
- s->rtaken[reginterferes[r][i]] = 1;
+ s->rtaken[reginterferes[r][i]] = 1;
locreg(&l, r);
return l;
}
@@ -319,17 +319,18 @@
Loc l1, l2;
AsmOp cond, jmp;
- cond = reloptab[exprop(n)].test;
- jmp = reloptab[exprop(n)].jmp;
+ cond = reloptab[exprop(args[0])].test;
+ jmp = reloptab[exprop(args[0])].jmp;
/* if we have a cond, we're knocking off the redundant test,
* and want to eval the children */
if (cond) {a = selexpr(s, args[0]->expr.args[0]);
b = selexpr(s, args[0]->expr.args[1]);
+ b = inr(s, b);
} else {cond = Itest;
jmp = Ijnz;
- a = selexpr(s, args[0]); /* cond */
+ a = inr(s, selexpr(s, args[0])); /* cond */
b = a;
}
@@ -360,6 +361,9 @@
args = n->expr.args;
r = (Loc){Locnone, };+ printf("===================\n");+ dump(n, stdout);
+ printf("===================\n"); switch (exprop(n)) {case Oadd: r = binop(s, Iadd, args[0], args[1]); break;
case Osub: r = binop(s, Isub, args[0], args[1]); break;
@@ -391,6 +395,7 @@
case Oeq: case One: case Ogt: case Oge: case Olt: case Ole:
a = selexpr(s, args[0]);
b = selexpr(s, args[1]);
+ b = inr(s, b);
c = getreg(s, ModeB);
r = coreg(c, mode(n));
g(s, reloptab[exprop(n)].test, &a, &b, NULL);
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -193,7 +193,14 @@
simp(s, n->loopstmt.body);
simp(s, n->loopstmt.step);
simp(s, lcond);
- c = simp(s, n->loopstmt.cond);
+ printf("*********************\n");+ dump(n->loopstmt.cond, stdout);
+ printf("*********************\n");+ breakhere();
+ c = rval(s, n->loopstmt.cond);
+ printf("*********************\n");+ dump(c, stdout);
+ printf("*********************\n");cjmp(s, c, lbody, lend);
simp(s, lend);
}
@@ -249,7 +256,6 @@
* foo = foo ? blah*/
case Oaddeq: case Osubeq: case Omuleq: case Odiveq: case Omodeq:
case Oboreq: case Obandeq: case Obxoreq: case Obsleq:
- breakhere();
assert(fusedmap[exprop(n)] != Obad);
u = simp(s, args[0]);
v = simp(s, args[1]);
@@ -279,6 +285,7 @@
* x = x + 1
*/
case Opostinc:
+ breakhere();
r = simp(s, args[0]);
v = mkexpr(-1, Oadd, mkint(-1, 1), r, NULL);
t = mkexpr(-1, Ostor, r, v, NULL);
@@ -305,10 +312,9 @@
jmp(s, s->endlbl);
break;
case Oasn:
- breakhere();
- t = rval(s, args[0]);
- v = lval(s, args[1]);
- r = mkexpr(-1, Ostor, r, v, NULL);
+ t = lval(s, args[0]);
+ v = rval(s, args[1]);
+ r = mkexpr(-1, Ostor, t, v, NULL);
break;
default:
if (isimpure(n)) {--- a/parse/infer.c
+++ b/parse/infer.c
@@ -168,7 +168,6 @@
b = t;
}
- printf("--- unify %s => %s\n", tystr(a), tystr(b));mergecstrs(ctx, a, b);
if (a->type != b->type) {if (a->type == Tyvar)
--- a/parse/node.c
+++ b/parse/node.c
@@ -87,7 +87,7 @@
n = mknode(line, Nloopstmt);
n->loopstmt.init = init;
- n->loopstmt.cond = init;
+ n->loopstmt.cond = cond;
n->loopstmt.step = incr;
n->loopstmt.body = body;
--
⑨