commit 78c66786fbc61bd189601b144ebacf2c7fbb2760
parent c3c644ca25e8ae9be6aa62c7cf2dca86d254bead
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Thu, 13 Jan 2022 00:16:23 -0600
ir: rename `struct interval` to `struct temp`
This name is more appropriate
Diffstat:
M | ir.c | | | 22 | +++++++++++----------- |
M | ir.h | | | 6 | +++--- |
M | util.c | | | 4 | ++-- |
M | x64.c | | | 28 | ++++++++++++++-------------- |
4 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/ir.c b/ir.c
@@ -20,7 +20,7 @@ extern struct toplevel toplevel;
#define PUTINS(op, val) ins = (struct instr){(val), (op)} ; bumpinterval(out, &ins, val) ; array_add(out, ins) ;
#define STARTINS(op, val) PUTINS((op), (val)) ; curi++ ;
-#define NEWTMP tmpi++; interval.start = curi + 1; interval.end = curi + 1; array_add((&out->intervals), interval);
+#define NEWTMP tmpi++; interval.start = curi + 1; interval.end = curi + 1; array_add((&out->temps), interval);
#define PTRSIZE 8
@@ -29,7 +29,7 @@ extern struct target targ;
static uint64_t tmpi;
static uint64_t labeli;
static uint64_t curi;
-static struct interval interval;
+static struct temp interval;
static uint16_t regs; // used register bitfield
uint64_t out_index;
@@ -94,7 +94,7 @@ bumpinterval(struct iproc *out, struct instr *instr, size_t index) {
case IR_CALLARG:
case IR_IN:
case IR_EXTRA:
- out->intervals.data[index].end = curi;
+ out->temps.data[index].end = curi;
break;
default:
die("bumpinterval");
@@ -347,20 +347,20 @@ genblock(struct iproc *out, struct block *block)
static void
chooseregs(struct iproc *proc)
{
- bool active[proc->intervals.len];
- memset(active, 0, proc->intervals.len * sizeof(*active));
+ bool active[proc->temps.len];
+ memset(active, 0, proc->temps.len * sizeof(*active));
// FIXME: this is obviously not close to optimal
for (uint64_t i = 0; i <= curi; i++) {
- for (size_t j = 0; j < proc->intervals.len; j++) {
- if (active[j] && proc->intervals.data[j].end == i - 1) {
+ for (size_t j = 0; j < proc->temps.len; j++) {
+ if (active[j] && proc->temps.data[j].end == i - 1) {
active[j] = false;
- regfree(proc->intervals.data[j].reg);
+ regfree(proc->temps.data[j].reg);
}
- if (!active[j] && proc->intervals.data[j].start == i) {
+ if (!active[j] && proc->temps.data[j].start == i) {
active[j] = true;
- proc->intervals.data[j].reg = regalloc();
+ proc->temps.data[j].reg = regalloc();
}
}
}
@@ -384,7 +384,7 @@ genproc(struct decl *decl, struct proc *proc)
blockpush(&proc->block);
// put a blank interval, since tmpi starts at 1
- array_add((&iproc.intervals), interval);
+ array_add((&iproc.temps), interval);
size_t i = 0;
for (size_t j = 0; j < proc->in.len; j++, i++) {
diff --git a/ir.h b/ir.h
@@ -29,7 +29,7 @@ struct instr {
} op;
};
-struct interval {
+struct temp {
uint64_t start;
uint64_t end;
uint8_t reg;
@@ -44,8 +44,8 @@ struct iproc {
struct {
size_t len;
size_t cap;
- struct interval *data;
- } intervals;
+ struct temp *data;
+ } temps;
};
struct iprocs {
diff --git a/util.c b/util.c
@@ -197,8 +197,8 @@ dumpir(struct iproc *instrs)
putc('\n', stderr);
- for (size_t i = 0; i < instrs->intervals.len; i++) {
- fprintf(stderr, "%lu: %lu to %lu\n", i, instrs->intervals.data[i].start, instrs->intervals.data[i].end);
+ for (size_t i = 0; i < instrs->temps.len; i++) {
+ fprintf(stderr, "%lu: %lu to %lu\n", i, instrs->temps.data[i].start, instrs->temps.data[i].end);
}
}
diff --git a/x64.c b/x64.c
@@ -673,12 +673,12 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
while (ins < end) {
curi++;
- for (size_t j = 0; j < proc->intervals.len; j++) {
- if ((active & (1 << j)) && proc->intervals.data[j].end == curi - 1)
- active &= ~(1 << proc->intervals.data[j].reg);
+ for (size_t j = 0; j < proc->temps.len; j++) {
+ if ((active & (1 << j)) && proc->temps.data[j].end == curi - 1)
+ active &= ~(1 << proc->temps.data[j].reg);
- if (!(active & (1 << j)) && proc->intervals.data[j].start == curi)
- active |= 1 << proc->intervals.data[j].reg;
+ if (!(active & (1 << j)) && proc->temps.data[j].start == curi)
+ active |= 1 << proc->temps.data[j].reg;
}
switch (ins->op) {
// FIXME: we don't handle jumps backward yet
@@ -698,10 +698,10 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
switch (ins->op) {
case IR_STORE:
- src = proc->intervals.data[ins->val].reg;
+ src = proc->temps.data[ins->val].reg;
NEXT;
assert(ins->op == IR_EXTRA);
- total += mov_mr64_r64(text, proc->intervals.data[ins->val].reg, src);
+ total += mov_mr64_r64(text, proc->temps.data[ins->val].reg, src);
NEXT;
break;
default:
@@ -710,7 +710,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
break;
case IR_ASSIGN:
tmp = ins->val;
- dest = proc->intervals.data[ins->val].reg;
+ dest = proc->temps.data[ins->val].reg;
NEXT;
assert(ins->op == IR_SIZE);
@@ -719,9 +719,9 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
switch (ins->op) {
case IR_CEQ:
- total += mov_r64_r64(text, dest, proc->intervals.data[ins->val].reg);
+ total += mov_r64_r64(text, dest, proc->temps.data[ins->val].reg);
NEXT;
- total += cmp_r64_r64(text, dest, proc->intervals.data[ins->val].reg);
+ total += cmp_r64_r64(text, dest, proc->temps.data[ins->val].reg);
NEXT;
if (ins->op == IR_CONDJUMP) {
curi++;
@@ -735,9 +735,9 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
}
break;
case IR_ADD:
- total += mov_r64_r64(text, dest, proc->intervals.data[ins->val].reg);
+ total += mov_r64_r64(text, dest, proc->temps.data[ins->val].reg);
NEXT;
- total += add_r64_r64(text, dest, proc->intervals.data[ins->val].reg);
+ total += add_r64_r64(text, dest, proc->temps.data[ins->val].reg);
NEXT;
break;
case IR_IMM:
@@ -749,7 +749,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
NEXT;
break;
case IR_LOAD:
- total += mov_r64_mr64(text, dest, proc->intervals.data[ins->val].reg);
+ total += mov_r64_mr64(text, dest, proc->temps.data[ins->val].reg);
NEXT;
break;
case IR_ALLOC:
@@ -775,7 +775,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
NEXT;
while (ins->op == IR_CALLARG) {
count++;
- total += push_r64(text, proc->intervals.data[ins->val].reg);
+ total += push_r64(text, proc->temps.data[ins->val].reg);
NEXT;
}