1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

cmd/gc: remove several copies of outervalue

Walk calls it outervalue, racewalk calls it basenod,
isstack does it manually and slightly differently.

Change-Id: Id5b5d32b8faf143fe9d34bd08457bfab6fb33daa
Reviewed-on: https://go-review.googlesource.com/3745
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Dmitry Vyukov 2015-02-03 12:48:35 +03:00
parent 9568126f35
commit c1bbf0a2ea
2 changed files with 12 additions and 32 deletions

View File

@ -24,7 +24,6 @@ static void racewalknode(Node **np, NodeList **init, int wr, int skip);
static int callinstr(Node **n, NodeList **init, int wr, int skip);
static Node* uintptraddr(Node *n);
static void makeaddable(Node *n);
static Node* basenod(Node *n);
static void foreach(Node *n, void(*f)(Node*, void*), void *c);
static void hascallspred(Node *n, void *c);
static void appendinit(Node **np, NodeList *init);
@ -155,12 +154,8 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
default:
fatal("racewalk: unknown node type %O", n->op);
case OASOP:
case OAS:
case OAS2:
case OAS2RECV:
case OAS2FUNC:
case OAS2MAPR:
racewalknode(&n->left, init, 1, 0);
racewalknode(&n->right, init, 0, 0);
goto ret;
@ -350,7 +345,7 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
goto ret;
case OEFACE:
racewalknode(&n->left, init, 0, 0);
// n->left is Type* which is not interesting.
racewalknode(&n->right, init, 0, 0);
goto ret;
@ -393,6 +388,10 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
case OARRAYLIT: // lowered to assignments
case OMAPLIT:
case OSTRUCTLIT:
case OAS2:
case OAS2RECV:
case OAS2MAPR:
case OASOP:
yyerror("racewalk: %O must be lowered by now", n->op);
goto ret;
@ -489,7 +488,7 @@ callinstr(Node **np, NodeList **init, int wr, int skip)
if(isartificial(n))
return 0;
b = basenod(n);
b = outervalue(n);
// it skips e.g. stores to ... parameter array
if(isartificial(b))
return 0;
@ -499,7 +498,7 @@ callinstr(Node **np, NodeList **init, int wr, int skip)
// that has got a pointer inside. Whether it points to
// the heap or not is impossible to know at compile time
if((class&PHEAP) || class == PPARAMREF || class == PEXTERN
|| b->op == OINDEX || b->op == ODOTPTR || b->op == OIND || b->op == OXDOT) {
|| b->op == OINDEX || b->op == ODOTPTR || b->op == OIND) {
hascalls = 0;
foreach(n, hascallspred, &hascalls);
if(hascalls) {
@ -568,25 +567,6 @@ uintptraddr(Node *n)
return r;
}
// basenod returns the simplest child node of n pointing to the same
// memory area.
static Node*
basenod(Node *n)
{
for(;;) {
if(n->op == ODOT || n->op == OXDOT || n->op == OCONVNOP || n->op == OCONV || n->op == OPAREN) {
n = n->left;
continue;
}
if(n->op == OINDEX && isfixedarray(n->type)) {
n = n->left;
continue;
}
break;
}
return n;
}
static Node*
detachexpr(Node *n, NodeList **init)
{

View File

@ -1963,8 +1963,7 @@ isstack(Node *n)
{
Node *defn;
while(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP || n->op == OINDEX && isfixedarray(n->left->type))
n = n->left;
n = outervalue(n);
// If n is *autotmp and autotmp = &foo, replace n with foo.
// We introduce such temps when initializing struct literals.
@ -1995,8 +1994,7 @@ isstack(Node *n)
static int
isglobal(Node *n)
{
while(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP || n->op == OINDEX && isfixedarray(n->left->type))
n = n->left;
n = outervalue(n);
switch(n->op) {
case ONAME:
@ -2355,7 +2353,9 @@ Node*
outervalue(Node *n)
{
for(;;) {
if(n->op == ODOT || n->op == OPAREN) {
if(n->op == OXDOT)
fatal("OXDOT in walk");
if(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP) {
n = n->left;
continue;
}