local_optimize() now kills unrteachable code if dominance info is available.
[libfirm] / ir / ir / irgwalk.c
index 66246c0..f879313 100644 (file)
  */
 
 /**
-* traverse an ir graph
-* - execute the pre function before recursion
-* - execute the post function after recursion
-*/
+ * @file irgwalk.c
+ *
+ * traverse an ir graph
+ * - execute the pre function before recursion
+ * - execute the post function after recursion
+ */
 
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
 #endif
 
-#include <stdlib.h>
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
 
 #include "irnode_t.h"
 #include "irgraph_t.h" /* visited flag */
 #include "irprog.h"
 #include "irgwalk.h"
 #include "typewalk.h"
-#include "firmstat.h"
+#include "irhooks.h"
 #include "ircgcons.h"
 
 #include "eset.h"
 #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,
+/**
+ * Walk over an interprocedural graph (callgraph).
+ * Visits only graphs in irg_set.
+ */
+static void irg_walk_cg(ir_node * node, unsigned long visited, eset * irg_set,
                         irg_walk_func *pre, irg_walk_func *post, void * env) {
   int i;
   ir_graph * rem = current_ir_graph;
@@ -105,7 +112,9 @@ static void irg_walk_cg(ir_node * node, int visited, eset * irg_set,
 }
 
 
-/* Insert all ir_graphs in irg_set, that are (transitive) reachable. */
+/**
+ * Insert all ir_graphs in irg_set, that are (transitive) reachable.
+ */
 static void collect_irgs(ir_node * node, eset * irg_set) {
   if (get_irn_op(node) == op_Call) {
     int i;
@@ -210,7 +219,7 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
 
   if (get_interprocedural_view()) {
     eset * irg_set = eset_create();
-    int visited;
+    unsigned long visited;
     ir_graph * irg;
     assert(get_irp_ip_view_state() == ip_view_valid);
 
@@ -231,11 +240,13 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
   return;
 }
 
-
+/*
+ * 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;
 
-  stat_irg_walk(irg, (void *)pre, (void *)post);
+  hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post);
   current_ir_graph = irg;
   irg_walk(get_irg_end(irg), pre, post, env);
   current_ir_graph = rem;
@@ -388,8 +399,8 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p
 {
   int i;
 
-  if(get_Block_block_visited(node) < get_irg_block_visited(current_ir_graph)) {
-    set_Block_block_visited(node, get_irg_block_visited(current_ir_graph));
+  if (Block_not_block_visited(node)) {
+    mark_Block_block_visited(node);
 
     if(pre) pre(node, env);
 
@@ -419,7 +430,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
   ir_node *block, *pred;
   int i;
 
-  stat_irg_block_walk(current_ir_graph, node, (void *)pre, (void *)post);
+  hook_irg_block_walk(current_ir_graph, node, (generic_func *)pre, (generic_func *)post);
 
   assert(node);
   assert(!get_interprocedural_view());   /* interprocedural_view not implemented, because it
@@ -442,9 +453,9 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
     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);
+        ir_node *block = get_nodes_block(pred);
 
-       if (! is_Bad(block))
+        if (! is_Bad(block))
           irg_block_walk_2(block, pre, post, env);
       }
     }
@@ -453,7 +464,9 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
   return;
 }
 
-
+/*
+ * 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;
@@ -470,7 +483,9 @@ typedef struct walk_env {
   void *env;
 } walk_env;
 
-/* Walk to all constant expressions in this entity. */
+/**
+ * Walk to all constant expressions in this entity.
+ */
 static void walk_entity(entity *ent, void *env)
 {
   walk_env *my_env = (walk_env *)env;
@@ -511,13 +526,12 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *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)) {
+    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);
+        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);
       }
     }
   }