shithub: riscv

Download patch

ref: ea1d75e67581f9a65abddbe2f03af70ea8eb1e1a
parent: 1e9bb75854a336de2a63f9a4fb4d67dd75d682f1
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 18 15:28:08 EDT 2023

6c: eliminate the rathole

Currently, kencc generates temporaries into a global
rathole, rather than putting them onto the stack; this
means that any code with a 'non-interruptible
temporary' not thread or note safe.

This change fixes it.

--- a/sys/src/cmd/6c/cgen.c
+++ b/sys/src/cmd/6c/cgen.c
@@ -1016,17 +1016,14 @@
 		break;
 
 	case ODOT:
-		sugen(l, nodrat, l->type->width);
+		regsalloc(&nod, l);
+		sugen(l, &nod, l->type->width);
 		if(nn == Z)
 			break;
-		warn(n, "non-interruptable temporary");
-		nod = *nodrat;
 		if(!r || r->op != OCONST) {
 			diag(n, "DOT and no offset");
 			break;
 		}
-		nod.xoffset += (long)r->vconst;
-		nod.type = n->type;
 		cgen(&nod, nn);
 		break;
 
@@ -1409,9 +1406,6 @@
 		prtree(nn, "sugen lhs");
 		prtree(n, "sugen");
 	}
-	if(nn == nodrat)
-		if(w > nrathole)
-			nrathole = w;
 	switch(n->op) {
 	case OIND:
 		if(nn == Z) {
@@ -1427,18 +1421,15 @@
 
 	case ODOT:
 		l = n->left;
-		sugen(l, nodrat, l->type->width);
+		regsalloc(&nod1, l);
+		sugen(l, &nod1, l->type->width);
 		if(nn == Z)
 			break;
-		warn(n, "non-interruptable temporary");
-		nod1 = *nodrat;
 		r = n->right;
 		if(!r || r->op != OCONST) {
 			diag(n, "DOT and no offset");
 			break;
 		}
-		nod1.xoffset += (long)r->vconst;
-		nod1.type = n->type;
 		sugen(&nod1, nn, w);
 		break;
 
@@ -1524,15 +1515,17 @@
 			break;
 		}
 
-		sugen(n->right, nodrat, w);
+		regsalloc(&nod0, n->right);
+		sugen(n->right, &nod0, w);
 		warn(n, "non-interruptable temporary");
-		sugen(nodrat, n->left, w);
-		sugen(nodrat, nn, w);
+		sugen(&nod0, n->left, w);
+		sugen(&nod0, nn, w);
 		break;
 
 	case OFUNC:
 		if(nn == Z) {
-			sugen(n, nodrat, w);
+			regsalloc(&nod0, n);
+			sugen(n, &nod0, w);
 			break;
 		}
 		if(nn->op != OIND) {
--- a/sys/src/cmd/6c/gc.h
+++ b/sys/src/cmd/6c/gc.h
@@ -144,10 +144,8 @@
 EXTERN	Prog*	lastp;
 EXTERN	long	maxargsafe;
 EXTERN	int	mnstring;
-EXTERN	Node*	nodrat;
 EXTERN	Node*	nodret;
 EXTERN	Node*	nodsafe;
-EXTERN	long	nrathole;
 EXTERN	long	nstring;
 EXTERN	Prog*	p;
 EXTERN	long	pc;
@@ -154,7 +152,6 @@
 EXTERN	Node	lregnode;
 EXTERN	Node	qregnode;
 EXTERN	char	string[NSNAME];
-EXTERN	Sym*	symrathole;
 EXTERN	Node	znode;
 EXTERN	Prog	zprog;
 EXTERN	int	reg[D_NONE];
--- a/sys/src/cmd/6c/swt.c
+++ b/sys/src/cmd/6c/swt.c
@@ -350,7 +350,7 @@
 	char *n;
 	ulong sig;
 
-	if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
+	if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE){
 		sig = sign(s);
 		Bputc(b, ASIGNAME);
 		Bputc(b, ASIGNAME>>8);
--- a/sys/src/cmd/6c/txt.c
+++ b/sys/src/cmd/6c/txt.c
@@ -6,7 +6,6 @@
 ginit(void)
 {
 	int i;
-	Type *t;
 
 	thechar = '6';
 	thestring = "amd64";
@@ -15,7 +14,6 @@
 	listinit();
 	nstring = 0;
 	mnstring = 0;
-	nrathole = 0;
 	pc = 0;
 	breakpc = -1;
 	continpc = -1;
@@ -72,19 +70,6 @@
 	nodsafe->class = CAUTO;
 	complex(nodsafe);
 
-	t = typ(TARRAY, types[TCHAR]);
-	symrathole = slookup(".rathole");
-	symrathole->class = CGLOBL;
-	symrathole->type = t;
-
-	nodrat = new(ONAME, Z, Z);
-	nodrat->sym = symrathole;
-	nodrat->type = types[TIND];
-	nodrat->etype = TVOID;
-	nodrat->class = CGLOBL;
-	complex(nodrat);
-	nodrat->type = t;
-
 	nodret = new(ONAME, Z, Z);
 	nodret->sym = slookup(".ret");
 	nodret->type = types[TIND];
@@ -126,7 +111,6 @@
 	while(mnstring)
 		outstring("", 1L);
 	symstring->type->width = nstring;
-	symrathole->type->width = nrathole;
 	for(i=0; i<NHASH; i++)
 	for(s = hash[i]; s != S; s = s->link) {
 		if(s->type == T)