changed code placement so it can work in more environments:
[libfirm] / ir / ana / irdom.c
index 930078e..8ad7a94 100644 (file)
@@ -27,8 +27,8 @@
 #include "irnode_t.h"
 #include "ircons_t.h"
 
-#define get_dom_info(bl) (&(bl)->attr.block.dom)
 
+#define get_dom_info(bl) (&(bl)->attr.block.dom)
 
 /*--------------------------------------------------------------------*/
 /** Accessing the dominator data structures                          **/
@@ -99,11 +99,14 @@ int block_dominates(const ir_node *a, const ir_node *b)
 {
        const dom_info *ai, *bi;
 
-       assert(is_Block(a) && is_Block(b));
-       ai = get_dom_info(a);
-       bi = get_dom_info(b);
-       return bi->tree_pre_num - ai->tree_pre_num
-               <= ai->max_subtree_pre_num - ai->tree_pre_num;
+       if (is_Block(a) && is_Block(b)) {
+               ai = get_dom_info(a);
+               bi = get_dom_info(b);
+               return bi->tree_pre_num - ai->tree_pre_num
+                       <= ai->max_subtree_pre_num - ai->tree_pre_num;
+       }
+
+       return 0;
 }
 
 ir_node *get_Block_dominated_first(const ir_node *bl)
@@ -152,6 +155,7 @@ static void assign_tree_pre_order(ir_node *bl, void *data)
 {
        unsigned *num = data;
        dom_info *bi = get_dom_info(bl);
+
        bi->tree_pre_num = (*num)++;
 }
 
@@ -160,13 +164,16 @@ static void assign_tree_pre_order_max(ir_node *bl, void *data)
        dom_info *bi = get_dom_info(bl);
        ir_node *p;
        unsigned max = 0;
+       unsigned children = 0;
 
        for(p = bi->first; p; p = get_dom_info(p)->next) {
                unsigned max_p = get_dom_info(p)->max_subtree_pre_num;
                max = max > max_p ? max : max_p;
+               children++;
        }
 
-       bi->max_subtree_pre_num = max;
+       bi->max_subtree_pre_num = children > 0 ? max : bi->tree_pre_num;
+       assert(bi->max_subtree_pre_num >= bi->tree_pre_num);
 }
 
 /*--------------------------------------------------------------------*/