commit 30a8ff0298ffbe13275029e00cb31289b8211980
parent 8c4365e8eb495d27138d9c02babb3e2578f45c9e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 4 Nov 2021 09:24:54 +0100
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.
Diffstat:
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -237,26 +237,26 @@ cast(Type *td, Node *np)
}
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 @@ rhs(Node *np, Node *ret)
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;