]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/5g, cmd/6g, cmd/8g: remove O(n) reset loop in copyprop
authorRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 19:22:11 +0000 (15:22 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 19:22:11 +0000 (15:22 -0400)
Simpler version of CL 13084043.

R=ken2
CC=golang-dev
https://golang.org/cl/13602045

src/cmd/5g/peep.c
src/cmd/6g/peep.c
src/cmd/8g/peep.c

index f96804d73ddc5543244f09509b7341304f45fb39..9e51fa1b8ab52935ec25347724614ef88eb83511 100644 (file)
@@ -47,6 +47,8 @@ static Flow*  findpre(Flow *r, Adr *v);
 static int     copyau1(Prog *p, Adr *v);
 static int     isdconst(Addr *a);
 
+static uint32  gactive;
+
 // UNUSED
 int    shiftprop(Flow *r);
 void   constprop(Adr *c1, Adr *v1, Flow *r);
@@ -63,6 +65,7 @@ peep(Prog *firstp)
        g = flowstart(firstp, sizeof(Flow));
        if(g == nil)
                return;
+       gactive = 0;
 
 loop1:
        if(debug['P'] && debug['v'])
@@ -360,15 +363,14 @@ copyprop(Graph *g, Flow *r0)
 {
        Prog *p;
        Adr *v1, *v2;
-       Flow *r;
 
+       USED(g);
        p = r0->prog;
        v1 = &p->from;
        v2 = &p->to;
        if(copyas(v1, v2))
                return 1;
-       for(r=g->start; r!=nil; r=r->link)
-               r->active = 0;
+       gactive++;
        return copy1(v1, v2, r0->s1, 0);
 }
 
@@ -378,12 +380,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
        int t;
        Prog *p;
 
-       if(r->active) {
+       if(r->active == gactive) {
                if(debug['P'])
                        print("act set; return 1\n");
                return 1;
        }
-       r->active = 1;
+       r->active = gactive;
        if(debug['P'])
                print("copy %D->%D f=%d\n", v1, v2, f);
        for(; r != nil; r = r->s1) {
index 9b935ded8bbd0351ee926ded1131da3a8222e56e..9ae5421bf98bfe5cb484a578ece47a279cbc10ce 100644 (file)
@@ -45,6 +45,8 @@ static int    copyas(Adr*, Adr*);
 static int     copyau(Adr*, Adr*);
 static int     copysub(Adr*, Adr*, Adr*, int);
 
+static uint32  gactive;
+
 // do we need the carry bit
 static int
 needc(Prog *p)
@@ -92,6 +94,7 @@ peep(Prog *firstp)
        g = flowstart(firstp, sizeof(Flow));
        if(g == nil)
                return;
+       gactive = 0;
 
        // byte, word arithmetic elimination.
        elimshortmov(g);
@@ -643,8 +646,8 @@ copyprop(Graph *g, Flow *r0)
 {
        Prog *p;
        Adr *v1, *v2;
-       Flow *r;
 
+       USED(g);
        if(debug['P'] && debug['v'])
                print("copyprop %P\n", r0->prog);
        p = r0->prog;
@@ -652,8 +655,7 @@ copyprop(Graph *g, Flow *r0)
        v2 = &p->to;
        if(copyas(v1, v2))
                return 1;
-       for(r=g->start; r!=nil; r=r->link)
-               r->active = 0;
+       gactive++;
        return copy1(v1, v2, r0->s1, 0);
 }
 
@@ -663,12 +665,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
        int t;
        Prog *p;
 
-       if(r->active) {
+       if(r->active == gactive) {
                if(debug['P'])
                        print("act set; return 1\n");
                return 1;
        }
-       r->active = 1;
+       r->active = gactive;
        if(debug['P'])
                print("copy %D->%D f=%d\n", v1, v2, f);
        for(; r != nil; r = r->s1) {
index 6e4d8176c11fc85f2d7e525cb857a996dae895da..f8e832e6d44b3a09ce307543c754ecac90f1e736 100644 (file)
@@ -44,6 +44,8 @@ static int    copyas(Adr*, Adr*);
 static int     copyau(Adr*, Adr*);
 static int     copysub(Adr*, Adr*, Adr*, int);
 
+static uint32  gactive;
+
 // do we need the carry bit
 static int
 needc(Prog *p)
@@ -91,6 +93,7 @@ peep(Prog *firstp)
        g = flowstart(firstp, sizeof(Flow));
        if(g == nil)
                return;
+       gactive = 0;
 
        // byte, word arithmetic elimination.
        elimshortmov(g);
@@ -441,15 +444,14 @@ copyprop(Graph *g, Flow *r0)
 {
        Prog *p;
        Adr *v1, *v2;
-       Flow *r;
 
+       USED(g);
        p = r0->prog;
        v1 = &p->from;
        v2 = &p->to;
        if(copyas(v1, v2))
                return 1;
-       for(r=g->start; r!=nil; r=r->link)
-               r->active = 0;
+       gactive++;
        return copy1(v1, v2, r0->s1, 0);
 }
 
@@ -459,12 +461,12 @@ copy1(Adr *v1, Adr *v2, Flow *r, int f)
        int t;
        Prog *p;
 
-       if(r->active) {
+       if(r->active == gactive) {
                if(debug['P'])
                        print("act set; return 1\n");
                return 1;
        }
-       r->active = 1;
+       r->active = gactive;
        if(debug['P'])
                print("copy %D->%D f=%d\n", v1, v2, f);
        for(; r != nil; r = r->s1) {