1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:40:03 -07:00

cmd/gc: refactor racewalk

It is refactoring towards generic walk
+ it handles mode nodes.
Partially fixes 4228 issue.

R=golang-dev, lvd, rsc
CC=golang-dev
https://golang.org/cl/6775098
This commit is contained in:
Dmitriy Vyukov 2012-11-07 12:01:31 +04:00
parent eb2e6e59ee
commit 703043c8dc

View File

@ -15,7 +15,6 @@
#include <u.h> #include <u.h>
#include <libc.h> #include <libc.h>
#include "go.h" #include "go.h"
#include "opnames.h"
// TODO(dvyukov): do not instrument initialization as writes: // TODO(dvyukov): do not instrument initialization as writes:
// a := make([]int, 10) // a := make([]int, 10)
@ -88,16 +87,19 @@ static void
racewalknode(Node **np, NodeList **init, int wr, int skip) racewalknode(Node **np, NodeList **init, int wr, int skip)
{ {
Node *n, *n1; Node *n, *n1;
NodeList *l;
NodeList *fini; NodeList *fini;
n = *np; n = *np;
if(n == N) if(n == N)
return; return;
if(0)
print("op=%s, left=[ %N ], right=[ %N ], right's type=%T, n's type=%T, n's class=%d\n", if(debug['w'] > 1)
opnames[n->op], n->left, n->right, n->right ? n->right->type : nil, n->type, n->class); dump("racewalk-before", n);
setlineno(n); setlineno(n);
if(init == nil || init == &n->ninit)
fatal("racewalk: bad init list");
racewalklist(n->ninit, nil); racewalklist(n->ninit, nil);
@ -146,16 +148,9 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
goto ret; goto ret;
case OFOR: case OFOR:
if(n->ntest != N)
racewalklist(n->ntest->ninit, nil);
racewalknode(&n->nincr, init, wr, 0);
racewalklist(n->nbody, nil);
goto ret; goto ret;
case OIF: case OIF:
racewalknode(&n->ntest, &n->ninit, wr, 0);
racewalklist(n->nbody, nil);
racewalklist(n->nelse, nil);
goto ret; goto ret;
case OPROC: case OPROC:
@ -164,34 +159,25 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
case OCALLINTER: case OCALLINTER:
racewalknode(&n->left, init, 0, 0); racewalknode(&n->left, init, 0, 0);
racewalklist(n->list, init);
goto ret; goto ret;
case OCALLFUNC: case OCALLFUNC:
racewalknode(&n->left, init, 0, 0); racewalknode(&n->left, init, 0, 0);
racewalklist(n->list, init);
goto ret; goto ret;
case OCALLMETH: case OCALLMETH:
racewalklist(n->list, init);
goto ret; goto ret;
case ORETURN: case ORETURN:
racewalklist(n->list, nil);
goto ret; goto ret;
case OSELECT: case OSELECT:
// n->nlist is nil by now because this code
// is running after walkselect
racewalklist(n->nbody, nil);
goto ret; goto ret;
case OSWITCH: case OSWITCH:
if(n->ntest->op == OTYPESW) if(n->ntest->op == OTYPESW)
// TODO(dvyukov): the expression can contain calls or reads. // TODO(dvyukov): the expression can contain calls or reads.
return; return;
racewalknode(&n->ntest, &n->ninit, 0, 0);
racewalklist(n->nbody, nil);
goto ret; goto ret;
case OEMPTY: case OEMPTY:
@ -301,7 +287,6 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
case OSLICEARR: case OSLICEARR:
// Seems to only lead to double instrumentation. // Seems to only lead to double instrumentation.
//racewalknode(&n->left, init, 0, 0); //racewalknode(&n->left, init, 0, 0);
//racewalklist(n->list, init);
goto ret; goto ret;
case OADDR: case OADDR:
@ -375,6 +360,18 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
} }
ret: ret:
if(n->op != OBLOCK) // OBLOCK is handled above in a special way.
racewalklist(n->list, init);
l = nil;
racewalknode(&n->ntest, &l, 0, 0);
n->ninit = concat(n->ninit, l);
l = nil;
racewalknode(&n->nincr, &l, 0, 0);
n->ninit = concat(n->ninit, l);
racewalklist(n->nbody, nil);
racewalklist(n->nelse, nil);
racewalklist(n->rlist, nil);
*np = n; *np = n;
} }