Commit 6d47de2f authored by Russ Cox's avatar Russ Cox

cmd/5g, cmd/6g, cmd/8g: remove O(n) reset loop in copyprop

Simpler version of CL 13084043.

R=ken2
CC=golang-dev
https://golang.org/cl/13602045
parent a0bc379d
...@@ -47,6 +47,8 @@ static Flow* findpre(Flow *r, Adr *v); ...@@ -47,6 +47,8 @@ static Flow* findpre(Flow *r, Adr *v);
static int copyau1(Prog *p, Adr *v); static int copyau1(Prog *p, Adr *v);
static int isdconst(Addr *a); static int isdconst(Addr *a);
static uint32 gactive;
// UNUSED // UNUSED
int shiftprop(Flow *r); int shiftprop(Flow *r);
void constprop(Adr *c1, Adr *v1, Flow *r); void constprop(Adr *c1, Adr *v1, Flow *r);
...@@ -63,6 +65,7 @@ peep(Prog *firstp) ...@@ -63,6 +65,7 @@ peep(Prog *firstp)
g = flowstart(firstp, sizeof(Flow)); g = flowstart(firstp, sizeof(Flow));
if(g == nil) if(g == nil)
return; return;
gactive = 0;
loop1: loop1:
if(debug['P'] && debug['v']) if(debug['P'] && debug['v'])
...@@ -360,15 +363,14 @@ copyprop(Graph *g, Flow *r0) ...@@ -360,15 +363,14 @@ copyprop(Graph *g, Flow *r0)
{ {
Prog *p; Prog *p;
Adr *v1, *v2; Adr *v1, *v2;
Flow *r;
USED(g);
p = r0->prog; p = r0->prog;
v1 = &p->from; v1 = &p->from;
v2 = &p->to; v2 = &p->to;
if(copyas(v1, v2)) if(copyas(v1, v2))
return 1; return 1;
for(r=g->start; r!=nil; r=r->link) gactive++;
r->active = 0;
return copy1(v1, v2, r0->s1, 0); return copy1(v1, v2, r0->s1, 0);
} }
...@@ -378,12 +380,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f) ...@@ -378,12 +380,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
int t; int t;
Prog *p; Prog *p;
if(r->active) { if(r->active == gactive) {
if(debug['P']) if(debug['P'])
print("act set; return 1\n"); print("act set; return 1\n");
return 1; return 1;
} }
r->active = 1; r->active = gactive;
if(debug['P']) if(debug['P'])
print("copy %D->%D f=%d\n", v1, v2, f); print("copy %D->%D f=%d\n", v1, v2, f);
for(; r != nil; r = r->s1) { for(; r != nil; r = r->s1) {
......
...@@ -45,6 +45,8 @@ static int copyas(Adr*, Adr*); ...@@ -45,6 +45,8 @@ static int copyas(Adr*, Adr*);
static int copyau(Adr*, Adr*); static int copyau(Adr*, Adr*);
static int copysub(Adr*, Adr*, Adr*, int); static int copysub(Adr*, Adr*, Adr*, int);
static uint32 gactive;
// do we need the carry bit // do we need the carry bit
static int static int
needc(Prog *p) needc(Prog *p)
...@@ -92,6 +94,7 @@ peep(Prog *firstp) ...@@ -92,6 +94,7 @@ peep(Prog *firstp)
g = flowstart(firstp, sizeof(Flow)); g = flowstart(firstp, sizeof(Flow));
if(g == nil) if(g == nil)
return; return;
gactive = 0;
// byte, word arithmetic elimination. // byte, word arithmetic elimination.
elimshortmov(g); elimshortmov(g);
...@@ -643,8 +646,8 @@ copyprop(Graph *g, Flow *r0) ...@@ -643,8 +646,8 @@ copyprop(Graph *g, Flow *r0)
{ {
Prog *p; Prog *p;
Adr *v1, *v2; Adr *v1, *v2;
Flow *r;
USED(g);
if(debug['P'] && debug['v']) if(debug['P'] && debug['v'])
print("copyprop %P\n", r0->prog); print("copyprop %P\n", r0->prog);
p = r0->prog; p = r0->prog;
...@@ -652,8 +655,7 @@ copyprop(Graph *g, Flow *r0) ...@@ -652,8 +655,7 @@ copyprop(Graph *g, Flow *r0)
v2 = &p->to; v2 = &p->to;
if(copyas(v1, v2)) if(copyas(v1, v2))
return 1; return 1;
for(r=g->start; r!=nil; r=r->link) gactive++;
r->active = 0;
return copy1(v1, v2, r0->s1, 0); return copy1(v1, v2, r0->s1, 0);
} }
...@@ -663,12 +665,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f) ...@@ -663,12 +665,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
int t; int t;
Prog *p; Prog *p;
if(r->active) { if(r->active == gactive) {
if(debug['P']) if(debug['P'])
print("act set; return 1\n"); print("act set; return 1\n");
return 1; return 1;
} }
r->active = 1; r->active = gactive;
if(debug['P']) if(debug['P'])
print("copy %D->%D f=%d\n", v1, v2, f); print("copy %D->%D f=%d\n", v1, v2, f);
for(; r != nil; r = r->s1) { for(; r != nil; r = r->s1) {
......
...@@ -44,6 +44,8 @@ static int copyas(Adr*, Adr*); ...@@ -44,6 +44,8 @@ static int copyas(Adr*, Adr*);
static int copyau(Adr*, Adr*); static int copyau(Adr*, Adr*);
static int copysub(Adr*, Adr*, Adr*, int); static int copysub(Adr*, Adr*, Adr*, int);
static uint32 gactive;
// do we need the carry bit // do we need the carry bit
static int static int
needc(Prog *p) needc(Prog *p)
...@@ -91,6 +93,7 @@ peep(Prog *firstp) ...@@ -91,6 +93,7 @@ peep(Prog *firstp)
g = flowstart(firstp, sizeof(Flow)); g = flowstart(firstp, sizeof(Flow));
if(g == nil) if(g == nil)
return; return;
gactive = 0;
// byte, word arithmetic elimination. // byte, word arithmetic elimination.
elimshortmov(g); elimshortmov(g);
...@@ -441,15 +444,14 @@ copyprop(Graph *g, Flow *r0) ...@@ -441,15 +444,14 @@ copyprop(Graph *g, Flow *r0)
{ {
Prog *p; Prog *p;
Adr *v1, *v2; Adr *v1, *v2;
Flow *r;
USED(g);
p = r0->prog; p = r0->prog;
v1 = &p->from; v1 = &p->from;
v2 = &p->to; v2 = &p->to;
if(copyas(v1, v2)) if(copyas(v1, v2))
return 1; return 1;
for(r=g->start; r!=nil; r=r->link) gactive++;
r->active = 0;
return copy1(v1, v2, r0->s1, 0); return copy1(v1, v2, r0->s1, 0);
} }
...@@ -459,12 +461,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f) ...@@ -459,12 +461,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
int t; int t;
Prog *p; Prog *p;
if(r->active) { if(r->active == gactive) {
if(debug['P']) if(debug['P'])
print("act set; return 1\n"); print("act set; return 1\n");
return 1; return 1;
} }
r->active = 1; r->active = gactive;
if(debug['P']) if(debug['P'])
print("copy %D->%D f=%d\n", v1, v2, f); print("copy %D->%D f=%d\n", v1, v2, f);
for(; r != nil; r = r->s1) { for(; r != nil; r = r->s1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment