and again
[libfirm] / ir / opt / combo.c
index 8f95093..099091c 100644 (file)
@@ -50,6 +50,7 @@
 #include "irgmod.h"
 #include "iropt_dbg.h"
 #include "debug.h"
+#include "array_t.h"
 #include "error.h"
 
 #include "tv_t.h"
@@ -63,9 +64,6 @@
 /* define this to check the consistency of partitions */
 #define CHECK_PARTITIONS
 
-/* define this to disable followers (may be buggy) */
-#undef NO_FOLLOWER
-
 typedef struct node_t            node_t;
 typedef struct partition_t       partition_t;
 typedef struct opcode_key_t      opcode_key_t;
@@ -225,6 +223,7 @@ static void check_all_partitions(environment_t *env) {
        partition_t *P;
        node_t      *node;
 
+#ifdef DEBUG_libfirm
        for (P = env->dbg_list; P != NULL; P = P->dbg_next) {
                check_partition(P);
                list_for_each_entry(node_t, node, &P->Follower, node_list) {
@@ -233,6 +232,7 @@ static void check_all_partitions(environment_t *env) {
                        assert(leader != node && leader->part == node->part);
                }
        }
+#endif
 }
 
 /**
@@ -500,6 +500,7 @@ static INLINE tarval *get_node_tarval(const ir_node *irn) {
  */
 static INLINE void add_to_worklist(partition_t *X, environment_t *env) {
        assert(X->on_worklist == 0);
+       DB((dbg, LEVEL_2, "Adding part%d to worklist\n", X->nr));
        X->wl_next     = env->worklist;
        X->on_worklist = 1;
        env->worklist  = X;
@@ -814,12 +815,6 @@ static partition_t *split_no_followers(partition_t *Z, node_t *g, environment_t
        return Z_prime;
 }  /* split_no_followers */
 
-#ifdef NO_FOLLOWER
-
-#define split(Z, g, env) split_no_followers(*(Z), g, env)
-
-#else
-
 /**
  * Make the Follower -> Leader transition for a node.
  *
@@ -1151,7 +1146,6 @@ static partition_t *split(partition_t **pX, node_t *gg, environment_t *env) {
 
        return X_prime;
 }  /* split */
-#endif /* NO_FOLLOWER */
 
 /**
  * Returns non-zero if the i'th input of a Phi node is live.
@@ -2556,13 +2550,9 @@ static void propagate(environment_t *env) {
                for (x = fallen; x != NULL; x = x->next)
                        x->on_fallen = 0;
 
-#ifndef NO_FOLLOWER
                if (old_type_was_T_or_C) {
                        node_t *y, *tmp;
 
-                       if (Y->on_worklist == 0)
-                               add_to_worklist(Y, env);
-
                        /* check if some nodes will make the leader -> follower transition */
                        list_for_each_entry_safe(node_t, y, tmp, &Y->Leader, node_list) {
                                if (y->type.tv != tarval_top && ! is_con(y->type)) {
@@ -2581,7 +2571,6 @@ static void propagate(environment_t *env) {
                                }
                        }
                }
-#endif
                split_by(Y, env);
        }
 }  /* propagate */
@@ -2659,19 +2648,22 @@ static void apply_cf(ir_node *block, void *ctx) {
                env->modified = 1;
 
                for (i = n - 1; i >= 0; --i) {
-                       ir_node *pred    = get_Block_cfgpred(block, i);
-                       node_t  *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
-
-                       if (pred_bl->flagged == 0) {
-                               pred_bl->flagged = 3;
-
-                               if (pred_bl->type.tv == tarval_reachable) {
-                                       /*
-                                        * We will remove an edge from block to its pred.
-                                        * This might leave the pred block as an endless loop
-                                        */
-                                       if (! is_backedge(block, i))
-                                               keep_alive(pred_bl->node);
+                       ir_node *pred = get_Block_cfgpred(block, i);
+
+                       if (! is_Bad(pred)) {
+                               node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
+
+                               if (pred_bl->flagged == 0) {
+                                       pred_bl->flagged = 3;
+
+                                       if (pred_bl->type.tv == tarval_reachable) {
+                                               /*
+                                                * We will remove an edge from block to its pred.
+                                                * This might leave the pred block as an endless loop
+                                                */
+                                               if (! is_backedge(block, i))
+                                                       keep_alive(pred_bl->node);
+                                       }
                                }
                        }
                }
@@ -2681,6 +2673,7 @@ static void apply_cf(ir_node *block, void *ctx) {
                if (block != get_irg_end_block(current_ir_graph)) {
                        /* mark dead blocks */
                        set_Block_dead(block);
+                       DB((dbg, LEVEL_1, "Removing dead %+F\n", block));
                } else {
                        /* the endblock is unreachable */
                        set_irn_in(block, 0, NULL);
@@ -2694,6 +2687,7 @@ static void apply_cf(ir_node *block, void *ctx) {
 
                if (can_exchange(pred)) {
                        ir_node *new_block = get_nodes_block(pred);
+                       DB((dbg, LEVEL_1, "Fuse %+F with %+F\n", block, new_block));
                        DBG_OPT_COMBO(block, new_block, FS_OPT_COMBO_CF);
                        exchange(block, new_block);
                        node->node = new_block;
@@ -2711,18 +2705,21 @@ static void apply_cf(ir_node *block, void *ctx) {
                if (node->type.tv == tarval_reachable) {
                        in_X[k++] = pred;
                } else {
-                       node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
-
-                       if (pred_bl->flagged == 0) {
-                               pred_bl->flagged = 3;
-
-                               if (pred_bl->type.tv == tarval_reachable) {
-                                       /*
-                                        * We will remove an edge from block to its pred.
-                                        * This might leave the pred block as an endless loop
-                                        */
-                                       if (! is_backedge(block, i))
-                                               keep_alive(pred_bl->node);
+                       DB((dbg, LEVEL_1, "Removing dead input %d from %+F (%+F)\n", i, block, pred));
+                       if (! is_Bad(pred)) {
+                               node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
+
+                               if (pred_bl->flagged == 0) {
+                                       pred_bl->flagged = 3;
+
+                                       if (pred_bl->type.tv == tarval_reachable) {
+                                               /*
+                                                * We will remove an edge from block to its pred.
+                                                * This might leave the pred block as an endless loop
+                                                */
+                                               if (! is_backedge(block, i))
+                                                       keep_alive(pred_bl->node);
+                                       }
                                }
                        }
                }
@@ -2914,7 +2911,7 @@ static void apply_end(ir_node *end, environment_t *env) {
                if (! is_Block(ka))
                        node = get_irn_node(get_nodes_block(ka));
 
-               if (node->type.tv != tarval_unreachable)
+               if (node->type.tv != tarval_unreachable && !is_Bad(ka))
                        in[j++] = ka;
        }
        if (j != n) {
@@ -2960,11 +2957,13 @@ static void set_compute_functions(void) {
 }  /* set_compute_functions */
 
 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local) {
+#ifdef DEBUG_libfirm
        ir_node *irn = local != NULL ? local : n;
        node_t *node = get_irn_node(irn);
 
        ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
        return 1;
+#endif
 }
 
 void combo(ir_graph *irg) {
@@ -2999,7 +2998,6 @@ void combo(ir_graph *irg) {
        assure_irg_outs(irg);
        assure_cf_loop(irg);
 
-
        /* we have our own value_of function */
        set_value_of_func(get_node_tarval);