X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgwalk.c;h=22feaeba36d904d1f4ac55ec91e1b060680fbeb3;hb=1de3ff1c7f4478924c6348f774608e60b962d055;hp=8e55c01020aad5ace5617b69d7c348671788aabb;hpb=d7337be4ef7938bf403e919f71844215a56e10b2;p=libfirm diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 8e55c0102..22feaeba3 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -160,11 +160,15 @@ void irg_walk_core(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) { - ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED); - inc_irg_visited(current_ir_graph); - assert(current_ir_graph == get_irn_irg(node)); + ir_graph *irg = get_irn_irg(node); + ir_graph *rem = current_ir_graph; + + current_ir_graph = irg; + ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED); + inc_irg_visited(irg); irg_walk_core(node, pre, post, env); - ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED); + ir_free_resources(irg, IR_RESOURCE_IRN_VISITED); + current_ir_graph = rem; } /* @@ -186,7 +190,7 @@ void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void current_ir_graph. */ void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) { - int i, n; + size_t i, n; ir_graph *irg; for (i = 0, n = get_irp_n_irgs(); i < n; i++) { @@ -369,37 +373,28 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, } -/* walks only over Block nodes in the graph. Has it's own visited +/* walks only over Block nodes in the graph. Has its own visited flag, so that it can be interleaved with the other walker. */ -void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) +void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, + void *env) { - ir_graph *irg = get_irn_irg(node); - ir_node *block, *pred; - int i; + ir_graph *irg = get_irn_irg(node); + ir_node *block = is_Block(node) ? node : get_nodes_block(node); hook_irg_block_walk(irg, node, (generic_func *)pre, (generic_func *)post); - assert(node); ir_reserve_resources(irg, IR_RESOURCE_BLOCK_VISITED); inc_irg_block_visited(irg); - block = is_Block(node) ? node : get_nodes_block(node); - assert(is_Block(block)); irg_block_walk_2(block, pre, post, env); - /* keepalive: the endless loops ... */ + /* Some blocks might be only reachable through keep-alive edges */ if (is_End(node)) { int arity = get_irn_arity(node); + int i; for (i = 0; i < arity; i++) { - pred = get_irn_n(node, i); - if (!is_Block(pred)) { - pred = get_nodes_block(pred); - if (!is_Block(pred)) { - /* if rare cases a kept node might have a bad block input */ - continue; - } - } - /* Sometimes the blocks died, but are still reachable through kept nodes. - * Make sure the algorithms that try to remove these reach them. */ + ir_node *pred = get_irn_n(node, i); + if (!is_Block(pred)) + continue; irg_block_walk_2(pred, pre, post, env); } } @@ -427,8 +422,10 @@ void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, vo ir_graph * rem = current_ir_graph; current_ir_graph = irg; + ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED); inc_irg_visited(irg); irg_walk_2(irg->anchor, pre, post, env); + ir_free_resources(irg, IR_RESOURCE_IRN_VISITED); current_ir_graph = rem; } @@ -445,7 +442,7 @@ static void walk_initializer(ir_initializer_t *initializer, walk_env *env) { switch (initializer->kind) { case IR_INITIALIZER_CONST: - irg_walk(initializer->consti.value, env->pre, env->post, env->env); + irg_walk(initializer->consti.value, env->pre, env->post, env->env); return; case IR_INITIALIZER_TARVAL: case IR_INITIALIZER_NULL: @@ -474,7 +471,7 @@ static void walk_entity(ir_entity *ent, void *env) if (ent->initializer != NULL) { walk_initializer(ent->initializer, my_env); } else if (entity_has_compound_ent_values(ent)) { - int i, n_vals = get_compound_ent_n_values(ent); + size_t i, n_vals = get_compound_ent_n_values(ent); for (i = 0; i < n_vals; i++) irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->env); @@ -484,9 +481,10 @@ static void walk_entity(ir_entity *ent, void *env) /* Walks over all code in const_code_irg. */ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) { - int i, j, n_types; walk_env my_env; ir_segment_t s; + size_t i; + size_t n_types; ir_graph *rem = current_ir_graph; current_ir_graph = get_const_code_irg(); @@ -497,7 +495,7 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) my_env.env = env; /* Walk all types that can contain constant entities. */ - for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; s++) + for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) walk_types_entities(get_segment_type(s), &walk_entity, &my_env); n_types = get_irp_n_types(); for (i = 0; i < n_types; i++) @@ -509,7 +507,7 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) for (i = 0; i < n_types; i++) { ir_type *tp = get_irp_type(i); if (is_Array_type(tp)) { - int n_dim = get_array_n_dimensions(tp); + size_t j, n_dim = get_array_n_dimensions(tp); for (j = 0; j < n_dim; j++) { ir_node *n = get_array_lower_bound(tp, j); if (n) irg_walk(n, pre, post, env);