1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:41:36 -07:00

cmd/gc: run escape analysis always (even in -N mode)

Fixes #8585.
Removes some little-used code paths.

LGTM=josharian
R=golang-codereviews, minux, josharian
CC=golang-codereviews, iant, r
https://golang.org/cl/132970043
This commit is contained in:
Russ Cox 2014-09-24 15:20:03 -04:00
parent 50c9d63459
commit 00d2f916ad
5 changed files with 1503 additions and 13 deletions

View File

@ -54,9 +54,6 @@ addrescapes(Node *n)
if(n->class == PAUTO && n->esc == EscNever) if(n->class == PAUTO && n->esc == EscNever)
break; break;
if(debug['N'] && n->esc != EscUnknown)
fatal("without escape analysis, only PAUTO's should have esc: %N", n);
switch(n->class) { switch(n->class) {
case PPARAMREF: case PPARAMREF:
addrescapes(n->defn); addrescapes(n->defn);
@ -91,8 +88,7 @@ addrescapes(Node *n)
snprint(buf, sizeof buf, "&%S", n->sym); snprint(buf, sizeof buf, "&%S", n->sym);
n->heapaddr->sym = lookup(buf); n->heapaddr->sym = lookup(buf);
n->heapaddr->orig->sym = n->heapaddr->sym; n->heapaddr->orig->sym = n->heapaddr->sym;
if(!debug['N']) n->esc = EscHeap;
n->esc = EscHeap;
if(debug['m']) if(debug['m'])
print("%L: moved to heap: %N\n", n->lineno, n); print("%L: moved to heap: %N\n", n->lineno, n);
curfn = oldfn; curfn = oldfn;

View File

@ -481,8 +481,12 @@ main(int argc, char *argv[])
} }
// Phase 5: Escape analysis. // Phase 5: Escape analysis.
if(!debug['N']) // Required for moving heap allocations onto stack,
escapes(xtop); // which in turn is required by the closure implementation,
// which stores the addresses of stack variables into the closure.
// If the closure does not escape, it needs to be on the stack
// or else the stack copier will not update it.
escapes(xtop);
// Escape analysis moved escaped values off stack. // Escape analysis moved escaped values off stack.
// Move large values off stack too. // Move large values off stack too.

View File

@ -736,10 +736,6 @@ reswitch:
l = n->left; l = n->left;
if((t = l->type) == T) if((t = l->type) == T)
goto error; goto error;
// top&Eindir means this is &x in *&x. (or the arg to built-in print)
// n->etype means code generator flagged it as non-escaping.
if(debug['N'] && !(top & Eindir) && !n->etype)
addrescapes(n->left);
n->type = ptrto(t); n->type = ptrto(t);
goto ret; goto ret;
@ -2119,8 +2115,6 @@ lookdot(Node *n, Type *t, int dostrcmp)
if(!eqtype(rcvr, tt)) { if(!eqtype(rcvr, tt)) {
if(rcvr->etype == tptr && eqtype(rcvr->type, tt)) { if(rcvr->etype == tptr && eqtype(rcvr->type, tt)) {
checklvalue(n->left, "call pointer method on"); checklvalue(n->left, "call pointer method on");
if(debug['N'])
addrescapes(n->left);
n->left = nod(OADDR, n->left, N); n->left = nod(OADDR, n->left, N);
n->left->implicit = 1; n->left->implicit = 1;
typecheck(&n->left, Etype|Erv); typecheck(&n->left, Etype|Erv);

View File

@ -7,6 +7,8 @@
// Test, using compiler diagnostic flags, that the escape analysis is working. // Test, using compiler diagnostic flags, that the escape analysis is working.
// Compiles but does not run. Inlining is disabled. // Compiles but does not run. Inlining is disabled.
// escape2n.go contains all the same tests but compiles with -N.
package foo package foo
import ( import (

1494
test/escape2n.go Normal file

File diff suppressed because it is too large Load Diff