ref: d82fe81032115596968f35e60beb85ac5ef69f9c
parent: 48669bd9d1a6bbec7837e05e81f6f283e5d0858a
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Nov 4 05:24:54 EDT 2021
cc2/qbe: Change call() 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 call() 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 called where it can write the results.
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -237,26 +237,26 @@
}
static Node *
-call(Node *np, Node *fun, Node *ret)
+call(Node *np, Node *fun)
{
int n, op;
Type *tp;
- Node aux, **q, *p, *pars[NR_FUNPARAM];
+ Node **q, *tmp, *p, *pars[NR_FUNPARAM];
for (n = 0, p = np->right; p; p = p->right)
pars[n++] = rhs(p->left, node(OTMP));
tp = &np->type;
- code(ASCALL, tmpnode(ret, tp), fun, NULL);
+ tmp = tmpnode(NULL, tp);
+ code(ASCALL, tmp, fun, NULL);
for (q = pars; q < &pars[n]; ++q) {
op = (q == &pars[n-1]) ? ASPARE : ASPAR;
- tmpnode(&aux, &(*q)->type);
- code(op, NULL, *q, &aux);
+ code(op, NULL, *q, tmpnode(NULL, &(*q)->type));
}
code((np->op == OCALL) ? ASCALLE : ASCALLEX, NULL, NULL, NULL);
- return ret;
+ return tmp;
}
static Node *
@@ -578,7 +578,8 @@
case OCALLE:
if (l->op == OPTR)
l = rhs(l, &aux1);
- return call(np, l, ret);
+ *ret = *call(np, l);
+ return ret;
case OCAST:
*ret = *cast(tp, rhs(l, &aux1));
return ret;