Commit 30228a3b authored by Russ Cox's avatar Russ Cox

avoid register computing len(x), cap(x)

for slice or string x.

R=ken
OCL=32249
CL=32249
parent 33c10450
...@@ -91,6 +91,20 @@ cgen(Node *n, Node *res) ...@@ -91,6 +91,20 @@ cgen(Node *n, Node *res)
goto ret; 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) { if(n->addable) {
gmove(n, res); gmove(n, res);
goto ret; goto ret;
......
...@@ -628,23 +628,23 @@ gmove(Node *f, Node *t) ...@@ -628,23 +628,23 @@ gmove(Node *f, Node *t)
// case CASE(TINT32, TINT64): // sign extend int32 // case CASE(TINT32, TINT64): // sign extend int32
// case CASE(TINT32, TUINT64): // case CASE(TINT32, TUINT64):
// fatal("gmove TINT32,INT64 not implemented"); // fatal("gmove TINT32,INT64 not implemented");
//// split64(t, &tlo, &thi); //// split64(t, &tlo, &thi);
//// nodreg(&flo, tlo.type, D_AX); //// nodreg(&flo, tlo.type, D_AX);
//// nodreg(&fhi, thi.type, D_DX); //// nodreg(&fhi, thi.type, D_DX);
//// gmove(f, &flo); //// gmove(f, &flo);
//// gins(ACDQ, N, N); //// gins(ACDQ, N, N);
//// gins(AMOVL, &flo, &tlo); //// gins(AMOVL, &flo, &tlo);
//// gins(AMOVL, &fhi, &thi); //// gins(AMOVL, &fhi, &thi);
//// splitclean(); //// splitclean();
// return; // return;
// case CASE(TUINT32, TINT64): // zero extend uint32 // case CASE(TUINT32, TINT64): // zero extend uint32
// case CASE(TUINT32, TUINT64): // case CASE(TUINT32, TUINT64):
// fatal("gmove TUINT32,INT64 not implemented"); // fatal("gmove TUINT32,INT64 not implemented");
//// split64(t, &tlo, &thi); //// split64(t, &tlo, &thi);
//// gmove(f, &tlo); //// gmove(f, &tlo);
//// gins(AMOVL, ncon(0), &thi); //// gins(AMOVL, ncon(0), &thi);
//// splitclean(); //// splitclean();
// return; // return;
// /* // /*
...@@ -813,23 +813,23 @@ gmove(Node *f, Node *t) ...@@ -813,23 +813,23 @@ gmove(Node *f, Node *t)
// case CASE(TINT64, TFLOAT32): // case CASE(TINT64, TFLOAT32):
// case CASE(TINT64, TFLOAT64): // case CASE(TINT64, TFLOAT64):
// fatal("gmove TINT,TFLOAT not implemented"); // fatal("gmove TINT,TFLOAT not implemented");
//// if(t->op != OREGISTER) //// if(t->op != OREGISTER)
//// goto hard; //// goto hard;
//// if(f->op == OREGISTER) { //// if(f->op == OREGISTER) {
//// cvt = f->type; //// cvt = f->type;
//// goto hardmem; //// goto hardmem;
//// } //// }
//// switch(ft) { //// switch(ft) {
//// case TINT16: //// case TINT16:
//// a = AFMOVW; //// a = AFMOVW;
//// break; //// break;
//// case TINT32: //// case TINT32:
//// a = AFMOVL; //// a = AFMOVL;
//// break; //// break;
//// default: //// default:
//// a = AFMOVV; //// a = AFMOVV;
//// break; //// break;
//// } //// }
// break; // break;
// case CASE(TINT8, TFLOAT32): // case CASE(TINT8, TFLOAT32):
...@@ -1186,6 +1186,18 @@ naddr(Node *n, Addr *a) ...@@ -1186,6 +1186,18 @@ naddr(Node *n, Addr *a)
} }
break; 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: case OADDR:
naddr(n->left, a); naddr(n->left, a);
if(a->type == D_OREG) { if(a->type == D_OREG) {
......
...@@ -102,6 +102,20 @@ cgen(Node *n, Node *res) ...@@ -102,6 +102,20 @@ cgen(Node *n, Node *res)
goto ret; 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) { if(n->addable) {
gmove(n, res); gmove(n, res);
goto ret; goto ret;
......
...@@ -417,6 +417,8 @@ int ...@@ -417,6 +417,8 @@ int
ismem(Node *n) ismem(Node *n)
{ {
switch(n->op) { switch(n->op) {
case OLEN:
case OCAP:
case OINDREG: case OINDREG:
case ONAME: case ONAME:
case OPARAM: case OPARAM:
...@@ -1012,6 +1014,18 @@ naddr(Node *n, Addr *a) ...@@ -1012,6 +1014,18 @@ naddr(Node *n, Addr *a)
} }
fatal("naddr: OADDR\n"); 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: // case OADD:
// if(n->right->op == OLITERAL) { // if(n->right->op == OLITERAL) {
// v = n->right->vconst; // v = n->right->vconst;
......
...@@ -83,6 +83,20 @@ cgen(Node *n, Node *res) ...@@ -83,6 +83,20 @@ cgen(Node *n, Node *res)
return; 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 both are addressable, move
if(n->addable && res->addable) { if(n->addable && res->addable) {
gmove(n, res); gmove(n, res);
......
...@@ -959,6 +959,8 @@ int ...@@ -959,6 +959,8 @@ int
ismem(Node *n) ismem(Node *n)
{ {
switch(n->op) { switch(n->op) {
case OLEN:
case OCAP:
case OINDREG: case OINDREG:
case ONAME: case ONAME:
case OPARAM: case OPARAM:
...@@ -1762,6 +1764,18 @@ naddr(Node *n, Addr *a) ...@@ -1762,6 +1764,18 @@ naddr(Node *n, Addr *a)
} }
fatal("naddr: OADDR\n"); 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: // case OADD:
// if(n->right->op == OLITERAL) { // if(n->right->op == OLITERAL) {
// v = n->right->vconst; // v = n->right->vconst;
......
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