Commit 7f4af57e authored by Matthias Braun's avatar Matthias Braun
Browse files

verifier to check that no out edges point to dead/removed nodes

parent dd140fb7
......@@ -677,3 +677,55 @@ int be_verify_register_allocation(const arch_env_t *arch_env, ir_graph *irg) {
return !env.problem_found;
}
//---------------------------------------------------------------------------
typedef struct _verify_out_dead_nodes_env {
ir_graph *irg;
bitset_t *reachable;
bitset_t *visited;
int problem_found;
} verify_out_dead_nodes_env;
static void check_out_edges(ir_node *node, verify_out_dead_nodes_env *env) {
const ir_edge_t* edge;
foreach_out_edge(node, edge) {
ir_node* src = get_edge_src_irn(edge);
if(!bitset_is_set(env->reachable, get_irn_idx(src))) {
ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) only reachable through out edges from %+F\n",
src, get_nodes_block(src), get_irg_dump_name(env->irg), node);
env->problem_found = 1;
}
if(!bitset_is_set(env->visited, get_irn_idx(src))) {
bitset_set(env->visited, get_irn_idx(src));
if(!is_Block(src))
check_out_edges(src, env);
}
}
}
static void set_reachable(ir_node *node, void* data)
{
bitset_t* reachable = data;
bitset_set(reachable, get_irn_idx(node));
}
int be_verify_out_edges(ir_graph *irg) {
verify_out_dead_nodes_env env;
env.irg = irg;
env.reachable = bitset_alloca(get_irg_last_idx(irg));
env.visited = bitset_alloca(get_irg_last_idx(irg));
env.problem_found = 0;
irg_walk_graph(irg, set_reachable, NULL, env.reachable);
check_out_edges(get_irg_start(irg), &env);
return !env.problem_found;
}
......@@ -55,4 +55,12 @@ int be_verify_spillslots(const arch_env_t *arch_env, ir_graph *irg);
*/
int be_verify_register_allocation(const arch_env_t *arch_env, ir_graph *irg);
/**
* Verify that out edges are valid
*
* @param irg The irg to check
* @param 1 if verify succeeded, 0 otherwise
*/
int be_verify_out_edges(ir_graph *irg);
#endif /* BEVERIFY_H_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment