Fix bug where pushes were being placed in the wrong blocks.

This commit is contained in:
David Given 2016-10-08 10:21:24 +02:00
parent 4e49830e09
commit 9db902314b

View file

@ -1,6 +1,6 @@
#include "mcg.h" #include "mcg.h"
static ARRAYOF(struct ir) pops; static PMAPOF(struct basicblock, struct ir) pops;
static PMAPOF(struct basicblock, struct ir) pushes; static PMAPOF(struct basicblock, struct ir) pushes;
static struct ir* get_last_push(struct basicblock* bb) static struct ir* get_last_push(struct basicblock* bb)
@ -62,7 +62,7 @@ static void convert_block(struct procedure* proc, struct basicblock* bb)
ir = get_first_pop(outbb); ir = get_first_pop(outbb);
if (!ir || (ir->size != lastpush->size)) if (!ir || (ir->size != lastpush->size))
return; return;
array_appendu(&pops, ir); pmap_add(&pops, outbb, ir);
/* Also abort unless *every* predecessor block of the one we've /* Also abort unless *every* predecessor block of the one we've
* just found *also* ends in a push of the same size. */ * just found *also* ends in a push of the same size. */
@ -93,7 +93,8 @@ static void convert_block(struct procedure* proc, struct basicblock* bb)
for (i=0; i<pops.count; i++) for (i=0; i<pops.count; i++)
{ {
struct ir* ir = pops.item[i]; struct basicblock* outbb = pops.item[i].left;
struct ir* ir = pops.item[i].right;
struct ir* phi = new_ir0(IR_PHI, ir->size); struct ir* phi = new_ir0(IR_PHI, ir->size);
for (j=0; j<pushes.count; j++) for (j=0; j<pushes.count; j++)
@ -103,7 +104,6 @@ static void convert_block(struct procedure* proc, struct basicblock* bb)
phi->root = phi; phi->root = phi;
*ir = *phi; *ir = *phi;
array_insert(&bb->irs, ir, 0);
} }
} }
} }