aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ir_inliner.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-23 19:20:32 +0100
committerlemon <lsof@mailbox.org>2026-03-23 19:20:32 +0100
commit8630aeb8b43c507cd00f5b091ddcee4def464f4d (patch)
tree1e39866c9f95e2f30903b96c7f255dd03a463d82 /src/ir_inliner.c
parent9ffc0e5a21817a45956bc35d5996bfae09c4d49e (diff)
IR: mark free'd instructions as such
That way they are not copied when inlining. Also rename ninstr -> ninstrtab. opnarg -> opnoper
Diffstat (limited to 'src/ir_inliner.c')
-rw-r--r--src/ir_inliner.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/ir_inliner.c b/src/ir_inliner.c
index db89479..c1c36e2 100644
--- a/src/ir_inliner.c
+++ b/src/ir_inliner.c
@@ -1,7 +1,7 @@
#include "ir.h"
typedef struct SavedFunc {
- uint ninstr;
+ uint ninstrtab;
Instr *instrtab;
IRCon *contab;
IRCall *calltab;
@@ -22,12 +22,12 @@ bool
maybeinlinee(Function *fn)
{
static Arena *savearena;
- extern int ninstr;
+ extern int ninstrtab, nfreeinstr;
// TODO better heuristics
if (ccopt.o < OPT1) return 0;
if (!fn->inlin && ccopt.o < OPT2) return 0;
- if (ninstr > MAX_INLINED_FN_NINS) return 0;
+ if (ninstrtab - nfreeinstr > MAX_INLINED_FN_NINS) return 0;
if (fn->nblk > MAX_INLINED_FN_NBLK) return 0;
for (int i = 0; i < fn->nabiarg; ++i) {
/* TODO inlining functions with stack args */
@@ -80,7 +80,7 @@ maybeinlinee(Function *fn)
b->lnext = b->lnext == fn->entry ? NULL : bmap[b->lnext->id];
} while ((b = b->lnext));
- sv->instrtab = alloccopy(&savearena, instrtab, sizeof *instrtab * (sv->ninstr = ninstr), 0);
+ sv->instrtab = alloccopy(&savearena, instrtab, sizeof *instrtab * (sv->ninstrtab = ninstrtab), 0);
sv->contab = alloccopy(&savearena, contab.p, sizeof *contab.p * contab.n, 0);
if (calltab.n) {
sv->calltab = alloccopy(&savearena, calltab.p, sizeof *calltab.p * calltab.n, 0);
@@ -148,16 +148,14 @@ inlcall(Function *fn, Block *blk, int curi, SavedFunc *sv)
}
Block *bmap[MAX_INLINED_FN_NBLK];
- short instrmap[MAX_INLINED_FN_NINS];
+ short *instrmap = alloc(fn->passarena, sv->ninstrtab * sizeof *instrmap, 0);
for (Block *b = sv->entry; b; b = b->lnext) {
bmap[b->id] = newblk(fn);
}
- for (int i = 0; i < sv->ninstr; ++i) {
- /* TODO don't wastefully allocate for tombstone instructions
- * - mark instructions some way when they are freed (put in instrfreelist)
- * */
+ for (int i = 0; i < sv->ninstrtab; ++i) {
int allocinstr(void);
- instrmap[i] = allocinstr();
+ if (sv->instrtab[i].op)
+ instrmap[i] = allocinstr();
}
exit->npred = 0;