summary refs log tree commit diff
path: root/isel.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-12-29 17:51:26 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-12-29 17:51:26 -0500
commit7815610cd8af498beac01d3ae6a1c9b20f1f0a8d (patch)
treecf002cb7585e8f99faa0dbf3bb3a872df3e48d00 /isel.c
parentea4b47003b1b2bb0ec204e90e3a3f1b0bb0a6090 (diff)
downloadroux-7815610cd8af498beac01d3ae6a1c9b20f1f0a8d.tar.gz
simplify seladdr()
This also provides a violent fix to a bug causing an invalid
addressing to be generated when indexing into a global variable.
The fix is not satisfactory, though, as bad code is generated
(instead of invalid code before).
Diffstat (limited to 'isel.c')
-rw-r--r--isel.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/isel.c b/isel.c
index 399ed5e..9a60554 100644
--- a/isel.c
+++ b/isel.c
@@ -24,7 +24,6 @@ typedef struct ANum ANum;
 struct ANum {
 	char n, l, r;
 	Ins *i;
-	Ref mem;
 };
 
 static void amatch(Addr *, Ref, ANum *, Fn *, int);
@@ -158,24 +157,19 @@ static void
 seladdr(Ref *r, ANum *an, Fn *fn)
 {
 	Addr a;
-	Ref r0, r1;
+	Ref r0;
 
 	r0 = *r;
 	if (rtype(r0) == RTmp) {
+		amatch(&a, r0, an, fn, 1);
+		if (req(a.base, R))
+			return;
 		chuse(r0, -1, fn);
-		r1 = an[r0.val].mem;
-		if (req(r1, R)) {
-			amatch(&a, r0, an, fn, 1);
-			vgrow(&fn->mem, ++fn->nmem);
-			fn->mem[fn->nmem-1] = a;
-			r1 = MEM(fn->nmem-1);
-			chuse(a.base, +1, fn);
-			chuse(a.index, +1, fn);
-			if (rtype(a.base) != RTmp)
-			if (rtype(a.index) != RTmp)
-				an[r0.val].mem = r1;
-		}
-		*r = r1;
+		vgrow(&fn->mem, ++fn->nmem);
+		fn->mem[fn->nmem-1] = a;
+		chuse(a.base, +1, fn);
+		chuse(a.index, +1, fn);
+		*r = MEM(fn->nmem-1);
 	}
 }
 
@@ -629,5 +623,9 @@ isel(Fn *fn)
 	if (debug['I']) {
 		fprintf(stderr, "\n> After instruction selection:\n");
 		printfn(fn, stderr);
+		for (n=0; n<fn->ntmp; ++n) {
+			if (strcmp(fn->tmp[n].name, "i") == 0)
+				fprintf(stderr, ">> nuse for i: %d\n", fn->tmp[n].nuse);
+		}
 	}
 }