diff options
| author | 2023-05-30 18:20:21 +0200 | |
|---|---|---|
| committer | 2023-05-31 08:27:39 +0200 | |
| commit | 05c305bee19221e3b5b9557267c5cfa7525f752f (patch) | |
| tree | e815dc1c9bce65c3c162146df9cba2d265766ec2 /ir.c | |
| parent | 43566b21908d80b7c4448c1547c520e3e7c155af (diff) | |
fix void conditional expr; condjump, condexprvalue optimizations
Diffstat (limited to 'ir.c')
| -rw-r--r-- | ir.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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; } |