]> Cypherpunks repositories - gostls13.git/commitdiff
avoid register computing len(x), cap(x)
authorRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 22:55:27 +0000 (15:55 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 22:55:27 +0000 (15:55 -0700)
for slice or string x.

R=ken
OCL=32249
CL=32249

src/cmd/5g/cgen.c
src/cmd/5g/gsubr.c
src/cmd/6g/cgen.c
src/cmd/6g/gsubr.c
src/cmd/8g/cgen.c
src/cmd/8g/gsubr.c

index 46fb048ff6ded1c30bfd3d586617b17e43a7c0ec..327bb1aebc4cd37963a1718372fdb32cef668258 100644 (file)
@@ -91,6 +91,20 @@ cgen(Node *n, Node *res)
                goto ret;
        }
 
+       // update addressability for string, slice
+       // can't do in walk because n->left->addable
+       // changes if n->left is an escaping local variable.
+       switch(n->op) {
+       case OLEN:
+               if(isslice(n->left->type) || istype(n->left->type, TSTRING))
+                       n->addable = n->left->addable;
+               break;
+       case OCAP:
+               if(isslice(n->left->type))
+                       n->addable = n->left->addable;
+               break;
+       }
+
        if(n->addable) {
                gmove(n, res);
                goto ret;
index 999592bf202db48687e895e0ef8efdddf5a682a4..5d94604466f6b41accb653804cd5f52f02fde94e 100644 (file)
@@ -628,23 +628,23 @@ gmove(Node *f, Node *t)
 //     case CASE(TINT32, TINT64):      // sign extend int32
 //     case CASE(TINT32, TUINT64):
 //             fatal("gmove TINT32,INT64 not implemented");
-////           split64(t, &tlo, &thi);
-////           nodreg(&flo, tlo.type, D_AX);
-////           nodreg(&fhi, thi.type, D_DX);
-////           gmove(f, &flo);
-////           gins(ACDQ, N, N);
-////           gins(AMOVL, &flo, &tlo);
-////           gins(AMOVL, &fhi, &thi);
-////           splitclean();
+////           split64(t, &tlo, &thi);
+////           nodreg(&flo, tlo.type, D_AX);
+////           nodreg(&fhi, thi.type, D_DX);
+////           gmove(f, &flo);
+////           gins(ACDQ, N, N);
+////           gins(AMOVL, &flo, &tlo);
+////           gins(AMOVL, &fhi, &thi);
+////           splitclean();
 //             return;
 
 //     case CASE(TUINT32, TINT64):     // zero extend uint32
 //     case CASE(TUINT32, TUINT64):
 //             fatal("gmove TUINT32,INT64 not implemented");
-////           split64(t, &tlo, &thi);
-////           gmove(f, &tlo);
-////           gins(AMOVL, ncon(0), &thi);
-////           splitclean();
+////           split64(t, &tlo, &thi);
+////           gmove(f, &tlo);
+////           gins(AMOVL, ncon(0), &thi);
+////           splitclean();
 //             return;
 
 //     /*
@@ -813,23 +813,23 @@ gmove(Node *f, Node *t)
 //     case CASE(TINT64, TFLOAT32):
 //     case CASE(TINT64, TFLOAT64):
 //             fatal("gmove TINT,TFLOAT not implemented");
-////           if(t->op != OREGISTER)
-////                   goto hard;
-////           if(f->op == OREGISTER) {
-////                   cvt = f->type;
-////                   goto hardmem;
-////           }
-////           switch(ft) {
-////           case TINT16:
-////                   a = AFMOVW;
-////                   break;
-////           case TINT32:
-////                   a = AFMOVL;
-////                   break;
-////           default:
-////                   a = AFMOVV;
-////                   break;
-////           }
+////           if(t->op != OREGISTER)
+////                   goto hard;
+////           if(f->op == OREGISTER) {
+////                   cvt = f->type;
+////                   goto hardmem;
+////           }
+////           switch(ft) {
+////           case TINT16:
+////                   a = AFMOVW;
+////                   break;
+////           case TINT32:
+////                   a = AFMOVL;
+////                   break;
+////           default:
+////                   a = AFMOVV;
+////                   break;
+////           }
 //             break;
 
 //     case CASE(TINT8, TFLOAT32):
@@ -1186,6 +1186,18 @@ naddr(Node *n, Addr *a)
                }
                break;
 
+       case OLEN:
+               // len of string or slice
+               naddr(n->left, a);
+               a->offset += Array_nel;
+               break;
+
+       case OCAP:
+               // cap of string or slice
+               naddr(n->left, a);
+               a->offset += Array_cap;
+               break;
+
        case OADDR:
                naddr(n->left, a);
                if(a->type == D_OREG) {
index b10ac8ef75ea87a1522149ab30ac7d52fa66c4ce..27ad4fdbe6aa6ccae8fe65b8ba4dae94e9a0d4b0 100644 (file)
@@ -102,6 +102,20 @@ cgen(Node *n, Node *res)
                goto ret;
        }
 
+       // update addressability for string, slice
+       // can't do in walk because n->left->addable
+       // changes if n->left is an escaping local variable.
+       switch(n->op) {
+       case OLEN:
+               if(isslice(n->left->type) || istype(n->left->type, TSTRING))
+                       n->addable = n->left->addable;
+               break;
+       case OCAP:
+               if(isslice(n->left->type))
+                       n->addable = n->left->addable;
+               break;
+       }
+
        if(n->addable) {
                gmove(n, res);
                goto ret;
index 0c5141d9b16ca625eba94bcad8145a9765cfd129..5ed0a8105917db7b5906a60bb764c831c31e0794 100644 (file)
@@ -417,6 +417,8 @@ int
 ismem(Node *n)
 {
        switch(n->op) {
+       case OLEN:
+       case OCAP:
        case OINDREG:
        case ONAME:
        case OPARAM:
@@ -1012,6 +1014,18 @@ naddr(Node *n, Addr *a)
                        }
                fatal("naddr: OADDR\n");
 
+       case OLEN:
+               // len of string or slice
+               naddr(n->left, a);
+               a->offset += Array_nel;
+               break;
+
+       case OCAP:
+               // cap of string or slice
+               naddr(n->left, a);
+               a->offset += Array_cap;
+               break;
+
 //     case OADD:
 //             if(n->right->op == OLITERAL) {
 //                     v = n->right->vconst;
index 474d0713f445621bdce904648563ccb96051a4e7..e37eb52952c4a52ea1396204850f501a7930aa10 100644 (file)
@@ -83,6 +83,20 @@ cgen(Node *n, Node *res)
                return;
        }
 
+       // update addressability for string, slice
+       // can't do in walk because n->left->addable
+       // changes if n->left is an escaping local variable.
+       switch(n->op) {
+       case OLEN:
+               if(isslice(n->left->type) || istype(n->left->type, TSTRING))
+                       n->addable = n->left->addable;
+               break;
+       case OCAP:
+               if(isslice(n->left->type))
+                       n->addable = n->left->addable;
+               break;
+       }
+
        // if both are addressable, move
        if(n->addable && res->addable) {
                gmove(n, res);
index f5fbc17febe5fc9bfebf06c4183dae11479080d1..77a4532f03088530c112bed1a67b06be1de49aca 100755 (executable)
@@ -959,6 +959,8 @@ int
 ismem(Node *n)
 {
        switch(n->op) {
+       case OLEN:
+       case OCAP:
        case OINDREG:
        case ONAME:
        case OPARAM:
@@ -1762,6 +1764,18 @@ naddr(Node *n, Addr *a)
                        }
                fatal("naddr: OADDR\n");
 
+       case OLEN:
+               // len of string or slice
+               naddr(n->left, a);
+               a->offset += Array_nel;
+               break;
+
+       case OCAP:
+               // cap of string or slice
+               naddr(n->left, a);
+               a->offset += Array_cap;
+               break;
+
 //     case OADD:
 //             if(n->right->op == OLITERAL) {
 //                     v = n->right->vconst;