* @file
* @brief Functions for traversing ir graphs
* @author Boris Boesler, Goetz Lindenmaier, Michael Beck
- * @version $Id$
* @brief
* traverse an ir graph
* - execute the pre function before recursion
#include "irgwalk.h"
#include "irhooks.h"
#include "entity_t.h"
+#include "ircons.h"
#include "error.h"
#include "pset_new.h"
pre(node, env);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_pre(pred, pre, env);
}
set_irn_visited(node, irg->visited);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_post(pred, post, env);
}
pre(node, env);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_both(pred, pre, post, env);
}
return cnt;
}
-/**
- * Intraprozedural graph walker.
- *
- * @return number of visited nodes
- */
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
current_ir_graph = rem;
}
-/*
- * walk over a graph
- */
void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
current_ir_graph = rem;
}
-/* Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
- Sets current_ir_graph properly for each walk. Conserves current
- current_ir_graph. */
void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env)
{
size_t i, n;
}
}
-/***************************************************************************/
-
/**
* specialized version of irg_walk_in_or_dep_2, called if only pre callback exists
*
pre(node, env);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_pre(pred, pre, env);
}
set_irn_visited(node, irg->visited);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_post(pred, post, env);
}
pre(node, env);
- if (node->op != op_Block) {
- ir_node *pred = get_irn_n(node, -1);
+ if (!is_Block(node)) {
+ ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_both(pred, pre, post, env);
}
else return irg_walk_in_or_dep_2_both(node, pre, post, env);
}
-/*
- * Generic graph walker. Follows dependency edges as well.
- */
void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
assert(is_ir_node(node));
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
-/*
- * Walk over a graph. Follow all edges (including dependencies)
- */
void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
current_ir_graph = rem;
}
-/***************************************************************************/
-
/* Walks back from n until it finds a real cf op. */
static ir_node *get_cf_op(ir_node *n)
{
post(node, env);
}
-
-/* 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)
{
ir_free_resources(irg, IR_RESOURCE_BLOCK_VISITED);
}
-/*
- * walk over a graph block wise
- */
void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
irg_walk_func *post, void *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)
{
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;
}
-/********************************************************************/
-
typedef struct walk_env {
irg_walk_func *pre;
irg_walk_func *post;
if (ent->initializer != NULL) {
walk_initializer(ent->initializer, my_env);
- } else if (entity_has_compound_ent_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);
}
}
-/* Walks over all code in const_code_irg. */
void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env)
{
walk_env my_env;