commit 9de57265ce8453de0f773c48550ca05460844dd1
parent 190263f1b628ba3171309147120fd3ba0e370b42
Author: Michael Forney <mforney@mforney.org>
Date: Sun, 19 Apr 2020 16:31:52 -0700
Use a dynamic array for phi arguments
Diffstat:
6 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/all.h b/all.h
@@ -206,8 +206,8 @@ struct Ins {
struct Phi {
Ref to;
- Ref arg[NPred];
- Blk *blk[NPred];
+ Ref *arg;
+ Blk **blk;
uint narg;
int cls;
Phi *link;
diff --git a/amd64/sysv.c b/amd64/sysv.c
@@ -590,9 +590,13 @@ selvaarg(Fn *fn, Blk *b, Ins *i)
*b0->phi = (Phi){
.cls = Kl, .to = loc,
.narg = 2,
- .blk = {bstk, breg},
- .arg = {lstk, lreg},
+ .blk = vnew(2, sizeof b0->phi->blk[0], Pfn),
+ .arg = vnew(2, sizeof b0->phi->arg[0], Pfn),
};
+ b0->phi->blk[0] = bstk;
+ b0->phi->blk[1] = breg;
+ b0->phi->arg[0] = lstk;
+ b0->phi->arg[1] = lreg;
r0 = newtmp("abi", Kl, fn);
r1 = newtmp("abi", Kw, fn);
b->jmp.type = Jjnz;
diff --git a/arm64/abi.c b/arm64/abi.c
@@ -583,9 +583,13 @@ selvaarg(Fn *fn, Blk *b, Ins *i)
*b0->phi = (Phi){
.cls = Kl, .to = loc,
.narg = 2,
- .blk = {bstk, breg},
- .arg = {lstk, lreg},
+ .blk = vnew(2, sizeof b0->phi->blk[0], Pfn),
+ .arg = vnew(2, sizeof b0->phi->arg[0], Pfn),
};
+ b0->phi->blk[0] = bstk;
+ b0->phi->blk[1] = breg;
+ b0->phi->arg[0] = lstk;
+ b0->phi->arg[1] = lreg;
r0 = newtmp("abi", Kl, fn);
r1 = newtmp("abi", Kw, fn);
b->jmp.type = Jjnz;
diff --git a/load.c b/load.c
@@ -330,6 +330,8 @@ def(Slice sl, bits msk, Blk *b, Ins *i, Loc *il)
p->to = r;
p->cls = sl.cls;
p->narg = b->npred;
+ p->arg = vnew(p->narg, sizeof p->arg[0], Pfn);
+ p->blk = vnew(p->narg, sizeof p->blk[0], Pfn);
for (np=0; np<b->npred; ++np) {
bp = b->pred[np];
if (!bp->s2
diff --git a/parse.c b/parse.c
@@ -673,7 +673,9 @@ Ins:
phi = alloc(sizeof *phi);
phi->to = r;
phi->cls = k;
+ phi->arg = vnew(i, sizeof arg[0], Pfn);
memcpy(phi->arg, arg, i * sizeof arg[0]);
+ phi->blk = vnew(i, sizeof blk[0], Pfn);
memcpy(phi->blk, blk, i * sizeof blk[0]);
phi->narg = i;
*plink = phi;
diff --git a/ssa.c b/ssa.c
@@ -181,6 +181,8 @@ phiins(Fn *fn)
p->cls = k;
p->to = TMP(t);
p->link = a->phi;
+ p->arg = vnew(0, sizeof p->arg[0], Pfn);
+ p->blk = vnew(0, sizeof p->blk[0], Pfn);
a->phi = p;
if (!bshas(defs, a->id))
if (!bshas(u, a->id)) {
@@ -294,8 +296,8 @@ renblk(Blk *b, Name **stk, Fn *fn)
t = p->to.val;
if ((t=fn->tmp[t].visit)) {
m = p->narg++;
- if (m == NPred)
- die("renblk, too many phi args");
+ vgrow(&p->arg, p->narg);
+ vgrow(&p->blk, p->narg);
p->arg[m] = getstk(t, b, stk);
p->blk[m] = b;
}