aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ir.c')
-rw-r--r--ir.c21
1 files changed, 21 insertions, 0 deletions
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;
}