From 78d992ff3052db9dc98a3074e8a4423760c342f1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 15 Apr 2024 03:08:34 +0300 Subject: fix insert_before/after + Hopefully for good, quite a lot of messing about with those functions --- src/asm.c | 2 +- src/regalloc.c | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/asm.c b/src/asm.c index 60d8139..4674c99 100644 --- a/src/asm.c +++ b/src/asm.c @@ -296,7 +296,7 @@ static void output_alloc(struct insn i, FILE *o) assert(i.type == ALLOC); /** @todo alignment is ignored, is that our responsibility? */ fprintf(o, "addi sp, sp, -%lli\n", i.v); - fprintf(o, "mov %s, sp\n", rname(i.out)); + fprintf(o, "mv %s, sp\n", rname(i.out)); } static void output_dealloc(struct insn i, FILE *o) diff --git a/src/regalloc.c b/src/regalloc.c index 8c42eab..cd21f5e 100644 --- a/src/regalloc.c +++ b/src/regalloc.c @@ -401,15 +401,24 @@ static void insn_insert_before_call(struct blk *b, struct insn save, { assert((insn_at(b->insns, pos)).type == CALL); struct insn setup; - do { - if (pos < 0) + while (1) { + if (pos < 0) { + pos = 0; break; + } setup = insn_at(b->insns, pos); - pos--; - } while (has_insn_flag(setup, CALL_SETUP)); + if (has_insn_flag(setup, CALL_SETUP)) { + pos--; + continue; + } + + /* we want to insert after this instruction */ + pos++; + break; + }; - insn_insert(b, save, pos + 1); + insn_insert(b, save, pos); } static void insn_insert_after_call(struct blk *b, struct insn restore, @@ -419,13 +428,18 @@ static void insn_insert_after_call(struct blk *b, struct insn restore, size_t max = vec_len(&b->insns); struct insn setup; - do { + while (1) { if (pos == max) break; setup = insn_at(b->insns, pos); - pos++; - } while (has_insn_flag(setup, CALL_TEARDOWN)); + if (has_insn_flag(setup, CALL_TEARDOWN)) { + pos++; + continue; + } + + break; + } insn_insert(b, restore, pos); } -- cgit v1.3