shithub: scc

Download patch

ref: 3c2610fd4650e8e7bb396d86141ada54e52e368d
parent: 3f1b3e7a7b4735ce4b796b174986d52dccdc1fa7
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 4 05:24:54 EDT 2021

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.

--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -120,7 +120,7 @@
 	return np;
 }
 
-static Node
+static Node *
 load(Type *tp, Node *np)
 {
 	int op;
@@ -128,7 +128,7 @@
 	int flags = tp->flags;
 
 	if (flags & (AGGRF|FUNF))
-		return *np;
+		return np;
 
 	switch (tp->size) {
 	case 1:
@@ -156,7 +156,7 @@
 	new = tmpnode(NULL, tp);
 	code(op, new, np, NULL);
 
-	return *new;
+	return new;
 }
 
 static Node *rhs(Node *np, Node *new);
@@ -333,7 +333,7 @@
 	if (islhs)
 		*ret = *addr;
 	else
-		*ret = load(&np->type, addr);
+		*ret = *load(&np->type, addr);
 
 	return ret;
 }
@@ -504,7 +504,7 @@
 	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(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);