mirror of
https://github.com/golang/go
synced 2024-11-24 05:00:18 -07:00
cmd/gc: do not compute dead value maps if they will not be used
Reduces 6g big.go memory usage from 251 MB to 242 MB. Reduces 6g slow.go memory usage from 529 MB to 453 MB. Mostly a memory savings; 6g slow.go is only about 5% faster. The test programs are at https://rsc.googlecode.com/hg/testdata/big.go (36k lines, 276kB) https://rsc.googlecode.com/hg/testdata/slow.go (7k lines, 352kB) R=golang-codereviews, bradfitz, iant CC=golang-codereviews https://golang.org/cl/42280045
This commit is contained in:
parent
57e27a879e
commit
145edc283f
@ -690,7 +690,7 @@ progeffects(Prog *prog, Array *vars, Bvec *uevar, Bvec *varkill)
|
||||
// liveness computation. The cfg argument is an array of BasicBlock*s and the
|
||||
// vars argument is an array of Node*s.
|
||||
static Liveness*
|
||||
newliveness(Node *fn, Prog *ptxt, Array *cfg, Array *vars)
|
||||
newliveness(Node *fn, Prog *ptxt, Array *cfg, Array *vars, int computedead)
|
||||
{
|
||||
Liveness *result;
|
||||
int32 i;
|
||||
@ -719,8 +719,13 @@ newliveness(Node *fn, Prog *ptxt, Array *cfg, Array *vars)
|
||||
|
||||
result->livepointers = arraynew(0, sizeof(Bvec*));
|
||||
result->argslivepointers = arraynew(0, sizeof(Bvec*));
|
||||
if(computedead) {
|
||||
result->deadvalues = arraynew(0, sizeof(Bvec*));
|
||||
result->argsdeadvalues = arraynew(0, sizeof(Bvec*));
|
||||
} else {
|
||||
result->deadvalues = nil;
|
||||
result->argsdeadvalues = nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -741,6 +746,7 @@ freeliveness(Liveness *lv)
|
||||
free(*(Bvec**)arrayget(lv->argslivepointers, i));
|
||||
arrayfree(lv->argslivepointers);
|
||||
|
||||
if(lv->deadvalues != nil) {
|
||||
for(i = 0; i < arraylength(lv->deadvalues); i++)
|
||||
free(*(Bvec**)arrayget(lv->deadvalues, i));
|
||||
arrayfree(lv->deadvalues);
|
||||
@ -748,6 +754,7 @@ freeliveness(Liveness *lv)
|
||||
for(i = 0; i < arraylength(lv->argsdeadvalues); i++)
|
||||
free(*(Bvec**)arrayget(lv->argsdeadvalues, i));
|
||||
arrayfree(lv->argsdeadvalues);
|
||||
}
|
||||
|
||||
for(i = 0; i < arraylength(lv->cfg); i++) {
|
||||
free(lv->uevar[i]);
|
||||
@ -1333,11 +1340,13 @@ livenessepilogue(Liveness *lv)
|
||||
arrayadd(lv->livepointers, &locals);
|
||||
|
||||
// Dead stuff second.
|
||||
if(lv->deadvalues != nil) {
|
||||
args = bvalloc(argswords() * BitsPerPointer);
|
||||
arrayadd(lv->argsdeadvalues, &args);
|
||||
locals = bvalloc(localswords() * BitsPerPointer);
|
||||
arrayadd(lv->deadvalues, &locals);
|
||||
}
|
||||
}
|
||||
|
||||
// walk backward, emit pcdata and populate the maps
|
||||
pos = arraylength(lv->livepointers) - 1;
|
||||
@ -1391,9 +1400,11 @@ livenessepilogue(Liveness *lv)
|
||||
twobitlivepointermap(lv, liveout, lv->vars, args, locals);
|
||||
|
||||
// Record dead values.
|
||||
if(lv->deadvalues != nil) {
|
||||
args = *(Bvec**)arrayget(lv->argsdeadvalues, pos);
|
||||
locals = *(Bvec**)arrayget(lv->deadvalues, pos);
|
||||
twobitdeadvaluemap(lv, liveout, lv->vars, args, locals);
|
||||
}
|
||||
|
||||
pos--;
|
||||
}
|
||||
@ -1487,7 +1498,7 @@ liveness(Node *fn, Prog *firstp, Sym *argssym, Sym *livesym, Sym *deadsym)
|
||||
cfg = newcfg(firstp);
|
||||
if(0) printcfg(cfg);
|
||||
vars = getvariables(fn);
|
||||
lv = newliveness(fn, firstp, cfg, vars);
|
||||
lv = newliveness(fn, firstp, cfg, vars, deadsym != nil);
|
||||
|
||||
// Run the dataflow framework.
|
||||
livenessprologue(lv);
|
||||
|
Loading…
Reference in New Issue
Block a user