+ block = is_Block(node) ? node : get_nodes_block(node);
+ assert(get_irn_op(block) == op_Block);
+ irg_block_walk_2(block, pre, post, env);
+
+ /* keepalive: the endless loops ... */
+ if (get_irn_op(node) == op_End) {
+ int arity = get_irn_arity(node);
+ for (i = 0; i < arity; i++) {
+ pred = get_irn_n(node, i);
+ if (get_irn_op(pred) == op_Block)
+ irg_block_walk_2(pred, pre, post, env);
+ }
+ /* Sometimes the blocks died, but are still reachable through Phis.
+ * Make sure the algorithms that try to remove these reach them. */
+ for (i = 0; i < arity; i++) {
+ pred = get_irn_n(node, i);
+ if (get_irn_op(pred) == op_Phi) {
+ ir_node *block = get_nodes_block(pred);
+
+ if (! is_Bad(block))
+ irg_block_walk_2(block, pre, post, env);
+ }
+ }
+ }
+
+ clear_using_block_visited(current_ir_graph);
+}
+
+/*
+ * walk over a graph block wise
+ */
+void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
+ irg_walk_func *post, void *env) {
+ ir_graph * rem = current_ir_graph;
+ current_ir_graph = irg;
+ irg_block_walk(get_irg_end(irg), pre, post, env);
+ current_ir_graph = rem;
+}
+
+/*
+ * Additionally walk over all anchors. Do NOT increase the visit flag.
+ */
+void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
+ int i;
+ ir_graph * rem = current_ir_graph;
+ current_ir_graph = irg;
+
+ for (i = 0; i < anchor_max; ++i) {
+ ir_node *anchor = irg->anchors[i];
+
+ irg_walk_2(anchor, pre, post, env);
+ }
+ current_ir_graph = rem;
+}
+
+/********************************************************************/
+
+typedef struct walk_env {
+ irg_walk_func *pre;
+ irg_walk_func *post;
+ void *env;
+} walk_env;
+
+/**
+ * Walk to all constant expressions in this entity.
+ */
+static void walk_entity(ir_entity *ent, void *env)
+{
+ walk_env *my_env = (walk_env *)env;
+
+ if (get_entity_variability(ent) != variability_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, 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);
+ }
+ }
+}
+
+/* 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, &my_env);
+ for (i = 0; i < get_irp_n_types(); i++)
+ walk_types_entities(get_irp_type(i), &walk_entity, &my_env);
+ for (i = 0; i < get_irp_n_irgs(); i++)
+ walk_types_entities(get_irg_frame_type(get_irp_irg(i)), &walk_entity, &my_env);
+
+ /* Walk constant array bounds. */
+ for (i = 0; i < get_irp_n_types(); i++) {
+ ir_type *tp = get_irp_type(i);
+ if (is_Array_type(tp)) {
+ for (j = 0; j < get_array_n_dimensions(tp); j++) {
+ ir_node *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;