From 05c305bee19221e3b5b9557267c5cfa7525f752f Mon Sep 17 00:00:00 2001 From: lemon Date: Tue, 30 May 2023 18:20:21 +0200 Subject: fix void conditional expr; condjump, condexprvalue optimizations --- ir.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ir.c') diff --git a/ir.c b/ir.c index f6cf3a6..3d2ad8e 100644 --- a/ir.c +++ b/ir.c @@ -210,11 +210,32 @@ addphi2(struct function *fn, enum irclass cls, return mkref(RTMP, ninstr++); } +union ref +addphi(struct function *fn, enum irclass cls, struct block **blk, union ref *ref, uint n) +{ + struct phi phi = { .n = n, .cap = -1 }; + struct instr ins = { Ophi, cls }; + assert(n > 0); + phi.blk = alloc(&fn->arena, n*sizeof(struct block *) + n*sizeof(union ref), 0); + phi.ref = (union ref *)((char *)phi.blk + n*sizeof(struct block *)); + memcpy(phi.blk, blk, n * sizeof(struct block *)); + memcpy(phi.ref, ref, n * sizeof(union ref)); + vpush(&phis, phi); + ins.l = mkref(REXT, phis.n-1); + assert(ninstr < arraylength(instr)); + assert(fn->curblk != NULL); + assert(fn->curblk->ins.n == 0); + instr[ninstr] = ins; + vpush(&fn->curblk->phi, ninstr); + return mkref(RTMP, ninstr++); +} + struct block * newblk(struct function *fn) { struct block *blk = alloc(&fn->arena, sizeof(struct block), 0); memset(blk, 0, sizeof *blk); + blk->id = -1; return blk; } -- cgit v1.2.3