summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/asm.h3
-rw-r--r--6/isel.c46
-rw-r--r--6/ra.c2
3 files changed, 48 insertions, 3 deletions
diff --git a/6/asm.h b/6/asm.h
index 8decfbf..6eebb0a 100644
--- a/6/asm.h
+++ b/6/asm.h
@@ -4,7 +4,7 @@
#define Wordsz 4 /* the size of a "natural int" */
#define Ptrsz 8 /* the size of a machine word (ie, pointer size) */
#define K 14 /* the number of allocatable registers */
-#define Nsaved 14 /* number of registers saved in the ABI */
+#define Nsaved 13 /* number of registers saved in the ABI */
typedef size_t regid;
@@ -195,7 +195,6 @@ void locprint(FILE *fd, Loc *l, char spec);
void iprintf(FILE *fd, Insn *insn);
/* emitting instructions */
-void g(Isel *s, AsmOp op, ...);
Insn *mkinsn(AsmOp op, ...);
/* register allocation */
diff --git a/6/isel.c b/6/isel.c
index 4cc9444..aa97bc0 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -131,7 +131,18 @@ static Insn *mkinsnv(AsmOp op, va_list ap)
return i;
}
-static void g(Isel *s, AsmOp op, ...)
+Insn *mkinsn(AsmOp op, ...)
+{
+ va_list ap;
+ Insn *i;
+
+ va_start(ap, op);
+ i = mkinsnv(op, ap);
+ va_end(ap);
+ return i;
+}
+
+void g(Isel *s, AsmOp op, ...)
{
va_list ap;
Insn *i;
@@ -749,18 +760,44 @@ static void isel(Isel *s, Node *n)
}
}
+Reg savedregs[] = {
+ Rrcx,
+ Rrdx,
+ Rrbx,
+ Rrsi,
+ Rrdi,
+ Rr8,
+ Rr9,
+ Rr10,
+ Rr11,
+ Rr12,
+ Rr13,
+ Rr14,
+ Rr15
+};
+
static void prologue(Isel *s, size_t sz)
{
Loc *rsp;
Loc *rbp;
Loc *stksz;
+ //size_t i;
rsp = locphysreg(Rrsp);
rbp = locphysreg(Rrbp);
stksz = loclit(sz, ModeQ);
+ /* enter function */
g(s, Ipush, rbp, NULL);
g(s, Imov, rsp, rbp, NULL);
g(s, Isub, stksz, rsp, NULL);
+#if 0
+ /* save registers */
+ for (i = 0; i < sizeof(savedregs)/sizeof(savedregs[0]); i++) {
+ s->calleesave[i] = locreg(ModeQ);
+ g(s, Imov, locphysreg(savedregs[i]), s->calleesave[i], NULL);
+ }
+#endif
+
s->stksz = stksz; /* need to update if we spill */
}
@@ -768,6 +805,7 @@ static void epilogue(Isel *s)
{
Loc *rsp, *rbp;
Loc *ret;
+ //size_t i;
rsp = locphysreg(Rrsp);
rbp = locphysreg(Rrbp);
@@ -775,6 +813,12 @@ static void epilogue(Isel *s)
ret = loc(s, s->ret);
g(s, Imov, ret, coreg(Rax, ret->mode), NULL);
}
+#if 0
+ /* restore registers */
+ for (i = 0; i < Nsaved; i++)
+ g(s, Imov, s->calleesave[i], locphysreg(savedregs[i]), NULL);
+ /* leave function */
+#endif
g(s, Imov, rbp, rsp, NULL);
g(s, Ipop, rbp, NULL);
g(s, Iret, NULL);
diff --git a/6/ra.c b/6/ra.c
index d1f13a2..6373b7d 100644
--- a/6/ra.c
+++ b/6/ra.c
@@ -996,8 +996,10 @@ void regalloc(Isel *s)
s->prepainted = mkbs();
s->shouldspill = mkbs();
s->neverspill = mkbs();
+#if 0
for (i = 0; i < Nsaved; i++)
bsput(s->shouldspill, s->calleesave[i]->reg.id);
+#endif
for (i = 0; i < maxregid; i++)
if (locmap[i]->reg.colour)
bsput(s->prepainted, i);