]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: remove several copies of outervalue
authorDmitry Vyukov <dvyukov@google.com>
Tue, 3 Feb 2015 09:48:35 +0000 (12:48 +0300)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 12 Feb 2015 08:31:05 +0000 (08:31 +0000)
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>
src/cmd/gc/racewalk.c
src/cmd/gc/walk.c

index f3134dab23d21e7170d3a93340b386d1a645c4a6..757b02cb122f5622af603c34449828bbc927c405 100644 (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)
 {
index 91568371d7a6d037c87ef83c9de16f6ef1c4cca9..99dd0d3c09311ffb17f6cad29fd8f57aa5111c74 100644 (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;
                }