Extract code and form new function minimize_ssa.
@@ -1651,12 +1651,42 @@ static void seal_bb (gen_ctx_t gen_ctx, bb_t bb) {
}
}
+static void minimize_ssa (gen_ctx_t gen_ctx) {
+ bb_insn_t phi, def;
+ size_t i, n;
+ int op_num, change_p;
+
+#if 0
+ fprintf (stderr, "Removing (%ld):", insns_num);
+#endif
+ do {
+ change_p = FALSE;
+ n = 0;
+#if 0
+ fprintf (stderr, " %ld", VARR_LENGTH (bb_insn_t, phis));
+#endif
+ for (i = 0; i < VARR_LENGTH (bb_insn_t, phis); i++) {
+ phi = VARR_GET (bb_insn_t, phis, i);
+ if ((def = trivial_phi (gen_ctx, phi, &op_num)) == NULL) {
+ VARR_SET (bb_insn_t, phis, n++, phi);
+ continue;
+ }
+ remove_trivial_phi (gen_ctx, phi, def, op_num);
+ change_p = TRUE;
+ }
+ VARR_TRUNC (bb_insn_t, phis, n);
+ } while (change_p);
+#if 0
+ fprintf (stderr, "\n");
+#endif
+}
+
static void build_ssa (gen_ctx_t gen_ctx) {
bb_t bb;
out_edge_t e;
bb_insn_t def, bb_insn, phi;
- int op_num, out_p, mem_p, def_op_num, var_index, change_p;
- size_t passed_mem_num, insns_num, i, j;
+ int op_num, out_p, mem_p, def_op_num, var_index;
+ size_t passed_mem_num, insns_num, i;
MIR_reg_t var;
def_tab_el_t el;
insn_var_iterator_t iter;
@@ -1702,29 +1732,7 @@ static void build_ssa (gen_ctx_t gen_ctx) {
for (e = DLIST_HEAD (out_edge_t, bb->out_edges); e != NULL; e = DLIST_NEXT (out_edge_t, e))
if (is_being_sealed_p (gen_ctx, e->dst)) seal_bb (gen_ctx, e->dst);
}
-#if 0
- fprintf (stderr, "Removing (%ld):", insns_num);
-#endif
- do { /* SSA minimization: */
- change_p = FALSE;
- j = 0;
-#if 0
- fprintf (stderr, " %ld", VARR_LENGTH (bb_insn_t, phis));
-#endif
- for (i = 0; i < VARR_LENGTH (bb_insn_t, phis); i++) {
- phi = VARR_GET (bb_insn_t, phis, i);
- if ((def = trivial_phi (gen_ctx, phi, &op_num)) == NULL) {
- VARR_SET (bb_insn_t, phis, j++, phi);
- continue;
- }
- remove_trivial_phi (gen_ctx, phi, def, op_num);
- change_p = TRUE;
- }
- VARR_TRUNC (bb_insn_t, phis, j);
- } while (change_p);
-#if 0
- fprintf (stderr, "\n");
-#endif
+ minimize_ssa (gen_ctx);
VARR_TRUNC (int, var_indexes, 0);
for (bb = DLIST_HEAD (bb_t, curr_cfg->bbs); bb != NULL; bb = DLIST_NEXT (bb_t, bb))
for (bb_insn = DLIST_HEAD (bb_insn_t, bb->bb_insns); bb_insn != NULL;
