From 5470b27c201e3fd91f5af86753dd55806277edcb Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Mon, 2 Sep 2002 15:23:00 +0000 Subject: [PATCH] Added walker for const code [r465] --- ir/ir/irgwalk.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- ir/ir/irgwalk.h | 4 ++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 1bbe1b209..8b84a24a3 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -25,7 +25,8 @@ # include "array.h" /* walk over an interprocedural graph (callgraph). Visits only graphs in irg_set. */ -static void irg_walk_cg(ir_node * node, int visited, eset * irg_set, irg_walk_func pre, irg_walk_func post, void * env) { +static void irg_walk_cg(ir_node * node, int visited, eset * irg_set, + irg_walk_func pre, irg_walk_func post, void * env) { int i; ir_graph * rem = current_ir_graph; ir_node * pred; @@ -279,7 +280,65 @@ void irg_block_walk_graph(ir_graph *irg, irg_walk_func pre, irg_walk_func post, current_ir_graph = rem; } +/********************************************************************/ + +typedef struct walk_env { + void *pre; + void *post; + void *env; +} walk_env; + +/* Walk to all constant expressions in this entity. */ +void walk_entity(entity *ent, void *env) { + walk_env *my_env = (walk_env *)env; + if (get_entity_variability(ent) != uninitialized) { + if (is_atomic_entity(ent)) { + irg_walk(get_atomic_ent_value(ent), my_env->pre, my_env->post, my_env->env); + } else { + int i; + for (i = 0; i < get_compound_ent_n_values(ent); i++) { + irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->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; + walk_env my_env; + + ir_graph *rem = current_ir_graph; + current_ir_graph = get_const_code_irg(); + inc_irg_visited(current_ir_graph); + my_env.pre = pre; + my_env.post = post; + my_env.env = env; + + /* Walk all types that can contain constant entities. */ + walk_types_entities(get_glob_type(), &walk_entity, &env); + for (i = 0; i < get_irp_n_types(); i++) + walk_types_entities(get_irp_type(i), &walk_entity, &env); + for (i = 0; i < get_irp_n_irgs(); i++) + walk_types_entities(get_irg_frame_type(get_irp_irg(i)), &walk_entity, &env); + + /* Walk constant array bounds. */ + for (i = 0; i < get_irp_n_types(); i++) { + type *tp = get_irp_type(i); + if (is_array_type(tp)) { + for (j = 0; j < get_array_n_dimensions(tp); j++) { + ir_node *n; + n = get_array_lower_bound(tp, j); + if (n) irg_walk(n, pre, post, env); + n = get_array_upper_bound(tp, j); + if (n) irg_walk(n, pre, post, env); + } + } + } + + current_ir_graph = rem; +} /********************************************************************/ /** Walking support for interprocedural analysis **/ diff --git a/ir/ir/irgwalk.h b/ir/ir/irgwalk.h index 7b5458664..3d217fa12 100644 --- a/ir/ir/irgwalk.h +++ b/ir/ir/irgwalk.h @@ -51,6 +51,10 @@ void irg_block_walk(ir_node *node, irg_walk_func pre, irg_walk_func post, void * * ir graph, starting at the end block. */ void irg_block_walk_graph(ir_graph *irg, irg_walk_func pre, irg_walk_func post, void *env); +/* Walks over all code in const_code_irg. + Uses visited flag in const_code_irg. */ +void walk_const_code(irg_walk_func pre, irg_walk_func post, void *env); + /********************************************************************/ /** Walking support for interprocedural analysis **/ /** **/ -- 2.20.1