ref: 3fa39059929b951b229ccc4525c1981a7ca470fa
parent: 4fc379d92730953c06b49b50e4a06a389a1a032d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 4 05:24:54 EDT 2021
cc2/qbe: Change lhs() to return Node Receiving a pointer to the struct were we want to store the result needs a lot of temporary variables in the code. If we make that lhs() returns a struct instead of a pointer to struct we can remove a lot of these temporaries and simplify the code. The code generated is pretty similar because returning structs usually mean passing an additional pointer to the function lhsed where it can write the results.
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -338,19 +338,17 @@
}
static Node *
-lhs(Node *np, Node *new)
+lhs(Node *np)
{
switch (np->op) {
case OREG:
case OMEM:
case OAUTO:
- *new = *np;
- return new;
+ return np;
case OPTR:
- return rhs(np->left, new);
+ return rhs(np->left, node(OTMP));
case OFIELD:
- *new = *field(np, 1);
- return new;
+ return field(np, 1);
default:
abort();
}
@@ -595,7 +593,7 @@
aux1.right = r;
aux1.type = np->type;
rhs(&aux1, &aux2);
- lhs(l, &aux1);
+ aux1 = *lhs(l);
assign(tp, &aux1, &aux2);
break;
default:
@@ -606,11 +604,11 @@
r = rhs(&aux2, &aux1);
case 0:
if (l->complex >= r->complex) {
- lhs(l, &aux2);
+ aux2 = *lhs(l);
rhs(r, ret);
} else {
rhs(r, ret);
- lhs(l, &aux2);
+ aux2 = *lhs(l);
}
return assign(tp, &aux2, ret);
@@ -625,7 +623,7 @@
*ret = *load(tp, rhs(l, &aux1));
return ret;
case OADDR:
- lhs(l, ret);
+ *ret = *lhs(l);
ret->type = *tp;
return ret;
case OFIELD: