From: David Given Date: Thu, 25 Oct 2018 02:46:19 +0000 (+0200) Subject: Neuter a ghastly O(n^2) algorithm. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0ee1bb575ec0926f3eca14edfcb76f10a35e3dae;p=ack.git Neuter a ghastly O(n^2) algorithm. --- diff --git a/mach/proto/mcg/pass_nonlocalphis.c b/mach/proto/mcg/pass_nonlocalphis.c index 52387c76e..acc359201 100644 --- a/mach/proto/mcg/pass_nonlocalphis.c +++ b/mach/proto/mcg/pass_nonlocalphis.c @@ -156,33 +156,38 @@ static void import_ir(struct ir* phi) void pass_convert_nonlocal_phis(void) { int i, j, k; + bool need_restart; graph_reset(&added); /* If a phi refers to an IR defined in a node which isn't a direct parent, * insert phis upstream for it. */ -restart: - for (i=0; iirs.count; j++) + for (i=0; iirs.item[j]; - if (phi->opcode == IR_PHI) + current_dest = dominance.preorder.item[i]; + + for (j=0; jirs.count; j++) { - for (k=0; ku.phivalue.count; k++) + struct ir* phi = current_dest->irs.item[j]; + if (phi->opcode == IR_PHI) { - current_ir = phi->u.phivalue.item[k].right; - current_src = current_ir->bb; - - if (!array_contains(¤t_dest->prevs, current_src)) + for (k=0; ku.phivalue.count; k++) { - tracef('I', "I: import of non-local IR $%d into %s from %s\n", - current_ir->id, current_dest->name, current_src->name); - import_ir(phi); - goto restart; + current_ir = phi->u.phivalue.item[k].right; + current_src = current_ir->bb; + + if (!array_contains(¤t_dest->prevs, current_src)) + { + tracef('I', "I: import of non-local IR $%d into %s from %s\n", + current_ir->id, current_dest->name, current_src->name); + import_ir(phi); + need_restart = true; + } } } }