Commit 69c0edd5 authored by Russ Cox's avatar Russ Cox

8g: discard tempalloc/tempfree experiment

in favor of tempname.
allows optimizer to do more.
unfortunately, optimizer seems to be broken; disable it.

R=ken2
https://golang.org/cl/163091
parent fdb030d8
...@@ -10,18 +10,16 @@ ...@@ -10,18 +10,16 @@
void void
mgen(Node *n, Node *n1, Node *rg) mgen(Node *n, Node *n1, Node *rg)
{ {
n1->ostk = 0;
n1->op = OEMPTY; n1->op = OEMPTY;
if(n->addable) { if(n->addable) {
*n1 = *n; *n1 = *n;
n1->ostk = 0;
if(n1->op == OREGISTER || n1->op == OINDREG) if(n1->op == OREGISTER || n1->op == OINDREG)
reg[n->val.u.reg]++; reg[n->val.u.reg]++;
return; return;
} }
if(n->type->width > widthptr) if(n->type->width > widthptr)
tempalloc(n1, n->type); tempname(n1, n->type);
else else
regalloc(n1, n->type, rg); regalloc(n1, n->type, rg);
cgen(n, n1); cgen(n, n1);
...@@ -30,9 +28,7 @@ mgen(Node *n, Node *n1, Node *rg) ...@@ -30,9 +28,7 @@ mgen(Node *n, Node *n1, Node *rg)
void void
mfree(Node *n) mfree(Node *n)
{ {
if(n->ostk) if(n->op == OREGISTER)
tempfree(n);
else if(n->op == OREGISTER)
regfree(n); regfree(n);
} }
...@@ -70,10 +66,9 @@ cgen(Node *n, Node *res) ...@@ -70,10 +66,9 @@ cgen(Node *n, Node *res)
// function calls on both sides? introduce temporary // function calls on both sides? introduce temporary
if(n->ullman >= UINF && res->ullman >= UINF) { if(n->ullman >= UINF && res->ullman >= UINF) {
tempalloc(&n1, n->type); tempname(&n1, n->type);
cgen(n, &n1); cgen(n, &n1);
cgen(&n1, res); cgen(&n1, res);
tempfree(&n1);
return; return;
} }
...@@ -107,10 +102,9 @@ cgen(Node *n, Node *res) ...@@ -107,10 +102,9 @@ cgen(Node *n, Node *res)
if(!n->addable && !res->addable) { if(!n->addable && !res->addable) {
// could use regalloc here sometimes, // could use regalloc here sometimes,
// but have to check for ullman >= UINF. // but have to check for ullman >= UINF.
tempalloc(&n1, n->type); tempname(&n1, n->type);
cgen(n, &n1); cgen(n, &n1);
cgen(&n1, res); cgen(&n1, res);
tempfree(&n1);
return; return;
} }
...@@ -132,12 +126,11 @@ cgen(Node *n, Node *res) ...@@ -132,12 +126,11 @@ cgen(Node *n, Node *res)
if(nl != N && nl->ullman >= UINF) if(nl != N && nl->ullman >= UINF)
if(nr != N && nr->ullman >= UINF) { if(nr != N && nr->ullman >= UINF) {
// both are hard // both are hard
tempalloc(&n1, nl->type); tempname(&n1, nl->type);
cgen(nl, &n1); cgen(nl, &n1);
n2 = *n; n2 = *n;
n2.left = &n1; n2.left = &n1;
cgen(&n2, res); cgen(&n2, res);
tempfree(&n1);
return; return;
} }
...@@ -240,11 +233,10 @@ cgen(Node *n, Node *res) ...@@ -240,11 +233,10 @@ cgen(Node *n, Node *res)
if(istype(nl->type, TMAP) || istype(nl->type, TCHAN)) { if(istype(nl->type, TMAP) || istype(nl->type, TCHAN)) {
// map has len in the first 32-bit word. // map has len in the first 32-bit word.
// a zero pointer means zero length // a zero pointer means zero length
tempalloc(&n1, types[tptr]); tempname(&n1, types[tptr]);
cgen(nl, &n1); cgen(nl, &n1);
regalloc(&n2, types[tptr], N); regalloc(&n2, types[tptr], N);
gmove(&n1, &n2); gmove(&n1, &n2);
tempfree(&n1);
n1 = n2; n1 = n2;
nodconst(&n2, types[tptr], 0); nodconst(&n2, types[tptr], 0);
...@@ -354,7 +346,7 @@ sbop: // symmetric binary ...@@ -354,7 +346,7 @@ sbop: // symmetric binary
abop: // asymmetric binary abop: // asymmetric binary
if(nl->ullman >= nr->ullman) { if(nl->ullman >= nr->ullman) {
tempalloc(&nt, nl->type); tempname(&nt, nl->type);
cgen(nl, &nt); cgen(nl, &nt);
mgen(nr, &n2, N); mgen(nr, &n2, N);
regalloc(&n1, nl->type, res); regalloc(&n1, nl->type, res);
...@@ -363,7 +355,6 @@ abop: // asymmetric binary ...@@ -363,7 +355,6 @@ abop: // asymmetric binary
gmove(&n1, res); gmove(&n1, res);
regfree(&n1); regfree(&n1);
mfree(&n2); mfree(&n2);
tempfree(&nt);
} else { } else {
regalloc(&n2, nr->type, res); regalloc(&n2, nr->type, res);
cgen(nr, &n2); cgen(nr, &n2);
...@@ -377,11 +368,10 @@ abop: // asymmetric binary ...@@ -377,11 +368,10 @@ abop: // asymmetric binary
return; return;
uop: // unary uop: // unary
tempalloc(&n1, nl->type); tempname(&n1, nl->type);
cgen(nl, &n1); cgen(nl, &n1);
gins(a, N, &n1); gins(a, N, &n1);
gmove(&n1, res); gmove(&n1, res);
tempfree(&n1);
return; return;
flt: // floating-point. 387 (not SSE2) to interoperate with 6c flt: // floating-point. 387 (not SSE2) to interoperate with 6c
...@@ -490,30 +480,27 @@ agen(Node *n, Node *res) ...@@ -490,30 +480,27 @@ agen(Node *n, Node *res)
if(nr->addable) { if(nr->addable) {
agenr(nl, &n3, res); agenr(nl, &n3, res);
if(!isconst(nr, CTINT)) { if(!isconst(nr, CTINT)) {
tempalloc(&tmp, types[TINT32]); tempname(&tmp, types[TINT32]);
cgen(nr, &tmp); cgen(nr, &tmp);
regalloc(&n1, tmp.type, N); regalloc(&n1, tmp.type, N);
gmove(&tmp, &n1); gmove(&tmp, &n1);
tempfree(&tmp);
} }
} else if(nl->addable) { } else if(nl->addable) {
if(!isconst(nr, CTINT)) { if(!isconst(nr, CTINT)) {
tempalloc(&tmp, types[TINT32]); tempname(&tmp, types[TINT32]);
cgen(nr, &tmp); cgen(nr, &tmp);
regalloc(&n1, tmp.type, N); regalloc(&n1, tmp.type, N);
gmove(&tmp, &n1); gmove(&tmp, &n1);
tempfree(&tmp);
} }
regalloc(&n3, types[tptr], res); regalloc(&n3, types[tptr], res);
agen(nl, &n3); agen(nl, &n3);
} else { } else {
tempalloc(&tmp, types[TINT32]); tempname(&tmp, types[TINT32]);
cgen(nr, &tmp); cgen(nr, &tmp);
nr = &tmp; nr = &tmp;
agenr(nl, &n3, res); agenr(nl, &n3, res);
regalloc(&n1, tmp.type, N); regalloc(&n1, tmp.type, N);
gins(optoas(OAS, tmp.type), &tmp, &n1); gins(optoas(OAS, tmp.type), &tmp, &n1);
tempfree(&tmp);
} }
// &a is in &n3 (allocated in res) // &a is in &n3 (allocated in res)
...@@ -693,11 +680,10 @@ igen(Node *n, Node *a, Node *res) ...@@ -693,11 +680,10 @@ igen(Node *n, Node *a, Node *res)
{ {
Node n1; Node n1;
tempalloc(&n1, types[tptr]); tempname(&n1, types[tptr]);
agen(n, &n1); agen(n, &n1);
regalloc(a, types[tptr], res); regalloc(a, types[tptr], res);
gmove(&n1, a); gmove(&n1, a);
tempfree(&n1);
a->op = OINDREG; a->op = OINDREG;
a->type = n->type; a->type = n->type;
} }
...@@ -713,11 +699,10 @@ agenr(Node *n, Node *a, Node *res) ...@@ -713,11 +699,10 @@ agenr(Node *n, Node *a, Node *res)
{ {
Node n1; Node n1;
tempalloc(&n1, types[tptr]); tempname(&n1, types[tptr]);
agen(n, &n1); agen(n, &n1);
regalloc(a, types[tptr], res); regalloc(a, types[tptr], res);
gmove(&n1, a); gmove(&n1, a);
tempfree(&n1);
} }
/* /*
...@@ -925,14 +910,12 @@ bgen(Node *n, int true, Prog *to) ...@@ -925,14 +910,12 @@ bgen(Node *n, int true, Prog *to)
// all the other ops have the same problem. // all the other ops have the same problem.
// We need to figure out what the right general // We need to figure out what the right general
// solution is, besides telling people to use float64. // solution is, besides telling people to use float64.
tempalloc(&t1, types[TFLOAT32]); tempname(&t1, types[TFLOAT32]);
tempalloc(&t2, types[TFLOAT32]); tempname(&t2, types[TFLOAT32]);
cgen(nr, &t1); cgen(nr, &t1);
cgen(nl, &t2); cgen(nl, &t2);
gmove(&t2, &tmp); gmove(&t2, &tmp);
gins(AFCOMFP, &t1, &tmp); gins(AFCOMFP, &t1, &tmp);
tempfree(&t2);
tempfree(&t1);
} }
gins(AFSTSW, N, &ax); gins(AFSTSW, N, &ax);
gins(ASAHF, N, N); gins(ASAHF, N, N);
...@@ -954,57 +937,49 @@ bgen(Node *n, int true, Prog *to) ...@@ -954,57 +937,49 @@ bgen(Node *n, int true, Prog *to)
if(is64(nr->type)) { if(is64(nr->type)) {
if(!nl->addable) { if(!nl->addable) {
tempalloc(&n1, nl->type); tempname(&n1, nl->type);
cgen(nl, &n1); cgen(nl, &n1);
nl = &n1; nl = &n1;
} }
if(!nr->addable) { if(!nr->addable) {
tempalloc(&n2, nr->type); tempname(&n2, nr->type);
cgen(nr, &n2); cgen(nr, &n2);
nr = &n2; nr = &n2;
} }
cmp64(nl, nr, a, to); cmp64(nl, nr, a, to);
if(nr == &n2)
tempfree(&n2);
if(nl == &n1)
tempfree(&n1);
break; break;
} }
a = optoas(a, nr->type); a = optoas(a, nr->type);
if(nr->ullman >= UINF) { if(nr->ullman >= UINF) {
tempalloc(&n1, nl->type); tempname(&n1, nl->type);
tempalloc(&tmp, nr->type); tempname(&tmp, nr->type);
cgen(nr, &tmp); cgen(nr, &tmp);
cgen(nl, &n1); cgen(nl, &n1);
regalloc(&n2, nr->type, N); regalloc(&n2, nr->type, N);
cgen(&tmp, &n2); cgen(&tmp, &n2);
tempfree(&tmp);
goto cmp; goto cmp;
} }
tempalloc(&n1, nl->type); tempname(&n1, nl->type);
cgen(nl, &n1); cgen(nl, &n1);
if(smallintconst(nr)) { if(smallintconst(nr)) {
gins(optoas(OCMP, nr->type), &n1, nr); gins(optoas(OCMP, nr->type), &n1, nr);
patch(gbranch(a, nr->type), to); patch(gbranch(a, nr->type), to);
tempfree(&n1);
break; break;
} }
tempalloc(&tmp, nr->type); tempname(&tmp, nr->type);
cgen(nr, &tmp); cgen(nr, &tmp);
regalloc(&n2, nr->type, N); regalloc(&n2, nr->type, N);
gmove(&tmp, &n2); gmove(&tmp, &n2);
tempfree(&tmp);
cmp: cmp:
gins(optoas(OCMP, nr->type), &n1, &n2); gins(optoas(OCMP, nr->type), &n1, &n2);
patch(gbranch(a, nr->type), to); patch(gbranch(a, nr->type), to);
regfree(&n2); regfree(&n2);
tempfree(&n1);
break; break;
} }
} }
...@@ -1073,8 +1048,8 @@ sgen(Node *n, Node *res, int32 w) ...@@ -1073,8 +1048,8 @@ sgen(Node *n, Node *res, int32 w)
nodreg(&dst, types[tptr], D_DI); nodreg(&dst, types[tptr], D_DI);
nodreg(&src, types[tptr], D_SI); nodreg(&src, types[tptr], D_SI);
tempalloc(&tsrc, types[tptr]); tempname(&tsrc, types[tptr]);
tempalloc(&tdst, types[tptr]); tempname(&tdst, types[tptr]);
if(!n->addable) if(!n->addable)
agen(n, &tsrc); agen(n, &tsrc);
if(!res->addable) if(!res->addable)
...@@ -1087,8 +1062,6 @@ sgen(Node *n, Node *res, int32 w) ...@@ -1087,8 +1062,6 @@ sgen(Node *n, Node *res, int32 w)
agen(res, &dst); agen(res, &dst);
else else
gmove(&tdst, &dst); gmove(&tdst, &dst);
tempfree(&tdst);
tempfree(&tsrc);
c = w % 4; // bytes c = w % 4; // bytes
q = w / 4; // doublewords q = w / 4; // doublewords
......
...@@ -60,12 +60,12 @@ cgen64(Node *n, Node *res) ...@@ -60,12 +60,12 @@ cgen64(Node *n, Node *res)
l = n->left; l = n->left;
r = n->right; r = n->right;
if(!l->addable) { if(!l->addable) {
tempalloc(&t1, l->type); tempname(&t1, l->type);
cgen(l, &t1); cgen(l, &t1);
l = &t1; l = &t1;
} }
if(r != N && !r->addable) { if(r != N && !r->addable) {
tempalloc(&t2, r->type); tempname(&t2, r->type);
cgen(r, &t2); cgen(r, &t2);
r = &t2; r = &t2;
} }
...@@ -417,11 +417,7 @@ cgen64(Node *n, Node *res) ...@@ -417,11 +417,7 @@ cgen64(Node *n, Node *res)
gins(AMOVL, &dx, &hi1); gins(AMOVL, &dx, &hi1);
splitclean(); splitclean();
out: out:;
if(r == &t2)
tempfree(&t2);
if(l == &t1)
tempfree(&t1);
} }
/* /*
......
...@@ -137,8 +137,6 @@ void ginit(void); ...@@ -137,8 +137,6 @@ void ginit(void);
void gclean(void); void gclean(void);
void regalloc(Node*, Type*, Node*); void regalloc(Node*, Type*, Node*);
void regfree(Node*); void regfree(Node*);
void tempalloc(Node*, Type*);
void tempfree(Node*);
Node* nodarg(Type*, int); Node* nodarg(Type*, int);
void nodreg(Node*, Type*, int); void nodreg(Node*, Type*, int);
void nodindreg(Node*, Type*, int); void nodindreg(Node*, Type*, int);
......
...@@ -80,6 +80,7 @@ compile(Node *fn) ...@@ -80,6 +80,7 @@ compile(Node *fn)
pc->as = ARET; // overwrite AEND pc->as = ARET; // overwrite AEND
pc->lineno = lineno; pc->lineno = lineno;
if(0)
if(!debug['N'] || debug['R'] || debug['P']) { if(!debug['N'] || debug['R'] || debug['P']) {
regopt(ptxt); regopt(ptxt);
} }
...@@ -198,7 +199,7 @@ cgen_callinter(Node *n, Node *res, int proc) ...@@ -198,7 +199,7 @@ cgen_callinter(Node *n, Node *res, int proc)
i = i->left; // interface i = i->left; // interface
if(!i->addable) { if(!i->addable) {
tempalloc(&tmpi, i->type); tempname(&tmpi, i->type);
cgen(i, &tmpi); cgen(i, &tmpi);
i = &tmpi; i = &tmpi;
} }
...@@ -230,9 +231,6 @@ cgen_callinter(Node *n, Node *res, int proc) ...@@ -230,9 +231,6 @@ cgen_callinter(Node *n, Node *res, int proc)
regfree(&nodr); regfree(&nodr);
regfree(&nodo); regfree(&nodo);
if(i == &tmpi)
tempfree(i);
setmaxarg(n->left->type); setmaxarg(n->left->type);
} }
...@@ -254,7 +252,7 @@ cgen_call(Node *n, int proc) ...@@ -254,7 +252,7 @@ cgen_call(Node *n, int proc)
if(n->left->ullman >= UINF) { if(n->left->ullman >= UINF) {
// if name involves a fn call // if name involves a fn call
// precompute the address of the fn // precompute the address of the fn
tempalloc(&afun, types[tptr]); tempname(&afun, types[tptr]);
cgen(n->left, &afun); cgen(n->left, &afun);
} }
...@@ -267,7 +265,6 @@ cgen_call(Node *n, int proc) ...@@ -267,7 +265,6 @@ cgen_call(Node *n, int proc)
if(n->left->ullman >= UINF) { if(n->left->ullman >= UINF) {
regalloc(&nod, types[tptr], N); regalloc(&nod, types[tptr], N);
cgen_as(&nod, &afun); cgen_as(&nod, &afun);
tempfree(&afun);
nod.type = t; nod.type = t;
ginscall(&nod, proc); ginscall(&nod, proc);
regfree(&nod); regfree(&nod);
...@@ -385,12 +382,11 @@ cgen_asop(Node *n) ...@@ -385,12 +382,11 @@ cgen_asop(Node *n)
nr = n->right; nr = n->right;
if(nr->ullman >= UINF && nl->ullman >= UINF) { if(nr->ullman >= UINF && nl->ullman >= UINF) {
tempalloc(&n1, nr->type); tempname(&n1, nr->type);
cgen(nr, &n1); cgen(nr, &n1);
n2 = *n; n2 = *n;
n2.right = &n1; n2.right = &n1;
cgen_asop(&n2); cgen_asop(&n2);
tempfree(&n1);
goto ret; goto ret;
} }
...@@ -475,12 +471,12 @@ cgen_asop(Node *n) ...@@ -475,12 +471,12 @@ cgen_asop(Node *n)
hard: hard:
if(nr->ullman > nl->ullman) { if(nr->ullman > nl->ullman) {
tempalloc(&n2, nr->type); tempname(&n2, nr->type);
cgen(nr, &n2); cgen(nr, &n2);
igen(nl, &n1, N); igen(nl, &n1, N);
} else { } else {
igen(nl, &n1, N); igen(nl, &n1, N);
tempalloc(&n2, nr->type); tempname(&n2, nr->type);
cgen(nr, &n2); cgen(nr, &n2);
} }
...@@ -489,13 +485,11 @@ hard: ...@@ -489,13 +485,11 @@ hard:
n3.right = &n2; n3.right = &n2;
n3.op = n->etype; n3.op = n->etype;
tempalloc(&n4, nl->type); tempname(&n4, nl->type);
cgen(&n3, &n4); cgen(&n3, &n4);
gmove(&n4, &n1); gmove(&n4, &n1);
regfree(&n1); regfree(&n1);
tempfree(&n4);
tempfree(&n2);
ret: ret:
; ;
...@@ -528,8 +522,8 @@ dodiv(int op, Type *t, Node *nl, Node *nr, Node *res, Node *ax, Node *dx) ...@@ -528,8 +522,8 @@ dodiv(int op, Type *t, Node *nl, Node *nr, Node *res, Node *ax, Node *dx)
{ {
Node n1, t1, t2, nz; Node n1, t1, t2, nz;
tempalloc(&t1, nl->type); tempname(&t1, nl->type);
tempalloc(&t2, nr->type); tempname(&t2, nr->type);
cgen(nl, &t1); cgen(nl, &t1);
cgen(nr, &t2); cgen(nr, &t2);
...@@ -546,8 +540,6 @@ dodiv(int op, Type *t, Node *nl, Node *nr, Node *res, Node *ax, Node *dx) ...@@ -546,8 +540,6 @@ dodiv(int op, Type *t, Node *nl, Node *nr, Node *res, Node *ax, Node *dx)
gins(optoas(OEXTEND, t), N, N); gins(optoas(OEXTEND, t), N, N);
gins(optoas(op, t), &n1, N); gins(optoas(op, t), &n1, N);
regfree(&n1); regfree(&n1);
tempfree(&t2);
tempfree(&t1);
if(op == ODIV) if(op == ODIV)
gmove(ax, res); gmove(ax, res);
...@@ -567,7 +559,7 @@ savex(int dr, Node *x, Node *oldx, Node *res, Type *t) ...@@ -567,7 +559,7 @@ savex(int dr, Node *x, Node *oldx, Node *res, Type *t)
// and not the destination // and not the destination
memset(oldx, 0, sizeof *oldx); memset(oldx, 0, sizeof *oldx);
if(r > 0 && !samereg(x, res)) { if(r > 0 && !samereg(x, res)) {
tempalloc(oldx, types[TINT32]); tempname(oldx, types[TINT32]);
gmove(x, oldx); gmove(x, oldx);
} }
...@@ -582,7 +574,6 @@ restx(Node *x, Node *oldx) ...@@ -582,7 +574,6 @@ restx(Node *x, Node *oldx)
if(oldx->op != 0) { if(oldx->op != 0) {
x->type = types[TINT32]; x->type = types[TINT32];
gmove(oldx, x); gmove(oldx, x);
tempfree(oldx);
} }
} }
...@@ -653,7 +644,7 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res) ...@@ -653,7 +644,7 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
memset(&oldcx, 0, sizeof oldcx); memset(&oldcx, 0, sizeof oldcx);
nodreg(&cx, types[TUINT32], D_CX); nodreg(&cx, types[TUINT32], D_CX);
if(reg[D_CX] > 1 && !samereg(&cx, res)) { if(reg[D_CX] > 1 && !samereg(&cx, res)) {
tempalloc(&oldcx, types[TUINT32]); tempname(&oldcx, types[TUINT32]);
gmove(&cx, &oldcx); gmove(&cx, &oldcx);
} }
...@@ -683,10 +674,8 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res) ...@@ -683,10 +674,8 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
patch(p1, pc); patch(p1, pc);
gins(a, &n1, &n2); gins(a, &n1, &n2);
if(oldcx.op != 0) { if(oldcx.op != 0)
gmove(&oldcx, &cx); gmove(&oldcx, &cx);
tempfree(&oldcx);
}
gmove(&n2, res); gmove(&n2, res);
...@@ -971,7 +960,7 @@ sliceslice: ...@@ -971,7 +960,7 @@ sliceslice:
if(bad) if(bad)
goto no; goto no;
tempalloc(&ntemp, res->type); tempname(&ntemp, res->type);
if(!sleasy(&nodes[0])) { if(!sleasy(&nodes[0])) {
cgen(&nodes[0], &ntemp); cgen(&nodes[0], &ntemp);
nnode0 = ntemp; nnode0 = ntemp;
...@@ -1079,8 +1068,6 @@ sliceslice: ...@@ -1079,8 +1068,6 @@ sliceslice:
if(!sleasy(res)) { if(!sleasy(res)) {
cgen(&nres, res); cgen(&nres, res);
} }
if(ntemp.op != OXXX)
tempfree(&ntemp);
return 1; return 1;
no: no:
......
...@@ -793,42 +793,6 @@ regfree(Node *n) ...@@ -793,42 +793,6 @@ regfree(Node *n)
fatal("regfree %R", i); fatal("regfree %R", i);
} }
void
tempalloc(Node *n, Type *t)
{
int w;
dowidth(t);
memset(n, 0, sizeof(*n));
n->op = ONAME;
n->sym = S;
n->type = t;
n->etype = t->etype;
n->class = PAUTO;
n->addable = 1;
n->ullman = 1;
n->noescape = 1;
n->ostk = stksize;
w = t->width;
stksize += w;
stksize = rnd(stksize, w);
n->xoffset = -stksize;
//print("tempalloc %d -> %d from %p\n", n->ostk, n->xoffset, __builtin_return_address(0));
if(stksize > maxstksize)
maxstksize = stksize;
}
void
tempfree(Node *n)
{
//print("tempfree %d\n", n->xoffset);
if(n->xoffset != -stksize)
fatal("tempfree %lld %d", -n->xoffset, stksize);
stksize = n->ostk;
}
/* /*
* initialize n to be register r of type t. * initialize n to be register r of type t.
*/ */
...@@ -1072,6 +1036,15 @@ bignodes(void) ...@@ -1072,6 +1036,15 @@ bignodes(void)
mpmovecflt(zerof.val.u.fval, 0); mpmovecflt(zerof.val.u.fval, 0);
} }
void
memname(Node *n, Type *t)
{
tempname(n, t);
strcpy(namebuf, n->sym->name);
namebuf[0] = '.'; // keep optimizer from registerizing
n->sym = lookup(namebuf);
}
void void
gmove(Node *f, Node *t) gmove(Node *f, Node *t)
{ {
...@@ -1297,8 +1270,8 @@ gmove(Node *f, Node *t) ...@@ -1297,8 +1270,8 @@ gmove(Node *f, Node *t)
} }
// set round to zero mode during conversion // set round to zero mode during conversion
tempalloc(&t1, types[TUINT16]); memname(&t1, types[TUINT16]);
tempalloc(&t2, types[TUINT16]); memname(&t2, types[TUINT16]);
gins(AFSTCW, N, &t1); gins(AFSTCW, N, &t1);
gins(AMOVW, ncon(0xf7f), &t2); gins(AMOVW, ncon(0xf7f), &t2);
gins(AFLDCW, &t2, N); gins(AFLDCW, &t2, N);
...@@ -1309,8 +1282,6 @@ gmove(Node *f, Node *t) ...@@ -1309,8 +1282,6 @@ gmove(Node *f, Node *t)
else else
gins(AFMOVVP, &r1, t); gins(AFMOVVP, &r1, t);
gins(AFLDCW, &t1, N); gins(AFLDCW, &t1, N);
tempfree(&t2);
tempfree(&t1);
return; return;
case CASE(TFLOAT32, TINT8): case CASE(TFLOAT32, TINT8):
...@@ -1320,7 +1291,7 @@ gmove(Node *f, Node *t) ...@@ -1320,7 +1291,7 @@ gmove(Node *f, Node *t)
case CASE(TFLOAT64, TUINT16): case CASE(TFLOAT64, TUINT16):
case CASE(TFLOAT64, TUINT8): case CASE(TFLOAT64, TUINT8):
// convert via int32. // convert via int32.
tempalloc(&t1, types[TINT32]); tempname(&t1, types[TINT32]);
gmove(f, &t1); gmove(f, &t1);
switch(tt) { switch(tt) {
default: default:
...@@ -1352,13 +1323,12 @@ gmove(Node *f, Node *t) ...@@ -1352,13 +1323,12 @@ gmove(Node *f, Node *t)
gmove(&t1, t); gmove(&t1, t);
break; break;
} }
tempfree(&t1);
return; return;
case CASE(TFLOAT32, TUINT32): case CASE(TFLOAT32, TUINT32):
case CASE(TFLOAT64, TUINT32): case CASE(TFLOAT64, TUINT32):
// convert via int64. // convert via int64.
tempalloc(&t1, types[TINT64]); tempname(&t1, types[TINT64]);
gmove(f, &t1); gmove(f, &t1);
split64(&t1, &tlo, &thi); split64(&t1, &tlo, &thi);
gins(ACMPL, &thi, ncon(0)); gins(ACMPL, &thi, ncon(0));
...@@ -1367,7 +1337,6 @@ gmove(Node *f, Node *t) ...@@ -1367,7 +1337,6 @@ gmove(Node *f, Node *t)
patch(p1, pc); patch(p1, pc);
gmove(&tlo, t); gmove(&tlo, t);
splitclean(); splitclean();
tempfree(&t1);
return; return;
case CASE(TFLOAT32, TUINT64): case CASE(TFLOAT32, TUINT64):
...@@ -1405,12 +1374,11 @@ gmove(Node *f, Node *t) ...@@ -1405,12 +1374,11 @@ gmove(Node *f, Node *t)
// otherwise, subtract 2^63, convert, and add it back. // otherwise, subtract 2^63, convert, and add it back.
// set round to zero mode during conversion // set round to zero mode during conversion
tempalloc(&t1, types[TUINT16]); memname(&t1, types[TUINT16]);
tempalloc(&t2, types[TUINT16]); memname(&t2, types[TUINT16]);
gins(AFSTCW, N, &t1); gins(AFSTCW, N, &t1);
gins(AMOVW, ncon(0xf7f), &t2); gins(AMOVW, ncon(0xf7f), &t2);
gins(AFLDCW, &t2, N); gins(AFLDCW, &t2, N);
tempfree(&t2);
// actual work // actual work
gmove(&two63f, &f0); gmove(&two63f, &f0);
...@@ -1432,7 +1400,6 @@ gmove(Node *f, Node *t) ...@@ -1432,7 +1400,6 @@ gmove(Node *f, Node *t)
// restore rounding mode // restore rounding mode
gins(AFLDCW, &t1, N); gins(AFLDCW, &t1, N);
tempfree(&t1);
return; return;
/* /*
...@@ -1487,7 +1454,7 @@ gmove(Node *f, Node *t) ...@@ -1487,7 +1454,7 @@ gmove(Node *f, Node *t)
nodreg(&ax, types[TUINT32], D_AX); nodreg(&ax, types[TUINT32], D_AX);
nodreg(&dx, types[TUINT32], D_DX); nodreg(&dx, types[TUINT32], D_DX);
nodreg(&cx, types[TUINT32], D_CX); nodreg(&cx, types[TUINT32], D_CX);
tempalloc(&t1, f->type); tempname(&t1, f->type);
split64(&t1, &tlo, &thi); split64(&t1, &tlo, &thi);
gmove(f, &t1); gmove(f, &t1);
gins(ACMPL, &thi, ncon(0)); gins(ACMPL, &thi, ncon(0));
...@@ -1516,7 +1483,6 @@ gmove(Node *f, Node *t) ...@@ -1516,7 +1483,6 @@ gmove(Node *f, Node *t)
gmove(&r1, t); gmove(&r1, t);
patch(p2, pc); patch(p2, pc);
splitclean(); splitclean();
tempfree(&t1);
return; return;
/* /*
...@@ -1563,10 +1529,9 @@ gmove(Node *f, Node *t) ...@@ -1563,10 +1529,9 @@ gmove(Node *f, Node *t)
case CASE(TFLOAT64, TFLOAT32): case CASE(TFLOAT64, TFLOAT32):
if(f->op == OREGISTER && t->op == OREGISTER) { if(f->op == OREGISTER && t->op == OREGISTER) {
tempalloc(&r1, types[TFLOAT32]); tempname(&r1, types[TFLOAT32]);
gins(AFMOVFP, f, &r1); gins(AFMOVFP, f, &r1);
gins(AFMOVF, &r1, t); gins(AFMOVF, &r1, t);
tempfree(&r1);
return; return;
} }
if(f->op == OREGISTER) if(f->op == OREGISTER)
...@@ -1597,10 +1562,9 @@ hard: ...@@ -1597,10 +1562,9 @@ hard:
hardmem: hardmem:
// requires memory intermediate // requires memory intermediate
tempalloc(&r1, cvt); tempname(&r1, cvt);
gmove(f, &r1); gmove(f, &r1);
gmove(&r1, t); gmove(&r1, t);
tempfree(&r1);
return; return;
fatal: fatal:
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#define D_HI D_NONE #define D_HI D_NONE
#define D_LO D_NONE #define D_LO D_NONE
#define isregtype(t) ((t)>= D_AX && (t)<=D_R15)
#define BLOAD(r) band(bnot(r->refbehind), r->refahead) #define BLOAD(r) band(bnot(r->refbehind), r->refahead)
#define BSTORE(r) band(bnot(r->calbehind), r->calahead) #define BSTORE(r) band(bnot(r->calbehind), r->calahead)
#define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
......
...@@ -287,8 +287,12 @@ regopt(Prog *firstp) ...@@ -287,8 +287,12 @@ regopt(Prog *firstp)
case ASHRW: case ASHRW:
case AIMULL: case AIMULL:
case AIMULW: case AIMULW:
case ANEGB:
case ANEGL: case ANEGL:
case ANEGW:
case ANOTB:
case ANOTL: case ANOTL:
case ANOTW:
case AADCL: case AADCL:
case ASBBL: case ASBBL:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment