aboutsummaryrefslogtreecommitdiffhomepage
path: root/c.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-21 12:32:32 +0200
committerlemon <lsof@mailbox.org>2023-06-21 12:32:32 +0200
commit995fd23ecd5de710a6f587d29af2874b1fb4756d (patch)
treec8c8d95d51a25abbfc3ea08f984b8a1720cacc4b /c.c
parent2e4d5123544b86ec13e166dc94da43c850a588f2 (diff)
explicitly store predecessors in each block
Diffstat (limited to 'c.c')
-rw-r--r--c.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/c.c b/c.c
index a8f2aa4..27abfe9 100644
--- a/c.c
+++ b/c.c
@@ -1255,7 +1255,6 @@ Loop:
}
struct condphis {
- vec_of(struct block *) blk;
vec_of(union ref) ref;
};
@@ -1289,7 +1288,6 @@ condexprrec(struct function *fn, const struct expr *ex, struct condphis *phis,
condexprrec(fn, &ex->sub[2], phis, -1, end, zero);
} else {
r = exprvalue(fn, ex);
- vpush(&phis->blk, fn->curblk);
if (boolcon == -2)
r = cvt(fn, TYBOOL, ex->ty.t, r);
if (boolcon >= 0)
@@ -1305,6 +1303,23 @@ condexprrec(struct function *fn, const struct expr *ex, struct condphis *phis,
}
}
+/* the naive way to generate something like a ? b : c ? d : e, uses multiple phis,
+ * this code reduces such nested conditional expressions into one phi */
+static union ref
+condexprvalue(struct function *fn, const struct expr *ex)
+{
+ union ref refbuf[8];
+ struct condphis phis = { VINIT(refbuf, arraylength(refbuf)) };
+ struct block *dst = newblk(fn);
+ union ref r;
+ condexprrec(fn, ex, &phis, -1, dst, NULL);
+ useblk(fn, dst);
+ assert(fn->curblk->npred == phis.ref.n);
+ r = addphi(fn, type2cls[ex->ty.t], phis.ref.p);
+ vfree(&phis.ref);
+ return r;
+}
+
static union ref
compilecall(struct function *fn, const struct expr *ex)
{
@@ -1335,25 +1350,6 @@ compilecall(struct function *fn, const struct expr *ex)
return addinstr(fn, ins);
}
-/* the naive way to generate something like a ? b : c ? d : e, uses multiple phis,
- * this code reduces such nested conditional expressions into one phi */
-static union ref
-condexprvalue(struct function *fn, const struct expr *ex)
-{
- struct block *blkbuf[8];
- union ref refbuf[8];
- struct condphis phis = { VINIT(blkbuf, arraylength(blkbuf)),
- VINIT(refbuf, arraylength(refbuf))};
- struct block *dst = newblk(fn);
- union ref r;
- condexprrec(fn, ex, &phis, -1, dst, NULL);
- useblk(fn, dst);
- r = addphi(fn, type2cls[ex->ty.t], phis.blk.p, phis.ref.p, phis.blk.n);
- vfree(&phis.blk);
- vfree(&phis.ref);
- return r;
-}
-
static union ref
compileexpr(struct function *fn, const struct expr *ex, bool discard)
{