commit 3c2610fd4650e8e7bb396d86141ada54e52e368d
parent 3f1b3e7a7b4735ce4b796b174986d52dccdc1fa7
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, 6 insertions(+), 6 deletions(-)
diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -120,7 +120,7 @@ complex(Node *np)
return np;
}
-static Node
+static Node *
load(Type *tp, Node *np)
{
int op;
@@ -128,7 +128,7 @@ load(Type *tp, Node *np)
int flags = tp->flags;
if (flags & (AGGRF|FUNF))
- return *np;
+ return np;
switch (tp->size) {
case 1:
@@ -156,7 +156,7 @@ load(Type *tp, Node *np)
new = tmpnode(NULL, tp);
code(op, new, np, NULL);
- return *new;
+ return new;
}
static Node *rhs(Node *np, Node *new);
@@ -333,7 +333,7 @@ field(Node *np, Node *ret, int islhs)
if (islhs)
*ret = *addr;
else
- *ret = load(&np->type, addr);
+ *ret = *load(&np->type, addr);
return ret;
}
@@ -504,7 +504,7 @@ rhs(Node *np, Node *ret)
case OMEM:
case OREG:
case OAUTO:
- *ret = load(tp, np);
+ *ret = *load(tp, np);
return ret;
case ONEG:
case OAND:
@@ -620,7 +620,7 @@ rhs(Node *np, Node *ret)
rhs(l, &aux1);
return rhs(r, ret);
case OPTR:
- *ret = load(tp, rhs(l, &aux1));
+ *ret = *load(tp, rhs(l, &aux1));
return ret;
case OADDR:
lhs(l, ret);