From 27177e293d914d15fdef3798c1ce1628f83d55ef Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 5 May 2011 15:31:58 +0200 Subject: [PATCH] verify that all blocks can be found by walk_block_graph This also ensures the invariant that at least 1 block in an endless loop is kept. --- ir/ir/irgwalk.c | 7 +------ ir/ir/irverify.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index df0af385d..5ed8c0153 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -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); } diff --git a/ir/ir/irverify.c b/ir/ir/irverify.c index 51d6c3a93..761f56cb1 100644 --- a/ir/ir/irverify.c +++ b/ir/ir/irverify.c @@ -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; } -- 2.20.1