shithub: scc

Download patch

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

cc2/qbe: Change field() 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 field() 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 fielded where it can write the results.

--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -316,7 +316,7 @@
 /* TODO: Do field() transformation in sethi */
 
 static Node *
-field(Node *np, Node *ret, int islhs)
+field(Node *np, int islhs)
 {
 	Node base, node, off, add, *addr;
 	TUINT offset = np->right->u.sym->u.off;
@@ -332,11 +332,9 @@
 	}
 
 	if (islhs)
-		*ret = *addr;
+		return addr;
 	else
-		*ret = *load(&np->type, addr);
-
-	return ret;
+		return load(&np->type, addr);
 }
 
 static Node *
@@ -351,7 +349,8 @@
 	case OPTR:
 		return rhs(np->left, new);
 	case OFIELD:
-		return field(np, new, 1);
+		*new = *field(np, 1);
+		return new;
 	default:
 		abort();
 	}
@@ -630,7 +629,8 @@
 		ret->type = *tp;
 		return ret;
 	case OFIELD:
-		return field(np, ret, 0);
+		*ret = *field(np, 0);
+		return ret;
 	case OBUILTIN:
 		switch (np->u.subop) {
 		case BVA_START: