simplify Sel lowering code
[libfirm] / ir / ana / irscc.c
index 86bd927..13c1d7c 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.
  *
@@ -58,7 +58,7 @@ static int loop_node_cnt = 0;
 /** Counter to generate depth first numbering of visited nodes. */
 static int current_dfn = 1;
 
-static int max_loop_depth = 0;
+static unsigned max_loop_depth = 0;
 
 void link_to_reg_end(ir_node *n, void *env);
 void set_projx_link(ir_node *cb_projx, ir_node *end_projx);
@@ -97,7 +97,7 @@ static inline scc_info *new_scc_info(struct obstack *obst)
  */
 static inline void mark_irn_in_stack(ir_node *n)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        scc->in_stack = 1;
 }
@@ -107,7 +107,7 @@ static inline void mark_irn_in_stack(ir_node *n)
 */
 static inline void mark_irn_not_in_stack(ir_node *n)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        scc->in_stack = 0;
 }
@@ -117,7 +117,7 @@ static inline void mark_irn_not_in_stack(ir_node *n)
  */
 static inline int irn_is_in_stack(ir_node *n)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        return scc->in_stack;
 }
@@ -127,7 +127,7 @@ static inline int irn_is_in_stack(ir_node *n)
  */
 static inline void set_irn_uplink(ir_node *n, int uplink)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        scc->uplink = uplink;
 }
@@ -137,7 +137,7 @@ static inline void set_irn_uplink(ir_node *n, int uplink)
  */
 static int get_irn_uplink(ir_node *n)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        return scc->uplink;
 }
@@ -147,7 +147,7 @@ static int get_irn_uplink(ir_node *n)
  */
 static inline void set_irn_dfn(ir_node *n, int dfn)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        scc->dfn = dfn;
 }
@@ -157,7 +157,7 @@ static inline void set_irn_dfn(ir_node *n, int dfn)
  */
 static int get_irn_dfn(ir_node *n)
 {
-       scc_info *scc = get_irn_link(n);
+       scc_info *scc = (scc_info*) get_irn_link(n);
        assert(scc);
        return scc->dfn;
 }
@@ -197,7 +197,7 @@ ir_loop * get_irn_loop(ir_node *n)
 /**********************************************************************/
 
 static ir_node **stack = NULL;
-static int tos = 0;                /* top of stack */
+static size_t tos = 0;                /* top of stack */
 
 /**
  * initializes the stack
@@ -229,10 +229,10 @@ static void finish_stack(void)
 static inline void push(ir_node *n)
 {
        if (tos == ARR_LEN(stack)) {
-               int nlen = ARR_LEN(stack) * 2;
+               size_t nlen = ARR_LEN(stack) * 2;
                ARR_RESIZE(ir_node *, stack, nlen);
        }
-       stack [tos++] = n;
+       stack[tos++] = n;
        mark_irn_in_stack(n);
 }
 
@@ -243,7 +243,10 @@ static inline void push(ir_node *n)
  */
 static inline ir_node *pop(void)
 {
-       ir_node *n = stack[--tos];
+       ir_node *n;
+
+       assert(tos > 0);
+       n = stack[--tos];
        mark_irn_not_in_stack(n);
        return n;
 }
@@ -271,7 +274,7 @@ static inline void pop_scc_to_loop(ir_node *n)
    can't they have two loops as sons? Does it never get that far? ) */
 static void close_loop(ir_loop *l)
 {
-       int last = get_loop_n_elements(l) - 1;
+       size_t last = get_loop_n_elements(l) - 1;
        loop_element lelement = get_loop_element(l, last);
        ir_loop *last_son = lelement.son;
 
@@ -330,7 +333,7 @@ static ir_loop *new_loop(void)
 
 static inline void init_node(ir_node *n, void *env)
 {
-       struct obstack *obst = env;
+       struct obstack *obst = (struct obstack*) env;
        set_irn_link(n, new_scc_info(obst));
        clear_backedges(n);
 }
@@ -416,7 +419,7 @@ static inline int get_start_index(ir_node *n)
 
 /**
  * Return non-zero if the given node is a legal loop header:
- * Block, Phi, Filter.
+ * Block, Phi
  *
  * @param n  the node to check
  */
@@ -428,9 +431,8 @@ static inline int is_possible_loop_head(ir_node *n)
 }
 
 /**
- * Returns non-zero if n is a loop header, i.e., it is a Block, Phi
- * or Filter node and has predecessors within the loop and out
- * of the loop.
+ * Returns non-zero if n is a loop header, i.e., it is a Block or Phi
+ * node and has predecessors within the loop and out of the loop.
  *
  * @param n    the node to check
  * @param root only needed for assertion.
@@ -469,7 +471,7 @@ static int is_head(ir_node *n, ir_node *root)
 
 /**
  * Returns non-zero if n is possible loop head of an endless loop.
- * I.e., it is a Block, Phi or Filter node and has only predecessors
+ * I.e., it is a Block or Phi node and has only predecessors
  * within the loop.
  *
  * @param n    the node to check
@@ -630,86 +632,11 @@ static ir_node *find_tail(ir_node *n)
        return is_outermost_Start(n) ? NULL : get_irn_n(m, res_index);
 }
 
-
-#if EXPERIMENTAL_LOOP_TREE
-
-/*  ----------------------------------------------------------------
-    AS:  This is experimental code to build loop trees suitable for
-    the heap analysis. Does not work correctly right now... :-(
-
-
-    Search in stack for the corresponding first Call-End-ProjX that
-    corresponds to one of the control flow predecessors of the given
-    block, that is the possible callers.
-    returns: the control predecessor to chose\
-    or       -1 if no corresponding Call-End-Node could be found
-             on the stack.
-    - -------------------------------------------------------------- */
-
-int search_endproj_in_stack(ir_node *start_block)
-{
-       int i, j;
-       assert(is_Block(start_block));
-       for (i = tos - 1; i >= 0; --i)
-       {
-               if (get_irn_op(stack[i]) == op_Proj && get_irn_mode(stack[i]) == mode_X &&
-                       get_irn_op(get_irn_n(stack[i], 0)) == op_EndReg)
-               {
-                       printf("FOUND PROJ!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
-                       ir_node *end_projx = stack[i];
-
-                       int arity = get_irn_arity(start_block);
-                       for (j = 0; j < arity; j++)
-                       {
-                               ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)),
-                                       get_Proj_proj(end_projx));
-                               if (get_irn_n(start_block, j) == begin_projx)
-                               {
-                                       printf("FOUND IT!!!!!!!!!!!!!!!!!!\n");
-                                       return(j);
-                               }
-                       }
-               }
-       }
-       return(-1);
-}
-
-
-static pmap *projx_link = NULL;
-
-void link_to_reg_end (ir_node *n, void *env)
-{
-       if (get_irn_op(n) == op_Proj &&
-               get_irn_mode(n) == mode_X &&
-               get_irn_op(get_irn_n(n, 0)) == op_EndReg) {
-                       /* Reg End Projx -> Find the CallBegin Projx and hash it */
-                       ir_node *end_projx = n;
-                       ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)),
-                               get_Proj_proj(end_projx));
-                       set_projx_link(begin_projx, end_projx);
-       }
-}
-
-void set_projx_link(ir_node *cb_projx, ir_node *end_projx)
-{
-       if (projx_link == NULL)
-               projx_link = pmap_create();
-       pmap_insert(projx_link, (void *)cb_projx, (void *)end_projx);
-}
-
-ir_node *get_projx_link(ir_node *cb_projx)
-{
-       return((ir_node *) pmap_get(projx_link, (void *)cb_projx));
-}
-
-#endif
-
 static inline int is_outermost_loop(ir_loop *l)
 {
        return l == get_loop_outer_loop(l);
 }
 
-
 /*-----------------------------------------------------------*
  *                   The core algorithm.                     *
  *-----------------------------------------------------------*/
@@ -897,7 +824,7 @@ void free_loop_information(ir_graph *irg)
 
 void free_all_loop_information(void)
 {
-       int i;
+       size_t i;
        for (i = 0; i < get_irp_n_irgs(); i++) {
                free_loop_information(get_irp_irg(i));
        }
@@ -909,7 +836,7 @@ void free_all_loop_information(void)
 
 static int is_loop_variant(ir_loop *l, ir_loop *b)
 {
-       int i, n_elems;
+       size_t i, n_elems;
 
        if (l == b) return 1;