give Bad nodes a mode
[libfirm] / ir / be / bedomfront.c
index 79aad6e..6736b34 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.
  *
 
 /**
  * @file
- * @brief       Algorithms for computing normal and iterated dominance frontiers.
+ * @brief       Algorithms for computing dominance frontiers.
  * @author      Sebastian Hack, Daniel Grund
  * @date        04.05.2005
  * @version     $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include "obst.h"
 #include "pmap.h"
@@ -42,7 +40,7 @@
 /**
  * The dominance frontier for a graph.
  */
-struct _be_dom_front_info_t {
+struct be_dom_front_info_t {
        pmap *df_map;         /**< A map, mapping every block to a list of its dominance frontier blocks. */
        struct obstack obst;  /**< An obstack holding all the frontier data. */
 };
@@ -55,8 +53,7 @@ struct _be_dom_front_info_t {
  * @param bl The block.
  * @return The immediate dominator of the block.
  */
-static INLINE
-ir_node *get_idom(ir_node *bl)
+static inline ir_node *get_idom(ir_node *bl)
 {
        ir_node *idom = get_Block_idom(bl);
        return idom == NULL ? bl : idom;
@@ -69,14 +66,13 @@ ir_node *get_idom(ir_node *bl)
  *
  * @return the list of all blocks in the dominance frontier of blk
  */
-static
-ir_node **compute_df(ir_node *blk, be_dom_front_info_t *info)
+static ir_node **compute_df(ir_node *blk, be_dom_front_info_t *info)
 {
        ir_node *c;
        const ir_edge_t *edge;
        ir_node **df_list = NEW_ARR_F(ir_node *, 0);
        ir_node **df;
-       int len;
+       size_t len;
 
        /* Add local dominance frontiers */
        foreach_block_succ(blk, edge) {
@@ -93,11 +89,11 @@ ir_node **compute_df(ir_node *blk, be_dom_front_info_t *info)
         * dominated by the given block.
         */
        for (c = get_Block_dominated_first(blk); c; c = get_Block_dominated_next(c)) {
-               int i;
+               size_t i;
                ir_node **df_c_list = compute_df(c, info);
 
-               for (i = ARR_LEN(df_c_list) - 1; i >= 0; --i) {
-                       ir_node *w = df_c_list[i];
+               for (i = ARR_LEN(df_c_list); i > 0;) {
+                       ir_node *w = df_c_list[--i];
                        if (get_idom(w) != blk)
                                ARR_APP1(ir_node *, df_list, w);
                }
@@ -115,7 +111,7 @@ ir_node **compute_df(ir_node *blk, be_dom_front_info_t *info)
 
 be_dom_front_info_t *be_compute_dominance_frontiers(ir_graph *irg)
 {
-       be_dom_front_info_t *info = xmalloc(sizeof(*info));
+       be_dom_front_info_t *info = XMALLOC(be_dom_front_info_t);
 
        edges_assure(irg);
        obstack_init(&info->obst);
@@ -137,38 +133,5 @@ void be_free_dominance_frontiers(be_dom_front_info_t *info)
 ir_node **be_get_dominance_frontier(const be_dom_front_info_t *info,
                                     ir_node *block)
 {
-       return pmap_get(info->df_map, block);
+       return (ir_node**)pmap_get(info->df_map, block);
 }
-
-#if 0
-/**
- * Calculates the iterated dominance frontier of a set of blocks.
- * Also clears the link field of the returned blocks as a side effect
- */
-void be_get_iterated_dominance_frontiers(const be_dom_front_info_t *domfronts,
-                                         ir_nodeset_t *blocks)
-{
-       ir_node *block;
-       ir_nodeset_iterator_t iter;
-       waitq *worklist = new_waitq();
-
-       foreach_ir_nodeset(blocks, block, iter) {
-               waitq_put(worklist, block);
-       }
-
-       while(! waitq_empty(worklist)) {
-               int     i;
-               ir_node *block       = waitq_get(worklist);
-               ir_node **domfront   = be_get_dominance_frontier(domfronts, block);
-               int     domfront_len = ARR_LEN(domfront);
-
-               for (i = 0; i < domfront_len; ++i) {
-                       ir_node *y = domfront[i];
-                       if (ir_nodeset_insert(blocks, y))
-                               waitq_put(worklist, y);
-               }
-       }
-
-       del_waitq(worklist);
-}
-#endif