valueset: Remove the unused link field.
[libfirm] / ir / ir / irgwalk_blk.c
index ca98317..e42c681 100644 (file)
@@ -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.
  *
@@ -21,7 +21,6 @@
  * @file
  * @brief   Blockwise walker implementation
  * @author  Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
@@ -32,6 +31,7 @@
 #include "irhooks.h"
 #include "array.h"
 #include "hashptr.h"
+#include "ircons.h"
 
 #define _get_walk_arity(env, node) \
        ((env)->follow_deps ? get_irn_ins_or_deps((node)) : get_irn_arity((node)))
@@ -41,7 +41,7 @@
 /**
  * Metadata for block walker
  */
-typedef struct _blk_collect_data_t {
+typedef struct blk_collect_data_t {
        struct obstack obst;            /**< obstack to allocate objects on */
        pset           *blk_map;        /**< Hash map: Block -> List */
        ir_node        **blk_list;      /**< the Block list */
@@ -51,7 +51,7 @@ typedef struct _blk_collect_data_t {
 /**
  * An entry for a block in the blk_map
  */
-typedef struct _block_entry_t {
+typedef struct block_entry_t {
        ir_node *block;       /**< the block */
        ir_node **phi_list;   /**< the list of Phi instruction */
        ir_node **df_list;    /**< the list of data flow instruction */
@@ -64,8 +64,8 @@ typedef struct _block_entry_t {
  */
 static int addr_cmp(const void *elt, const void *key)
 {
-       const block_entry_t *e1 = elt;
-       const block_entry_t *e2 = key;
+       const block_entry_t *e1 = (const block_entry_t*)elt;
+       const block_entry_t *e2 = (const block_entry_t*)key;
 
        return e1->block != e2->block;
 }
@@ -79,7 +79,7 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx)
        block_entry_t *elem;
 
        key.block = block;
-       elem = pset_find(ctx->blk_map, &key, HASH_PTR(block));
+       elem = (block_entry_t*)pset_find(ctx->blk_map, &key, hash_ptr(block));
        if (elem)
                return elem;
 
@@ -91,7 +91,7 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx)
        elem->cf_list    = NEW_ARR_F(ir_node *, 0);
        elem->entry_list = NEW_ARR_F(ir_node *, 0);
 
-       return pset_insert(ctx->blk_map, elem, HASH_PTR(block));
+       return (block_entry_t*)pset_insert(ctx->blk_map, elem, hash_ptr(block));
 }
 
 /**
@@ -99,20 +99,20 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx)
  */
 static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_func *pre, void *env)
 {
-       int j;
+       size_t j;
 
-       for (j = ARR_LEN(entry->cf_list) - 1; j >= 0; --j) {
-               ir_node *node = entry->cf_list[j];
+       for (j = ARR_LEN(entry->cf_list); j > 0;) {
+               ir_node *node = entry->cf_list[--j];
                pre(node, env);
        }
 
-       for (j = ARR_LEN(entry->df_list) - 1; j >= 0; --j) {
-               ir_node *node = entry->df_list[j];
+       for (j = ARR_LEN(entry->df_list); j > 0;) {
+               ir_node *node = entry->df_list[--j];
                pre(node, env);
        }
 
-       for (j = ARR_LEN(entry->phi_list) - 1; j >= 0; --j) {
-               ir_node *node = entry->phi_list[j];
+       for (j = ARR_LEN(entry->phi_list); j > 0;) {
+               ir_node *node = entry->phi_list[--j];
                pre(node, env);
        }
 
@@ -122,9 +122,10 @@ static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_fu
 /**
  * Traverse a block in post order.
  */
-void traverse_block_post(ir_node *block, block_entry_t *entry, irg_walk_func *post, void *env)
+static void traverse_block_post(ir_node *block, block_entry_t *entry,
+                                irg_walk_func *post, void *env)
 {
-       int j, n;
+       size_t j, n;
 
        post(block, env);
 
@@ -149,10 +150,10 @@ void traverse_block_post(ir_node *block, block_entry_t *entry, irg_walk_func *po
  */
 static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env)
 {
-       int i;
+       size_t i;
 
-       for (i = ARR_LEN(blks->blk_list) - 1; i >= 0; --i) {
-               ir_node       *block = blks->blk_list[i];
+       for (i = ARR_LEN(blks->blk_list); i > 0;) {
+               ir_node       *block = blks->blk_list[--i];
                block_entry_t *entry = block_find_entry(block, blks);
 
                traverse_block_pre(block, entry, pre, env);
@@ -169,7 +170,7 @@ static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env
  */
 static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *env)
 {
-       int i, k;
+       size_t i, k;
 
        for (i = 0, k = ARR_LEN(blks->blk_list); i < k; ++i) {
                ir_node       *block = blks->blk_list[i];
@@ -189,10 +190,10 @@ static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *e
  */
 static void traverse_both(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env)
 {
-       int i;
+       size_t i;
 
-       for (i = ARR_LEN(blks->blk_list) - 1; i >= 0; --i) {
-               ir_node       *block = blks->blk_list[i];
+       for (i = ARR_LEN(blks->blk_list); i > 0;) {
+               ir_node       *block = blks->blk_list[--i];
                block_entry_t *entry = block_find_entry(block, blks);
 
                traverse_block_pre(block, entry, pre, env);
@@ -224,7 +225,7 @@ typedef struct dom_traversal_t {
  */
 static void dom_block_visit_pre(ir_node *block, void *env)
 {
-       dom_traversal_t *ctx   = env;
+       dom_traversal_t *ctx   = (dom_traversal_t*)env;
        block_entry_t   *entry = block_find_entry(block, ctx->blks);
 
        traverse_block_pre(block, entry, ctx->pre, ctx->env);
@@ -235,7 +236,7 @@ static void dom_block_visit_pre(ir_node *block, void *env)
  */
 static void dom_block_visit_post(ir_node *block, void *env)
 {
-       dom_traversal_t *ctx   = env;
+       dom_traversal_t *ctx   = (dom_traversal_t*)env;
        block_entry_t   *entry = block_find_entry(block, ctx->blks);
 
        traverse_block_post(block, entry, ctx->post, ctx->env);
@@ -246,7 +247,7 @@ static void dom_block_visit_post(ir_node *block, void *env)
  */
 static void dom_block_visit_both(ir_node *block, void *env)
 {
-       dom_traversal_t *ctx   = env;
+       dom_traversal_t *ctx   = (dom_traversal_t*)env;
        block_entry_t   *entry = block_find_entry(block, ctx->blks);
 
        traverse_block_pre(block, entry, ctx->pre, ctx->env);
@@ -266,11 +267,11 @@ static void traverse_dom_blocks_top_down(blk_collect_data_t* blks, irg_walk_func
        ctx.env  = env;
 
        if (pre != NULL && post != NULL)
-               dom_tree_walk_irg(current_ir_graph,     dom_block_visit_both, NULL, &ctx);
+               dom_tree_walk_irg(current_ir_graph, dom_block_visit_both, NULL, &ctx);
        else if (pre != NULL)
-               dom_tree_walk_irg(current_ir_graph,     dom_block_visit_pre, NULL, &ctx);
+               dom_tree_walk_irg(current_ir_graph, dom_block_visit_pre, NULL, &ctx);
        else if (post != NULL)
-               dom_tree_walk_irg(current_ir_graph,     dom_block_visit_post, NULL, &ctx);
+               dom_tree_walk_irg(current_ir_graph, dom_block_visit_post, NULL, &ctx);
 }
 
 /**
@@ -284,7 +285,7 @@ static void collect_walk(ir_node *node, blk_collect_data_t *env)
 
        mark_irn_visited(node);
 
-       if (node->op == op_Block) {
+       if (is_Block(node)) {
                /* predecessors of a block are control flow nodes */
                for (i = _get_walk_arity(env, node) - 1; i >= 0; --i) {
                        ir_node *pred = _get_walk_irn_n(env, node, i);
@@ -323,7 +324,7 @@ static void collect_walk(ir_node *node, blk_collect_data_t *env)
                                collect_walk(pred, env);
 
                                /* BEWARE: predecessors of End nodes might be blocks */
-                               if (is_no_Block(pred)) {
+                               if (!is_Block(pred)) {
                                        ir_node *blk  = get_nodes_block(pred);
 
                                        /*
@@ -361,7 +362,7 @@ static void collect_blks_lists(ir_node *node, ir_node *block,
                        ir_node *pred = _get_walk_irn_n(env, node, i);
 
                        /* BEWARE: predecessors of End nodes might be blocks */
-                       if (is_no_Block(pred)) {
+                       if (!is_Block(pred)) {
                                ir_node *blk  = get_nodes_block(pred);
 
                                if (!irn_visited(pred)) {
@@ -388,18 +389,18 @@ static void collect_blks_lists(ir_node *node, ir_node *block,
  */
 static void collect_lists(blk_collect_data_t *env)
 {
-       int             i, j;
+       size_t          i, j;
        ir_node         *block, *node;
        block_entry_t   *entry;
 
        inc_irg_visited(current_ir_graph);
 
-       for (i = ARR_LEN(env->blk_list) - 1; i >= 0; --i) {
-               block = env->blk_list[i];
+       for (i = ARR_LEN(env->blk_list); i > 0;) {
+               block = env->blk_list[--i];
                entry = block_find_entry(block, env);
 
-               for (j = ARR_LEN(entry->entry_list) - 1; j >= 0; --j) {
-                       node = entry->entry_list[j];
+               for (j = ARR_LEN(entry->entry_list); j > 0;) {
+                       node = entry->entry_list[--j];
 
                        /* a entry might already be visited due to Phi loops */
                        if (node->visited < current_ir_graph->visited)
@@ -409,7 +410,7 @@ static void collect_lists(blk_collect_data_t *env)
 }
 
 /**
- * Intraprozedural graph walker over blocks.
+ * Intra procedural graph walker over blocks.
  */
 static void do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre,
        irg_walk_func *post, void *env, unsigned follow_deps,
@@ -420,12 +421,6 @@ static void do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre,
        blk_collect_data_t blks;
        block_entry_t      *entry;
 
-#ifdef INTERPROCEDURAL_VIEW
-       /* switch off interprocedural view */
-       int old_view       = get_interprocedural_view();
-       set_interprocedural_view(0);
-#endif
-
        obstack_init(&blks.obst);
        blks.blk_map     = new_pset(addr_cmp, 1);
        blks.blk_list    = NEW_ARR_F(ir_node *, 0);
@@ -452,9 +447,6 @@ static void do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre,
        del_pset(blks.blk_map);
        obstack_free(&blks.obst, NULL);
 
-#ifdef INTERPROCEDURAL_VIEW
-       set_interprocedural_view(old_view);
-#endif
        ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
 }