verify that all blocks can be found by walk_block_graph
authorMatthias Braun <matze@braunis.de>
Thu, 5 May 2011 13:31:58 +0000 (15:31 +0200)
committerMatthias Braun <matze@braunis.de>
Fri, 6 May 2011 07:27:25 +0000 (09:27 +0200)
This also ensures the invariant that at least 1 block in an endless
loop is kept.

ir/ir/irgwalk.c
ir/ir/irverify.c

index df0af38..5ed8c01 100644 (file)
@@ -393,12 +393,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
                int i;
                for (i = 0; i < arity; i++) {
                        ir_node *pred = get_irn_n(node, i);
-                       if (!is_Block(pred)) {
-                               pred = get_nodes_block(pred);
-                       }
-                       /* this walker is also used during optimize_graph_df where we can
-                        * temporarily have Bad as block inputs */
-                       if (is_Bad(pred))
+                       if (!is_Block(pred))
                                continue;
                        irg_block_walk_2(pred, pre, post, env);
                }
index 51d6c3a..761f56c 100644 (file)
@@ -1825,6 +1825,7 @@ typedef struct check_cfg_env_t {
        pmap *branch_nodes; /**< map blocks to their branching nodes,
                                 map mode_X nodes to the blocks they branch to */
        int   res;
+       ir_nodeset_t reachable_blocks;
        ir_nodeset_t kept_nodes;
        ir_nodeset_t true_projs;
        ir_nodeset_t false_projs;
@@ -1836,6 +1837,10 @@ static int check_block_cfg(ir_node *block, check_cfg_env_t *env)
        int   n_cfgpreds;
        int   i;
 
+       ASSERT_AND_RET_DBG(ir_nodeset_contains(&env->reachable_blocks, block),
+                          "Block is not reachable by blockwalker (endless loop with no kept block?)", 0,
+                          ir_printf("block %+F\n", block));
+
        n_cfgpreds   = get_Block_n_cfgpreds(block);
        branch_nodes = env->branch_nodes;
        for (i = 0; i < n_cfgpreds; ++i) {
@@ -1933,6 +1938,12 @@ static void assert_branch(ir_node *node, void *data)
        }
 }
 
+static void collect_reachable_blocks(ir_node *block, void *data)
+{
+       ir_nodeset_t *reachable_blocks = (ir_nodeset_t*) data;
+       ir_nodeset_insert(reachable_blocks, block);
+}
+
 /**
  * Checks CFG well-formedness
  */
@@ -1941,9 +1952,13 @@ static int check_cfg(ir_graph *irg)
        check_cfg_env_t env;
        env.branch_nodes = pmap_create(); /**< map blocks to branch nodes */
        env.res          = 1;
+       ir_nodeset_init(&env.reachable_blocks);
        ir_nodeset_init(&env.true_projs);
        ir_nodeset_init(&env.false_projs);
 
+       irg_block_walk_graph(irg, collect_reachable_blocks, NULL,
+                            &env.reachable_blocks);
+
        /* note that we do not use irg_walk_block because it will miss these
         * invalid blocks without a jump instruction which we want to detect
         * here */
@@ -1964,6 +1979,7 @@ static int check_cfg(ir_graph *irg)
        ir_nodeset_destroy(&env.false_projs);
        ir_nodeset_destroy(&env.true_projs);
        ir_nodeset_destroy(&env.kept_nodes);
+       ir_nodeset_destroy(&env.reachable_blocks);
        pmap_destroy(env.branch_nodes);
        return env.res;
 }