tv: Remove mul_table[][][] and simply use * and <<.
[libfirm] / ir / ana / irscc.c
index 0da5fd6..9658313 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.
  *
@@ -25,7 +25,6 @@
  *              Chapter 5.2.1.2.
  * @author   Goetz Lindenmaier
  * @date     7.2002
- * @version  $Id$
  */
 #include "config.h"
 
@@ -41,6 +40,7 @@
 #include "irdump.h"
 #include "array.h"
 #include "pmap.h"
+#include "ircons.h"
 
 /* A variant of the loop tree that avoids loops without head.
    This reduces the depth of the loop tree. */
@@ -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);
@@ -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;
 
@@ -315,7 +318,7 @@ static inline void pop_scc_unmark_visit(ir_node *n)
 static ir_loop *new_loop(void)
 {
        ir_loop *father = current_loop;
-       ir_loop *son    = alloc_loop(father, outermost_ir_graph->obst);
+       ir_loop *son    = alloc_loop(father, get_irg_obstack(outermost_ir_graph));
 
        if (son->depth > max_loop_depth) max_loop_depth = son->depth;
        current_loop = son;
@@ -357,7 +360,7 @@ static inline void finish_scc(void)
 }
 
 /**
- * Check weather a given node represents the outer most Start
+ * Check whether a given node represents the outermost Start
  * block. In intra-procedural view this is the start block of the
  * current graph, in interprocedural view it is the start block
  * of the outer most graph.
@@ -390,8 +393,8 @@ static inline int get_start_index(ir_node *n)
           means not reachable.
           I.e., with this code, the order on the loop tree is correct. But a
           (single) test showed the loop tree is deeper. */
-       if (get_irn_op(n) == op_Phi  ||
-           is_Block(n)              ||
+       if (is_Phi(n)   ||
+           is_Block(n) ||
            (get_irg_pinned(get_irn_irg(n)) == op_pin_state_floats &&
              get_irn_pinned(n)              == op_pin_state_floats))
                // Here we could test for backedge at -1 which is illegal
@@ -422,9 +425,7 @@ static inline int get_start_index(ir_node *n)
  */
 static inline int is_possible_loop_head(ir_node *n)
 {
-       ir_op *op = get_irn_op(n);
-       return ((op == op_Block) ||
-               (op == op_Phi));
+       return is_Block(n) || is_Phi(n);
 }
 
 /**
@@ -606,7 +607,9 @@ static ir_node *find_tail(ir_node *n)
                                                res_index = largest_dfn_pred (m);
                                        break;
                                }
-                               if (m == n) { break; }  /* It's not an unreachable loop, either. */
+                               /* It's not an unreachable loop, either. */
+                               if (m == n)
+                                       break;
                        }
                        //assert(0 && "no head found on stack");
                }
@@ -616,8 +619,10 @@ static ir_node *find_tail(ir_node *n)
                /* It's a completely bad loop: without Phi/Block nodes that can
                   be a head. I.e., the code is "dying".  We break the loop by
                   setting Bad nodes. */
-               int arity = get_irn_arity(n);
-               ir_node *bad = get_irg_bad(get_irn_irg(n));
+               ir_graph *irg   = get_irn_irg(n);
+               ir_mode  *mode  = get_irn_mode(n);
+               ir_node  *bad   = new_r_Bad(irg, mode);
+               int       arity = get_irn_arity(n);
                for (i = -1; i < arity; ++i) {
                        set_irn_n(n, i, bad);
                }
@@ -742,8 +747,6 @@ static void scc(ir_node *n)
        }
 }
 
-/* Constructs backedge information for irg. In interprocedural view constructs
-   backedges for all methods called by irg, too. */
 int construct_backedges(ir_graph *irg)
 {
        ir_graph *rem = current_ir_graph;
@@ -769,9 +772,9 @@ int construct_backedges(ir_graph *irg)
        obstack_free(&temp, NULL);
 
        assert(head_rem == current_loop);
-       mature_loops(current_loop, irg->obst);
+       mature_loops(current_loop, get_irg_obstack(irg));
        set_irg_loop(irg, current_loop);
-       set_irg_loopinfo_state(irg, loopinfo_consistent);
+       add_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
        assert(get_irg_loop(irg)->kind == k_ir_loop);
        current_ir_graph = rem;
        return max_loop_depth;
@@ -804,8 +807,6 @@ static void loop_reset_node(ir_node *n, void *env)
        reset_backedges(n);
 }
 
-/** Removes all loop information.
-    Resets all backedges */
 void free_loop_information(ir_graph *irg)
 {
        /* We can not use this recursion, as the loop might contain
@@ -815,13 +816,13 @@ void free_loop_information(ir_graph *irg)
        */
        irg_walk_graph(irg, loop_reset_node, NULL, NULL);
        set_irg_loop(irg, NULL);
-       set_irg_loopinfo_state(current_ir_graph, loopinfo_none);
+       clear_irg_properties(current_ir_graph, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
        /* We cannot free the loop nodes, they are on the obstack. */
 }
 
 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));
        }
@@ -833,7 +834,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;
 
@@ -848,14 +849,6 @@ static int is_loop_variant(ir_loop *l, ir_loop *b)
        return 0;
 }
 
-/* Test whether a value is loop invariant.
- *
- * @param n      The node to be tested.
- * @param block  A block node.  We pass the block, not the loop as we must
- *               start off with a block loop to find all proper uses.
- *
- * Returns non-zero, if the node n is not changed in the loop block
- * belongs to or in inner loops of this blocks loop. */
 int is_loop_invariant(const ir_node *n, const ir_node *block)
 {
        ir_loop *l = get_irn_loop(block);