mirror of
https://github.com/golang/go
synced 2024-11-21 22:24:40 -07:00
gc: introduce temp = nod+tempname
R=ken2 CC=golang-dev https://golang.org/cl/4967052
This commit is contained in:
parent
c45c0c0c1d
commit
9854fd2a0e
@ -877,3 +877,13 @@ tempname(Node *nn, Type *t)
|
|||||||
|
|
||||||
*nn = *n;
|
*nn = *n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node*
|
||||||
|
temp(Type *t)
|
||||||
|
{
|
||||||
|
Node *n;
|
||||||
|
|
||||||
|
n = nod(OXXX, N, N);
|
||||||
|
tempname(n, t);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
@ -991,6 +991,7 @@ void gen(Node *n);
|
|||||||
void genlist(NodeList *l);
|
void genlist(NodeList *l);
|
||||||
Node* sysfunc(char *name);
|
Node* sysfunc(char *name);
|
||||||
void tempname(Node *n, Type *t);
|
void tempname(Node *n, Type *t);
|
||||||
|
Node* temp(Type*);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* init.c
|
* init.c
|
||||||
|
@ -123,8 +123,7 @@ walkrange(Node *n)
|
|||||||
// no need to make a potentially expensive copy.
|
// no need to make a potentially expensive copy.
|
||||||
ha = a;
|
ha = a;
|
||||||
} else {
|
} else {
|
||||||
ha = nod(OXXX, N, N);
|
ha = temp(a->type);
|
||||||
tempname(ha, a->type);
|
|
||||||
init = list(init, nod(OAS, ha, a));
|
init = list(init, nod(OAS, ha, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,17 +132,14 @@ walkrange(Node *n)
|
|||||||
fatal("walkrange");
|
fatal("walkrange");
|
||||||
|
|
||||||
case TARRAY:
|
case TARRAY:
|
||||||
hv1 = nod(OXXX, N, n);
|
hv1 = temp(types[TINT]);
|
||||||
tempname(hv1, types[TINT]);
|
hn = temp(types[TINT]);
|
||||||
hn = nod(OXXX, N, N);
|
|
||||||
tempname(hn, types[TINT]);
|
|
||||||
hp = nil;
|
hp = nil;
|
||||||
|
|
||||||
init = list(init, nod(OAS, hv1, N));
|
init = list(init, nod(OAS, hv1, N));
|
||||||
init = list(init, nod(OAS, hn, nod(OLEN, ha, N)));
|
init = list(init, nod(OAS, hn, nod(OLEN, ha, N)));
|
||||||
if(v2) {
|
if(v2) {
|
||||||
hp = nod(OXXX, N, N);
|
hp = temp(ptrto(n->type->type));
|
||||||
tempname(hp, ptrto(n->type->type));
|
|
||||||
tmp = nod(OINDEX, ha, nodintconst(0));
|
tmp = nod(OINDEX, ha, nodintconst(0));
|
||||||
tmp->etype = 1; // no bounds check
|
tmp->etype = 1; // no bounds check
|
||||||
init = list(init, nod(OAS, hp, nod(OADDR, tmp, N)));
|
init = list(init, nod(OAS, hp, nod(OADDR, tmp, N)));
|
||||||
@ -168,8 +164,7 @@ walkrange(Node *n)
|
|||||||
th = typ(TARRAY);
|
th = typ(TARRAY);
|
||||||
th->type = ptrto(types[TUINT8]);
|
th->type = ptrto(types[TUINT8]);
|
||||||
th->bound = (sizeof(struct Hiter) + widthptr - 1) / widthptr;
|
th->bound = (sizeof(struct Hiter) + widthptr - 1) / widthptr;
|
||||||
hit = nod(OXXX, N, N);
|
hit = temp(th);
|
||||||
tempname(hit, th);
|
|
||||||
|
|
||||||
fn = syslook("mapiterinit", 1);
|
fn = syslook("mapiterinit", 1);
|
||||||
argtype(fn, t->down);
|
argtype(fn, t->down);
|
||||||
@ -200,10 +195,8 @@ walkrange(Node *n)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TCHAN:
|
case TCHAN:
|
||||||
hv1 = nod(OXXX, N, n);
|
hv1 = temp(t->type);
|
||||||
tempname(hv1, t->type);
|
hb = temp(types[TBOOL]);
|
||||||
hb = nod(OXXX, N, N);
|
|
||||||
tempname(hb, types[TBOOL]);
|
|
||||||
|
|
||||||
n->ntest = nod(ONE, hb, nodbool(0));
|
n->ntest = nod(ONE, hb, nodbool(0));
|
||||||
a = nod(OAS2RECV, N, N);
|
a = nod(OAS2RECV, N, N);
|
||||||
@ -215,18 +208,15 @@ walkrange(Node *n)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TSTRING:
|
case TSTRING:
|
||||||
ohv1 = nod(OXXX, N, N);
|
ohv1 = temp(types[TINT]);
|
||||||
tempname(ohv1, types[TINT]);
|
|
||||||
|
|
||||||
hv1 = nod(OXXX, N, N);
|
hv1 = temp(types[TINT]);
|
||||||
tempname(hv1, types[TINT]);
|
|
||||||
init = list(init, nod(OAS, hv1, N));
|
init = list(init, nod(OAS, hv1, N));
|
||||||
|
|
||||||
if(v2 == N)
|
if(v2 == N)
|
||||||
a = nod(OAS, hv1, mkcall("stringiter", types[TINT], nil, ha, hv1));
|
a = nod(OAS, hv1, mkcall("stringiter", types[TINT], nil, ha, hv1));
|
||||||
else {
|
else {
|
||||||
hv2 = nod(OXXX, N, N);
|
hv2 = temp(types[TINT]);
|
||||||
tempname(hv2, types[TINT]);
|
|
||||||
a = nod(OAS2, N, N);
|
a = nod(OAS2, N, N);
|
||||||
a->list = list(list1(hv1), hv2);
|
a->list = list(list1(hv1), hv2);
|
||||||
fn = syslook("stringiter2", 0);
|
fn = syslook("stringiter2", 0);
|
||||||
|
@ -194,8 +194,7 @@ walkselect(Node *sel)
|
|||||||
n->ntest->etype = 1; // pointer does not escape
|
n->ntest->etype = 1; // pointer does not escape
|
||||||
typecheck(&n->ntest, Erv);
|
typecheck(&n->ntest, Erv);
|
||||||
} else {
|
} else {
|
||||||
tmp = nod(OXXX, N, N);
|
tmp = temp(types[TBOOL]);
|
||||||
tempname(tmp, types[TBOOL]);
|
|
||||||
a = nod(OADDR, tmp, N);
|
a = nod(OADDR, tmp, N);
|
||||||
a->etype = 1; // pointer does not escape
|
a->etype = 1; // pointer does not escape
|
||||||
typecheck(&a, Erv);
|
typecheck(&a, Erv);
|
||||||
@ -215,8 +214,7 @@ walkselect(Node *sel)
|
|||||||
n->left->etype = 1; // pointer does not escape
|
n->left->etype = 1; // pointer does not escape
|
||||||
typecheck(&n->left, Erv);
|
typecheck(&n->left, Erv);
|
||||||
} else {
|
} else {
|
||||||
tmp = nod(OXXX, N, N);
|
tmp = temp(ch->type->type);
|
||||||
tempname(tmp, ch->type->type);
|
|
||||||
a = nod(OADDR, tmp, N);
|
a = nod(OADDR, tmp, N);
|
||||||
a->etype = 1; // pointer does not escape
|
a->etype = 1; // pointer does not escape
|
||||||
typecheck(&a, Erv);
|
typecheck(&a, Erv);
|
||||||
@ -287,8 +285,7 @@ walkselect(Node *sel)
|
|||||||
|
|
||||||
// generate sel-struct
|
// generate sel-struct
|
||||||
setlineno(sel);
|
setlineno(sel);
|
||||||
var = nod(OXXX, N, N);
|
var = temp(ptrto(types[TUINT8]));
|
||||||
tempname(var, ptrto(types[TUINT8]));
|
|
||||||
r = nod(OAS, var, mkcall("newselect", var->type, nil, nodintconst(sel->xoffset)));
|
r = nod(OAS, var, mkcall("newselect", var->type, nil, nodintconst(sel->xoffset)));
|
||||||
typecheck(&r, Etop);
|
typecheck(&r, Etop);
|
||||||
init = list(init, r);
|
init = list(init, r);
|
||||||
|
@ -689,13 +689,11 @@ slicelit(int ctxt, Node *n, Node *var, NodeList **init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make new auto *array (3 declare)
|
// make new auto *array (3 declare)
|
||||||
vauto = nod(OXXX, N, N);
|
vauto = temp(ptrto(t));
|
||||||
tempname(vauto, ptrto(t));
|
|
||||||
|
|
||||||
// set auto to point at new temp or heap (3 assign)
|
// set auto to point at new temp or heap (3 assign)
|
||||||
if(n->esc == EscNone) {
|
if(n->esc == EscNone) {
|
||||||
a = nod(OXXX, N, N);
|
a = temp(t);
|
||||||
tempname(a, t);
|
|
||||||
*init = list(*init, nod(OAS, a, N)); // zero new temp
|
*init = list(*init, nod(OAS, a, N)); // zero new temp
|
||||||
a = nod(OADDR, a, N);
|
a = nod(OADDR, a, N);
|
||||||
} else {
|
} else {
|
||||||
@ -859,8 +857,7 @@ ctxt = 0;
|
|||||||
// for i = 0; i < len(vstat); i++ {
|
// for i = 0; i < len(vstat); i++ {
|
||||||
// map[vstat[i].a] = vstat[i].b
|
// map[vstat[i].a] = vstat[i].b
|
||||||
// }
|
// }
|
||||||
index = nod(OXXX, N, N);
|
index = temp(types[TINT]);
|
||||||
tempname(index, types[TINT]);
|
|
||||||
|
|
||||||
a = nod(OINDEX, vstat, index);
|
a = nod(OINDEX, vstat, index);
|
||||||
a->etype = 1; // no bounds checking
|
a->etype = 1; // no bounds checking
|
||||||
|
@ -2788,8 +2788,7 @@ copyexpr(Node *n, Type *t, NodeList **init)
|
|||||||
{
|
{
|
||||||
Node *a, *l;
|
Node *a, *l;
|
||||||
|
|
||||||
l = nod(OXXX, N, N);
|
l = temp(t);
|
||||||
tempname(l, t);
|
|
||||||
a = nod(OAS, l, n);
|
a = nod(OAS, l, n);
|
||||||
typecheck(&a, Etop);
|
typecheck(&a, Etop);
|
||||||
walkexpr(&a, init);
|
walkexpr(&a, init);
|
||||||
|
@ -515,8 +515,7 @@ exprswitch(Node *sw)
|
|||||||
exprname = N;
|
exprname = N;
|
||||||
cas = nil;
|
cas = nil;
|
||||||
if(arg != Strue && arg != Sfalse) {
|
if(arg != Strue && arg != Sfalse) {
|
||||||
exprname = nod(OXXX, N, N);
|
exprname = temp(sw->ntest->type);
|
||||||
tempname(exprname, sw->ntest->type);
|
|
||||||
cas = list1(nod(OAS, exprname, sw->ntest));
|
cas = list1(nod(OAS, exprname, sw->ntest));
|
||||||
typechecklist(cas, Etop);
|
typechecklist(cas, Etop);
|
||||||
}
|
}
|
||||||
@ -673,20 +672,17 @@ typeswitch(Node *sw)
|
|||||||
* predeclare temporary variables
|
* predeclare temporary variables
|
||||||
* and the boolean var
|
* and the boolean var
|
||||||
*/
|
*/
|
||||||
facename = nod(OXXX, N, N);
|
facename = temp(sw->ntest->right->type);
|
||||||
tempname(facename, sw->ntest->right->type);
|
|
||||||
a = nod(OAS, facename, sw->ntest->right);
|
a = nod(OAS, facename, sw->ntest->right);
|
||||||
typecheck(&a, Etop);
|
typecheck(&a, Etop);
|
||||||
cas = list(cas, a);
|
cas = list(cas, a);
|
||||||
|
|
||||||
casebody(sw, facename);
|
casebody(sw, facename);
|
||||||
|
|
||||||
boolname = nod(OXXX, N, N);
|
boolname = temp(types[TBOOL]);
|
||||||
tempname(boolname, types[TBOOL]);
|
|
||||||
typecheck(&boolname, Erv);
|
typecheck(&boolname, Erv);
|
||||||
|
|
||||||
hashname = nod(OXXX, N, N);
|
hashname = temp(types[TUINT32]);
|
||||||
tempname(hashname, types[TUINT32]);
|
|
||||||
typecheck(&hashname, Erv);
|
typecheck(&hashname, Erv);
|
||||||
|
|
||||||
t = sw->ntest->right->type;
|
t = sw->ntest->right->type;
|
||||||
|
@ -562,8 +562,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
// and map index has an implicit one.
|
// and map index has an implicit one.
|
||||||
lpost = nil;
|
lpost = nil;
|
||||||
if(l->op == OINDEXMAP) {
|
if(l->op == OINDEXMAP) {
|
||||||
var = nod(OXXX, N, N);
|
var = temp(l->type);
|
||||||
tempname(var, l->type);
|
|
||||||
n->list->n = var;
|
n->list->n = var;
|
||||||
a = nod(OAS, l, var);
|
a = nod(OAS, l, var);
|
||||||
typecheck(&a, Etop);
|
typecheck(&a, Etop);
|
||||||
@ -571,8 +570,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
}
|
}
|
||||||
l = n->list->next->n;
|
l = n->list->next->n;
|
||||||
if(l->op == OINDEXMAP) {
|
if(l->op == OINDEXMAP) {
|
||||||
var = nod(OXXX, N, N);
|
var = temp(l->type);
|
||||||
tempname(var, l->type);
|
|
||||||
n->list->next->n = var;
|
n->list->next->n = var;
|
||||||
a = nod(OAS, l, var);
|
a = nod(OAS, l, var);
|
||||||
typecheck(&a, Etop);
|
typecheck(&a, Etop);
|
||||||
@ -975,8 +973,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
|
|
||||||
case ONEW:
|
case ONEW:
|
||||||
if(n->esc == EscNone && n->type->type->width < (1<<16)) {
|
if(n->esc == EscNone && n->type->type->width < (1<<16)) {
|
||||||
r = nod(OXXX, N, N);
|
r = temp(n->type->type);
|
||||||
tempname(r, n->type->type);
|
|
||||||
*init = list(*init, nod(OAS, r, N)); // zero temp
|
*init = list(*init, nod(OAS, r, N)); // zero temp
|
||||||
r = nod(OADDR, r, N);
|
r = nod(OADDR, r, N);
|
||||||
typecheck(&r, Erv);
|
typecheck(&r, Erv);
|
||||||
@ -1164,8 +1161,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
case OMAPLIT:
|
case OMAPLIT:
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
nvar = nod(OXXX, N, N);
|
nvar = temp(n->type);
|
||||||
tempname(nvar, n->type);
|
|
||||||
anylit(0, n, nvar, init);
|
anylit(0, n, nvar, init);
|
||||||
n = nvar;
|
n = nvar;
|
||||||
goto ret;
|
goto ret;
|
||||||
@ -1194,8 +1190,7 @@ makenewvar(Type *t, NodeList **init, Node **nstar)
|
|||||||
{
|
{
|
||||||
Node *nvar, *nas;
|
Node *nvar, *nas;
|
||||||
|
|
||||||
nvar = nod(OXXX, N, N);
|
nvar = temp(t);
|
||||||
tempname(nvar, t);
|
|
||||||
nas = nod(OAS, nvar, callnew(t->type));
|
nas = nod(OAS, nvar, callnew(t->type));
|
||||||
typecheck(&nas, Etop);
|
typecheck(&nas, Etop);
|
||||||
walkexpr(&nas, init);
|
walkexpr(&nas, init);
|
||||||
@ -1291,8 +1286,7 @@ ascompatet(int op, NodeList *nl, Type **nr, int fp, NodeList **init)
|
|||||||
// deferred until all the return arguments
|
// deferred until all the return arguments
|
||||||
// have been pulled from the output arguments
|
// have been pulled from the output arguments
|
||||||
if(fncall(l, r->type)) {
|
if(fncall(l, r->type)) {
|
||||||
tmp = nod(OXXX, N, N);
|
tmp = temp(r->type);
|
||||||
tempname(tmp, r->type);
|
|
||||||
typecheck(&tmp, Erv);
|
typecheck(&tmp, Erv);
|
||||||
a = nod(OAS, l, tmp);
|
a = nod(OAS, l, tmp);
|
||||||
a = convas(a, init);
|
a = convas(a, init);
|
||||||
@ -1434,8 +1428,7 @@ ascompatte(int op, Node *call, int isddd, Type **nl, NodeList *lr, int fp, NodeL
|
|||||||
// copy into temporaries.
|
// copy into temporaries.
|
||||||
alist = nil;
|
alist = nil;
|
||||||
for(l=structfirst(&savel, &r->type); l; l=structnext(&savel)) {
|
for(l=structfirst(&savel, &r->type); l; l=structnext(&savel)) {
|
||||||
a = nod(OXXX, N, N);
|
a = temp(l->type);
|
||||||
tempname(a, l->type);
|
|
||||||
alist = list(alist, a);
|
alist = list(alist, a);
|
||||||
}
|
}
|
||||||
a = nod(OAS2, N, N);
|
a = nod(OAS2, N, N);
|
||||||
@ -1778,8 +1771,7 @@ reorder1(NodeList *all)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make assignment of fncall to tempname
|
// make assignment of fncall to tempname
|
||||||
a = nod(OXXX, N, N);
|
a = temp(n->right->type);
|
||||||
tempname(a, n->right->type);
|
|
||||||
a = nod(OAS, a, n->right);
|
a = nod(OAS, a, n->right);
|
||||||
g = list(g, a);
|
g = list(g, a);
|
||||||
|
|
||||||
@ -1882,8 +1874,7 @@ reorder3(NodeList *all)
|
|||||||
if(c2 > c1) {
|
if(c2 > c1) {
|
||||||
if(vmatch1(n1->left, n2->right)) {
|
if(vmatch1(n1->left, n2->right)) {
|
||||||
// delay assignment to n1->left
|
// delay assignment to n1->left
|
||||||
q = nod(OXXX, N, N);
|
q = temp(n1->right->type);
|
||||||
tempname(q, n1->right->type);
|
|
||||||
q = nod(OAS, n1->left, q);
|
q = nod(OAS, n1->left, q);
|
||||||
n1->left = q->right;
|
n1->left = q->right;
|
||||||
r = list(r, q);
|
r = list(r, q);
|
||||||
@ -2146,8 +2137,7 @@ append(Node *n, NodeList **init)
|
|||||||
|
|
||||||
l = nil;
|
l = nil;
|
||||||
|
|
||||||
ns = nod(OXXX, N, N); // var s
|
ns = temp(nsrc->type);
|
||||||
tempname(ns, nsrc->type);
|
|
||||||
l = list(l, nod(OAS, ns, nsrc)); // s = src
|
l = list(l, nod(OAS, ns, nsrc)); // s = src
|
||||||
|
|
||||||
na = nodintconst(argc); // const argc
|
na = nodintconst(argc); // const argc
|
||||||
@ -2164,8 +2154,7 @@ append(Node *n, NodeList **init)
|
|||||||
conv(na, types[TINT64]))));
|
conv(na, types[TINT64]))));
|
||||||
l = list(l, nx);
|
l = list(l, nx);
|
||||||
|
|
||||||
nn = nod(OXXX, N, N); // var n
|
nn = temp(types[TINT]);
|
||||||
tempname(nn, types[TINT]);
|
|
||||||
l = list(l, nod(OAS, nn, nod(OLEN, ns, N))); // n = len(s)
|
l = list(l, nod(OAS, nn, nod(OLEN, ns, N))); // n = len(s)
|
||||||
|
|
||||||
nx = nod(OSLICE, ns, nod(OKEY, N, nod(OADD, nn, na))); // ...s[:n+argc]
|
nx = nod(OSLICE, ns, nod(OKEY, N, nod(OADD, nn, na))); // ...s[:n+argc]
|
||||||
|
Loading…
Reference in New Issue
Block a user