aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-31 11:13:15 +0100
committerlemon <lsof@mailbox.org>2025-12-31 11:13:15 +0100
commit97c6d5c44f30b29b52d1dc431ab9f2df4bb47fd2 (patch)
tree564615d402793491d545d612df31dd80451120ab /ir
parent3a46902b3ede49116522992793d3ececef53c5a8 (diff)
backend: separate instrs for integer/float store
Diffstat (limited to 'ir')
-rw-r--r--ir/abi0.c13
-rw-r--r--ir/intrin.c2
-rw-r--r--ir/ir.c5
-rw-r--r--ir/ir.h3
-rw-r--r--ir/mem2reg.c10
-rw-r--r--ir/op.def10
-rw-r--r--ir/regalloc.c6
7 files changed, 30 insertions, 19 deletions
diff --git a/ir/abi0.c b/ir/abi0.c
index 85f7003..d688e03 100644
--- a/ir/abi0.c
+++ b/ir/abi0.c
@@ -121,11 +121,11 @@ patchparam(struct function *fn, int *curi, int *param, int tydat, int nabi, stru
* store* %x, %a
* store* %x + N, %b
*/
- st = mkinstr(Ostore8 + ilog2(cls2siz[abi[0].ty.cls]), 0, alloc, r[0]);
+ st = mkinstr(cls2store[abi[0].ty.cls], 0, alloc, r[0]);
insertinstr(blk, ++*curi, st);
if (nabi > 1) {
struct instr tmp = mkinstr(Oadd, KPTR, alloc, mkref(RICON, r2off));
- st = mkinstr(Ostore8 + ilog2(cls2siz[abi[1].ty.cls]), 0, insertinstr(blk, ++*curi, tmp), r[1]);
+ st = mkinstr(cls2store[abi[1].ty.cls], 0, insertinstr(blk, ++*curi, tmp), r[1]);
insertinstr(blk, ++*curi, st);
}
}
@@ -226,7 +226,7 @@ patcharg(struct block *blk, int *icall, struct call *call,
union ref sadr = off == 0 ? src : insertinstr(blk, ++arginst, mkinstr(Oadd, KPTR, src, mkref(RICON, off)));
union ref tmp = insertinstr(blk, ++arginst, mkinstr(Oloads8+2*ilog2(align), align < 8 ? KI32 : KI64, sadr));
union ref dadr = off == 0 ? dst : insertinstr(blk, ++arginst, mkinstr(Oadd, KPTR, dst, mkref(RICON, off)));
- insertinstr(blk, ++arginst, mkinstr(Ostore8+ilog2(align), 0, dadr, tmp));
+ insertinstr(blk, ++arginst, mkinstr(Ostorei8+ilog2(align), 0, dadr, tmp));
}
*icall = arginst + (call->narg - argidx);
return 1;
@@ -320,12 +320,7 @@ abi0_call(struct function *fn, struct instr *ins, struct block *blk, int *curi)
r[1] = insertinstr(blk, ++*curi, ret2);
}
for (int i = 0; i < nret; ++i) {
- struct instr store = {0};
- switch (call->abiret[i].ty.cls) {
- default: assert(0);
- case KF32: case KI32: store.op = Ostore32; break;
- case KI64: case KF64: store.op = Ostore64; break;
- }
+ struct instr store = { cls2store[call->abiret[i].ty.cls] };
if (i == 0) {
store.l = retmem;
} else {
diff --git a/ir/intrin.c b/ir/intrin.c
index dcd05a5..ca49341 100644
--- a/ir/intrin.c
+++ b/ir/intrin.c
@@ -37,7 +37,7 @@ intrin(struct block *blk, int *curi, enum intrin in, struct arg *args, int narg,
psrc = insertinstr(blk, ++*curi, mkinstr(Oadd, KPTR, *args[1].arg, mkref(RICON, off)));
}
src = insertinstr(blk, ++*curi, mkinstr(Oloads8 + 2*ilog2(step), step < 8 ? KI32 : KI64, psrc));
- insertinstr(blk, ++*curi, mkinstr(Ostore8 + ilog2(step), 0, pdst, src));
+ insertinstr(blk, ++*curi, mkinstr(Ostorei8 + ilog2(step), 0, pdst, src));
}
return 1;
}
diff --git a/ir/ir.c b/ir/ir.c
index 29d52d4..cc16919 100644
--- a/ir/ir.c
+++ b/ir/ir.c
@@ -6,6 +6,9 @@ uchar cls2siz[] = { [KI32] = 4, [KI64] = 8, [KF32] = 4, [KF64] = 8 };
uchar cls2load[] = {
[KI32] = Oloads32, [KI64] = Oloadi64,
[KF32] = Oloadf32, [KF64] = Oloadf64, [KPTR] = -1
+}, cls2store[] = {
+ [KI32] = Ostorei32, [KI64] = Ostorei64,
+ [KF32] = Ostoref32, [KF64] = Ostoref64, [KPTR] = -1
};
const uchar siz2intcls[] = { [1] = KI32, [2] = KI32, [4] = KI32, [8] = KI64 };
@@ -71,6 +74,7 @@ irinit(struct function *fn)
type2cls[TYARRAY] = KPTR;
cls2siz[KPTR] = targ_primsizes[TYPTR];
cls2load[KPTR] = targ_64bit ? Oloadi64 : Oloads32;
+ cls2store[KPTR] = targ_64bit ? Ostorei64 : Ostorei32;
}
fn->entry = fn->curblk = allocz(fn->arena, sizeof(struct block), 0);
fn->nblk = 1;
@@ -513,6 +517,7 @@ replcuses(union ref from, union ref to)
} else if (instrtab[use->u].op == Ophi) {
u = phitab.p[instrtab[use->u].l.i];
n = use->blk->npred;
+ if (use->blk->phi.n == 0) continue; /* shouldn't happen */
} else {
u = &instrtab[use->u].l;
n = 2;
diff --git a/ir/ir.h b/ir/ir.h
index 8402864..5fe5e96 100644
--- a/ir/ir.h
+++ b/ir/ir.h
@@ -101,7 +101,7 @@ enum op {
#define oiscmp(o) in_range(o, Oequ, Ougte)
#define oisarith(o) in_range(o, Oneg, Ougte)
#define oisalloca(o) in_range(o, Oalloca1, Oalloca16)
-#define oisstore(o) in_range(o, Ostore8, Ostore64)
+#define oisstore(o) in_range(o, Ostorei8, Ostoref64)
#define oisload(o) in_range(o, Oloads8, Oloadf64)
extern const char *opnames[];
extern const uchar opnarg[];
@@ -235,6 +235,7 @@ enum { MAXINSTR = 1<<15 };
extern uchar type2cls[];
extern uchar cls2siz[];
extern uchar cls2load[];
+extern uchar cls2store[];
extern const uchar siz2intcls[];
extern struct instr instrtab[];
extern struct use *instruse[];
diff --git a/ir/mem2reg.c b/ir/mem2reg.c
index 4b0b007..7a5874c 100644
--- a/ir/mem2reg.c
+++ b/ir/mem2reg.c
@@ -15,10 +15,18 @@ static const uchar load2ext[] = {
[Oloads32 - Oloads8] = Oexts32, [Oloadu32 - Oloads8] = Oextu32,
[Oloadi64 - Oloads8] = Ocopy,
};
+static const uchar storesz[] = {
+ [Ostorei8 - Ostorei8] = 1,
+ [Ostorei16 - Ostorei8] = 2,
+ [Ostorei32 - Ostorei8] = 4,
+ [Ostorei64 - Ostorei8] = 8,
+ [Ostoref32 - Ostorei8] = 4,
+ [Ostoref64 - Ostorei8] = 8,
+};
#define loadsz(o) (loadszcls[(o) - Oloads8] & 0xF)
#define loadcls(o) (loadszcls[(o) - Oloads8] >> 4)
#define load2ext(o) (load2ext[(o) - Oloads8])
-#define storesz(o) (1 << ((o) - Ostore8))
+#define storesz(o) (storesz[(o) - Ostorei8])
/* Implements algorithm in 'Simple and Efficient Construction of Static Single Assignment' (Braun et al) */
diff --git a/ir/op.def b/ir/op.def
index 2476ecf..ac753c0 100644
--- a/ir/op.def
+++ b/ir/op.def
@@ -57,10 +57,12 @@ _(loadu32, 1)
_(loadi64, 1)
_(loadf32, 1)
_(loadf64, 1)
-_(store8, 2)
-_(store16, 2)
-_(store32, 2)
-_(store64, 2)
+_(storei8, 2)
+_(storei16, 2)
+_(storei32, 2)
+_(storei64, 2)
+_(storef32, 2)
+_(storef64, 2)
_(param, 2)
_(arg, 2)
_(call, 2)
diff --git a/ir/regalloc.c b/ir/regalloc.c
index 9678559..39a3f74 100644
--- a/ir/regalloc.c
+++ b/ir/regalloc.c
@@ -264,7 +264,7 @@ emitmove(enum irclass k, union alloc dst, union alloc src, struct block *blk, in
addstkslotref(insertinstr(blk, curi++, mv).i, src.a*8);
} else reg = src.a;
if (dst.t == ASTACK) {
- mv = mkinstr(Ostore8+ilog2(cls2siz[k]), 0, .r = mkref(RREG, reg));
+ mv = mkinstr(cls2store[k], 0, .r = mkref(RREG, reg));
addstkslotref(insertinstr(blk, curi, mv).i, dst.a*8);
}
}
@@ -1137,7 +1137,7 @@ devirt(struct rega *ra, struct block *blk)
alloc = temp < ra->intervals.ntemps && (it = &ra->intervals.temps[temp]) && it->nrange ? &it->alloc : NULL;
if (alloc && alloc->t == ASTACK) {
enum irclass cls = insrescls(*ins);
- int store = Ostore8 + ilog2(cls2siz[cls]);
+ int store = cls2store[cls];
/* t was spilled, gen store */
if (ins->op == Ocopy && ins->l.t != RADDR) {
ins->op = store;
@@ -1171,7 +1171,7 @@ devirt(struct rega *ra, struct block *blk)
}
}
}
- if (!ins->reg && insrescls(*ins) && ins->op != Omove && !ins->keep && !in_range(ins->op, Ostore8, Ostore64)) {
+ if (!ins->reg && insrescls(*ins) && ins->op != Omove && !ins->keep && !oisstore(ins->op)) {
/* dead */
Nop:
ins->op = Onop;