trverify: cleanup, check irg.entity == entity.irg
[libfirm] / ir / opt / cfopt.c
index 7ed73c2..b455993 100644 (file)
@@ -114,7 +114,7 @@ static void collect_nodes(ir_node *n, void *ctx)
                ir_node *block = get_nodes_block(n);
                add_Block_phi(block, n);
        } else if (is_Block(n)) {
-               if (has_Block_entity(n)) {
+               if (get_Block_entity(n) != NULL) {
                        /* block with a jump label attached cannot be removed. */
                        set_Block_removable(n, false);
                }
@@ -234,6 +234,26 @@ non_dispensable:
        return 1;
 }
 
+/**
+ * This method merges blocks. A block is applicable to be merged, if it
+ * has only one predecessor with an unconditional jump to this block;
+ * and if this block does not contain any phis.
+ */
+static void merge_blocks(ir_node *b, void *env)
+{
+       (void) env;
+
+       if (get_Block_n_cfgpreds(b) == 1) {
+               ir_node* pred = get_Block_cfgpred(b, 0);
+               if (is_Jmp(pred)) {
+                       ir_node* pred_block = get_nodes_block(pred);
+                       if (get_Block_phis(b) == NULL) {
+                               exchange(b, pred_block);
+                       }
+               }
+       }
+}
+
 /**
  * This method removes empty blocks.  A block is empty if it only contains Phi
  * and Jmp nodes.
@@ -861,7 +881,7 @@ static ir_graph_state_t do_cfopt(ir_graph *irg)
         * blocks, which it finds in a linked list computed before.
         * */
        assure_doms(irg);
-       irg_block_walk_graph(irg, optimize_blocks, NULL, &env);
+       irg_block_walk_graph(irg, optimize_blocks, merge_blocks, &env);
 
        new_end = optimize_in_place(end);
        if (new_end != end) {