forbid to set current_block to Bad
[libfirm] / ir / ana / irextbb2.c
index 602e393..94c38f2 100644 (file)
@@ -22,7 +22,6 @@
  * @brief     Alternative extended basic block computation
  * @author    Matthias Braun
  * @date      5.2005
- * @version   $Id$
  * @brief
  *  Alternative algorithm for computing extended basic blocks (using out edges
  *  and execution frequencies)
@@ -39,8 +38,8 @@
 #include "irprintf.h"
 #include "execfreq.h"
 
-typedef struct _env {
-       struct obstack *obst;   /**< the obstack where allocations took place */
+typedef struct env {
+       struct obstack *obst;   /**< the obstack where allocations took place */
        ir_extblk *head;        /**< head of the list of all extended blocks */
        ir_exec_freq *execfreqs;
 } env_t;
@@ -82,7 +81,8 @@ static void addto_extblk(ir_extblk *extblk, ir_node *block)
  * Returns the number of block successors.
  * we are interested only in 1, 2 and >2.
  */
-static int get_block_n_succs(ir_node *block) {
+static int get_block_n_succs(ir_node *block)
+{
        if (edges_activated(current_ir_graph)) {
                const ir_edge_t *edge;
 
@@ -121,14 +121,12 @@ static void pick_successor(ir_node *block, ir_extblk *extblk, env_t *env)
        ir_node         *best_succ    = NULL;
        double          best_execfreq = -1;
 
-       /*
+       /*
                More than two successors means we have a jump table.
                we cannot include a jump target into the current extended
                basic block, so create a new one here.
        */
        if (get_block_n_succs(block) > 2) {
-               const ir_edge_t *edge;
-
                foreach_block_succ(block, edge) {
                        ir_node *succ = get_edge_src_irn(edge);
                        create_extblk(succ, env);
@@ -141,10 +139,10 @@ static void pick_successor(ir_node *block, ir_extblk *extblk, env_t *env)
                ir_node *succ = get_edge_src_irn(edge);
                double execfreq;
 
-               if(irn_visited(succ))
+               if (irn_visited(succ))
                        continue;
 
-               if(get_Block_n_cfgpreds(succ) > 1) {
+               if (get_Block_n_cfgpreds(succ) > 1) {
                        create_extblk(succ, env);
                        continue;
                }
@@ -169,18 +167,16 @@ static void pick_successor(ir_node *block, ir_extblk *extblk, env_t *env)
        }
 
        /* add best successor and recursively try to pick more */
-       if(best_succ != NULL) {
+       if (best_succ != NULL) {
                addto_extblk(extblk, best_succ);
                mark_irn_visited(best_succ);
                pick_successor(best_succ, extblk, env);
        }
 }
 
-/*
- * Compute the extended basic blocks for a graph
- */
-void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs) {
-       env_t     env;
+void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs)
+{
+       env_t     env;
        ir_extblk *extbb, *next;
        ir_node   *endblock;
 
@@ -221,8 +217,8 @@ void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs) {
 
                extbb->blks = NEW_ARR_D(ir_node *, env.obst, len);
 
-               for (block = extbb->link, i = 0; i < len; ++i) {
-                       ir_node *nblock = get_irn_link(block);
+               for (block = (ir_node*) extbb->link, i = 0; i < len; ++i) {
+                       ir_node *nblock = (ir_node*) get_irn_link(block);
 
                        /* ensure that the leader is the first one */
                        extbb->blks[len - 1 - i] = block;
@@ -231,8 +227,8 @@ void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs) {
                }
 
 #if 0
-               for(i = 0; i < len; ++i) {
-                       if(i > 0)
+               for (i = 0; i < len; ++i) {
+                       if (i > 0)
                                printf(", ");
                        ir_printf("%+F", extbb->blks[i]);
                }
@@ -243,5 +239,5 @@ void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs) {
                extbb->visited = 0;
        }
 
-       irg->extblk_state = extblk_valid;
+       set_irg_state(irg, IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS);
 }