commit 5ee2d3192c60c04589ef92ff3bb78e62d953b51b
parent b610edb2ef5a3c07cc8e3490434abffd6eccbfc1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 4 Nov 2021 09:24:54 +0100
cc2/qbe: Change load() 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 load() 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, 14 insertions(+), 11 deletions(-)
diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -120,16 +120,16 @@ complex(Node *np)
return np;
}
-static Node *
-load(Type *tp, Node *np, Node *new)
+static Node
+load(Type *tp, Node *np)
{
int op;
+ Node *new;
int flags = tp->flags;
- if (flags & (AGGRF|FUNF)) {
- *new = *np;
- return new;
- }
+ if (flags & (AGGRF|FUNF))
+ return *np;
+
switch (tp->size) {
case 1:
op = ASLDSB;
@@ -153,9 +153,10 @@ load(Type *tp, Node *np, Node *new)
if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
++op;
- code(op, tmpnode(new, tp), np, NULL);
+ new = tmpnode(NULL, tp);
+ code(op, new, np, NULL);
- return new;
+ return *new;
}
static Node *rhs(Node *np, Node *new);
@@ -332,7 +333,7 @@ field(Node *np, Node *ret, int islhs)
if (islhs)
*ret = *addr;
else
- load(&np->type, addr, ret);
+ *ret = load(&np->type, addr);
return ret;
}
@@ -503,7 +504,8 @@ rhs(Node *np, Node *ret)
case OMEM:
case OREG:
case OAUTO:
- return load(tp, np, ret);
+ *ret = load(tp, np);
+ return ret;
case ONEG:
case OAND:
case OOR:
@@ -618,7 +620,8 @@ rhs(Node *np, Node *ret)
rhs(l, &aux1);
return rhs(r, ret);
case OPTR:
- return load(tp, rhs(l, &aux1), ret);
+ *ret = load(tp, rhs(l, &aux1));
+ return ret;
case OADDR:
lhs(l, ret);
ret->type = *tp;