ref: 2d59b15c39dc0412e2722141cb5d48bf72b5665e
parent: 99ddc5b0971c3ce0baddd667ea4c34c635c8e5ab
author: cinap_lenrek <[email protected]>
date: Tue Oct 6 02:20:01 EDT 2015
5c/6c/8c/vc: import various changes from charles forsyth - cover more cases that have no side effects - ensure function has complex FNX - pull operators out of OFUNC level - rewrite OSTRUCT lhs to avoid all side-effects, use regalloc() instead of regret()
--- a/sys/src/cmd/5c/cgen.c
+++ b/sys/src/cmd/5c/cgen.c
@@ -298,6 +298,7 @@
break;
case OFUNC:
+ l = uncomma(l);
if(l->complex >= FNX) {
if(l->op != OIND)
diag(n, "bad function call");
@@ -573,7 +574,7 @@
gopcode(o, &nod1, Z, &nod);
gmove(&nod, &nod2);
if(nn != Z)
- gmove(&nod, nn);
+ gmove(&nod2, nn);
regfree(&nod);
regfree(&nod1);
if(hardleft)
@@ -931,12 +932,12 @@
case OSTRUCT:
/*
- * rewrite so lhs has no fn call
+ * rewrite so lhs has no side effects
*/
- if(nn != Z && nn->complex >= FNX) {
+ if(nn != Z && side(nn)) {
nod1 = *n;
nod1.type = typ(TIND, n->type);
- regret(&nod2, &nod1);
+ regalloc(&nod2, &nod1, Z);
lcgen(nn, &nod2);
regsalloc(&nod0, &nod1);
gopcode(OAS, &nod2, Z, &nod0);
@@ -1026,6 +1027,7 @@
} else
nn = nn->left;
n = new(OFUNC, n->left, new(OLIST, nn, n->right));
+ n->complex = FNX;
n->type = types[TVOID];
n->left->type = types[TVOID];
cgen(n, Z);
--- a/sys/src/cmd/6c/cgen.c
+++ b/sys/src/cmd/6c/cgen.c
@@ -875,6 +875,7 @@
break;
case OFUNC:
+ l = uncomma(l);
if(l->complex >= FNX) {
if(l->op != OIND)
diag(n, "bad function call");
@@ -1536,6 +1537,7 @@
} else
nn = nn->left;
n = new(OFUNC, n->left, new(OLIST, nn, n->right));
+ n->complex = FNX;
n->type = types[TVOID];
n->left->type = types[TVOID];
cgen(n, Z);
--- a/sys/src/cmd/8c/cgen.c
+++ b/sys/src/cmd/8c/cgen.c
@@ -1606,6 +1606,7 @@
} else
nn = nn->left;
n = new(OFUNC, n->left, new(OLIST, nn, n->right));
+ n->complex = FNX;
n->type = types[TVOID];
n->left->type = types[TVOID];
cgen(n, Z);
--- a/sys/src/cmd/cc/sub.c
+++ b/sys/src/cmd/cc/sub.c
@@ -950,6 +950,8 @@
case OOROR:
case OCOMMA:
case ODOT:
+ case OFAS:
+ case OINDEX:
if(side(n->left))
break;
n = n->right;
@@ -961,6 +963,10 @@
case OSTRING:
case OLSTRING:
case ONAME:
+ case OREGPAIR:
+ case OEXREG:
+ case OREGISTER:
+ case OINDREG:
return 0;
}
return 1;
--- a/sys/src/cmd/vc/cgen.c
+++ b/sys/src/cmd/vc/cgen.c
@@ -260,6 +260,7 @@
break;
case OFUNC:
+ l = uncomma(l);
if(l->complex >= FNX) {
if(l->op != OIND)
diag(n, "bad function call");
@@ -530,7 +531,7 @@
gopcode(o, &nod1, Z, &nod);
gmove(&nod, &nod2);
if(nn != Z)
- gmove(&nod, nn);
+ gmove(&nod2, nn);
regfree(&nod);
regfree(&nod1);
if(hardleft)
@@ -946,12 +947,12 @@
case OSTRUCT:
/*
- * rewrite so lhs has no fn call
+ * rewrite so lhs has no side effects
*/
- if(nn != Z && nn->complex >= FNX) {
+ if(nn != Z && side(nn)) {
nod1 = *n;
nod1.type = typ(TIND, n->type);
- regret(&nod2, &nod1);
+ regalloc(&nod2, &nod1, Z);
lcgen(nn, &nod2);
regsalloc(&nod0, &nod1);
gopcode(OAS, &nod2, Z, &nod0);
@@ -1041,6 +1042,7 @@
} else
nn = nn->left;
n = new(OFUNC, n->left, new(OLIST, nn, n->right));
+ n->complex = FNX;
n->type = types[TVOID];
n->left->type = types[TVOID];
cgen(n, Z);