12 #include "bephicongr_t.h"
13 #include "bephicoal_t.h"
16 firm_dbg_module_t *dbgmod = NULL;
19 void be_phi_coal_init(void) {
20 dbgmod = firm_dbg_register("Phi coalescing");
21 firm_dbg_register("Testsdflkjsdf");
22 firm_dbg_set_mask(dbgmod, 1);
23 DBG((dbgmod, 1, "Phi coalescing dbg enabled"));
27 static INLINE ir_node **pset_to_array(pset *theset) {
31 count = pset_count(theset);
32 res = (ir_node **) malloc(count * sizeof(ir_node*));
33 for (i = 0, p = (ir_node *)pset_first(theset); p; p = (ir_node *)pset_next(theset))
41 static INLINE pset *clone(pset *theset) {
45 res = pset_new_ptr(8);
46 for (p = pset_first(theset); p; p = pset_next(theset))
47 pset_insert_ptr(res, p);
53 static void coalesce_locals(pset *phi_class) {
54 int i, count, phi_count, arity, intf_det, phi_col;
59 count = pset_count(phi_class);
60 pc = clone(phi_class);
61 // members = pset_to_array(phi_class);
63 /* how many phi nodes are in this class? */
64 DBG((dbgmod, 1, "Checking phi count\n"));
66 for (n = (ir_node *)pset_first(pc); n; n = (ir_node *)pset_next(pc)) {
74 DBG((dbgmod, 1, "Dropped: Too many phis\n"));
77 assert(phi_count == 1 && phi);
80 /* where is the definition of the arguments? */
81 DBG((dbgmod, 1, "Checking arg def\n"));
82 arity = get_irn_arity(phi);
83 for (i = 0; i < arity; ++i) {
84 ir_node *block_of_arg, *block_ith_pred;
85 ir_node *arg = get_irn_n(phi, i);
87 /* TODO: check next few lines after const node copy placement */
88 // if (iro_Const == get_irn_opcode(arg) && CONSTS_SPLIT_PHI_CLASSES)
91 block_of_arg = get_nodes_block(arg);
92 block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(phi), i));
94 if (block_of_arg != block_ith_pred) {
95 DBG((dbgmod, 1, "Dropped: Arg-def not in pred-block\n"));
101 /* determine a greedy set of non-interfering members
102 * crucial: starting with the phi node
104 DBG((dbgmod, 1, "Building greedy non-intfering set\n"));
105 intffree = pset_new_ptr(4);
107 pset_remove_ptr(pc, phi);
108 pset_insert_ptr(intffree, phi);
110 while (m = (ir_node *)pset_first(pc), m) {
111 DBG((dbgmod, 1, "Checking %n\n", m));
113 pset_remove_ptr(pc, m);
116 for (n = (ir_node *)pset_first(intffree); n; n = (ir_node *)pset_next(intffree)) {
117 DBG((dbgmod, 1, "\t%n", n));
118 if (phi_ops_interfere(m, n)) {
119 DBG((dbgmod, 1, "\tinterf\n"));
122 DBG((dbgmod, 1, "\tclean\n"));
127 DBG((dbgmod, 1, "Added to set\n"));
128 pset_insert_ptr(intffree, m);
133 * color the intffree set
135 DBG((dbgmod, 1, "Coloring...\n"));
136 phi_col = get_irn_color(phi);
137 DBG((dbgmod, 1, "phi-color: %d\n", tgt_col));
147 void be_phi_coalesce_locals(pset *all_phi_classes) {
150 DBG((dbgmod, 1, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"));
152 /* determine all phi classes */
153 for (phi_class = (pset *)pset_first(all_phi_classes); phi_class; phi_class = (pset *)pset_next(all_phi_classes))
154 coalesce_locals(phi_class);