backend: put ignore regs into beirg
[libfirm] / ir / ir / irgwalk_blk.c
index 8779ad7..3779bec 100644 (file)
  * @author  Michael Beck
  * @version $Id$
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include "irnode_t.h"
-#include "irgraph_t.h" /* visited flag */
+#include "irgraph_t.h"
 #include "irgwalk.h"
 #include "pset.h"
 #include "irhooks.h"
@@ -43,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 */
@@ -53,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,7 +62,8 @@ typedef struct _block_entry_t {
 /**
  * compare two block_entries
  */
-static int addr_cmp(const void *elt, const void *key) {
+static int addr_cmp(const void *elt, const void *key)
+{
        const block_entry_t *e1 = elt;
        const block_entry_t *e2 = key;
 
@@ -84,7 +83,7 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx)
        if (elem)
                return elem;
 
-       elem = obstack_alloc(&ctx->obst, sizeof(*elem));
+       elem = OALLOC(&ctx->obst, block_entry_t);
 
        elem->block      = block;
        elem->phi_list   = NEW_ARR_F(ir_node *, 0);
@@ -98,7 +97,8 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx)
 /**
  * Traverse a block in pre order.
  */
-static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_func *pre, void *env) {
+static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_func *pre, void *env)
+{
        int j;
 
        for (j = ARR_LEN(entry->cf_list) - 1; j >= 0; --j) {
@@ -122,7 +122,9 @@ 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;
 
        post(block, env);
@@ -146,7 +148,8 @@ void traverse_block_post(ir_node *block, block_entry_t *entry, irg_walk_func *po
 /**
  * traverse the pre order only, from End to Start
  */
-static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env) {
+static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env)
+{
        int i;
 
        for (i = ARR_LEN(blks->blk_list) - 1; i >= 0; --i) {
@@ -165,7 +168,8 @@ static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env
 /**
  * traverse the post order only, from Start to End
  */
-static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *env) {
+static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *env)
+{
        int i, k;
 
        for (i = 0, k = ARR_LEN(blks->blk_list); i < k; ++i) {
@@ -202,7 +206,8 @@ static void traverse_both(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk
 /**
  * Do the traversal.
  */
-static void traverse_blocks(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env) {
+static void traverse_blocks(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env)
+{
        if      (!post) traverse_pre (blks, pre, env);
        else if (!pre)  traverse_post(blks, post, env);
        else            traverse_both(blks, pre, post, env);
@@ -216,9 +221,10 @@ typedef struct dom_traversal_t {
 } dom_traversal_t;
 
 /**
- * Dom block pre walker.
+ * Dom block walker. Visit all nodes in pre oder.
  */
-static void pre_block_visit(ir_node *block, void *env) {
+static void dom_block_visit_pre(ir_node *block, void *env)
+{
        dom_traversal_t *ctx   = env;
        block_entry_t   *entry = block_find_entry(block, ctx->blks);
 
@@ -226,9 +232,10 @@ static void pre_block_visit(ir_node *block, void *env) {
 }
 
 /**
- * Dom block post walker.
+ * Dom block walker. Visit all nodes in post oder.
  */
-static void post_block_visit(ir_node *block, void *env) {
+static void dom_block_visit_post(ir_node *block, void *env)
+{
        dom_traversal_t *ctx   = env;
        block_entry_t   *entry = block_find_entry(block, ctx->blks);
 
@@ -236,9 +243,22 @@ static void post_block_visit(ir_node *block, void *env) {
 }
 
 /**
- * Do the traversal in the dominator tree.
+ * Dom block walker. Visit all nodes in pre oder, than in post order.
  */
-static void traverse_dom_blocks(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env) {
+static void dom_block_visit_both(ir_node *block, void *env)
+{
+       dom_traversal_t *ctx   = env;
+       block_entry_t   *entry = block_find_entry(block, ctx->blks);
+
+       traverse_block_pre(block, entry, ctx->pre, ctx->env);
+       traverse_block_post(block, entry, ctx->post, ctx->env);
+}
+
+/**
+ * Do the traversal in the dominator tree in top-down order.
+ */
+static void traverse_dom_blocks_top_down(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env)
+{
        dom_traversal_t ctx;
 
        ctx.blks = blks;
@@ -246,10 +266,12 @@ static void traverse_dom_blocks(blk_collect_data_t* blks, irg_walk_func *pre, ir
        ctx.post = post;
        ctx.env  = env;
 
-       dom_tree_walk_irg(current_ir_graph,
-               pre != NULL ? pre_block_visit : NULL,
-               post != NULL ? post_block_visit : NULL,
-               &ctx);
+       if (pre != NULL && post != NULL)
+               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);
+       else if (post != NULL)
+               dom_tree_walk_irg(current_ir_graph, dom_block_visit_post, NULL, &ctx);
 }
 
 /**
@@ -263,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);
@@ -302,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);
 
                                        /*
@@ -340,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)) {
@@ -390,21 +412,15 @@ static void collect_lists(blk_collect_data_t *env)
 /**
  * Intraprozedural 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,
-                void (*traverse)(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env))
+static void do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre,
+       irg_walk_func *post, void *env, unsigned follow_deps,
+       void (*traverse)(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env))
 {
        ir_node            *end_node = get_irg_end(irg);
        ir_node            *end_blk = get_irg_end_block(irg);
        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);
@@ -431,13 +447,11 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en
        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);
 }
 
-void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
+void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
+{
        ir_graph * rem = current_ir_graph;
 
        hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post);
@@ -446,7 +460,8 @@ void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *po
        current_ir_graph = rem;
 }
 
-void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
+void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
+{
        ir_graph * rem = current_ir_graph;
 
        hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post);
@@ -455,11 +470,12 @@ void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_wal
        current_ir_graph = rem;
 }
 
-void irg_walk_blkwise_dom_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
+void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
+{
        ir_graph * rem = current_ir_graph;
 
        hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post);
        current_ir_graph = irg;
-       do_irg_walk_blk(irg, pre, post, env, 0, traverse_dom_blocks);
+       do_irg_walk_blk(irg, pre, post, env, 0, traverse_dom_blocks_top_down);
        current_ir_graph = rem;
 }