- allow_ifconv interface was totally braindamaged. Use a simple and intuitive
[libfirm] / ir / opt / opt_blocks.c
index 78ff88d..4ecf135 100644 (file)
@@ -37,6 +37,7 @@
 #include "trouts.h"
 #include "irgwalk.h"
 #include "set.h"
+#include "irpass.h"
 #include "debug.h"
 
 /* define this for general block shaping: congruent blocks
@@ -110,7 +111,7 @@ struct environment_t {
        struct obstack  obst;           /** obstack for temporary data */
 };
 
-/** A node, input index pair. */
+/** A (node, input index) pair. */
 struct pair_t {
        pair_t  *next;    /**< Points to the next pair entry. */
        ir_node *irn;     /**< The IR-node. */
@@ -272,11 +273,11 @@ static int cmp_opcode(const void *elt, const void *key, size_t size) {
  * Creates a new empty partition and put in on the
  * partitions list.
  *
- * @param meet_block  the control flow meet block of thi partition
+ * @param meet_block  the control flow meet block of this partition
  * @param env         the environment
  */
 static partition_t *create_partition(ir_node *meet_block, environment_t *env) {
-       partition_t *part = obstack_alloc(&env->obst, sizeof(*part));
+       partition_t *part = OALLOC(&env->obst, partition_t);
 
        INIT_LIST_HEAD(&part->blocks);
        part->meet_block = meet_block;
@@ -295,7 +296,7 @@ static partition_t *create_partition(ir_node *meet_block, environment_t *env) {
  * @param env        the environment
  */
 static block_t *create_block(ir_node *block, int meet_input, partition_t *partition, environment_t *env) {
-       block_t *bl = obstack_alloc(&env->obst, sizeof(*bl));
+       block_t *bl = OALLOC(&env->obst, block_t);
 
        set_irn_link(block, bl);
 
@@ -327,7 +328,7 @@ static block_t *create_block(ir_node *block, int meet_input, partition_t *partit
  * @param env    the environment
  */
 static node_t *create_node(ir_node *irn, block_t *block, environment_t *env) {
-       node_t *node = obstack_alloc(&env->obst, sizeof(*node));
+       node_t *node = OALLOC(&env->obst, node_t);
 
        node->node     = irn;
        node->is_input = 0;
@@ -346,7 +347,7 @@ static node_t *create_node(ir_node *irn, block_t *block, environment_t *env) {
  * @param env    the environment
  */
 static void add_pair(block_t *block, ir_node *irn, int idx, environment_t *env) {
-       pair_t *pair = obstack_alloc(&env->obst, sizeof(*pair));
+       pair_t *pair = OALLOC(&env->obst, pair_t);
 
        pair->next  = block->input_pairs;
        pair->irn   = irn;
@@ -364,7 +365,7 @@ static void add_pair(block_t *block, ir_node *irn, int idx, environment_t *env)
  * @param env    the environment
  */
 static void add_phi(block_t *block, ir_node *phi, environment_t *env) {
-       phi_t *node = obstack_alloc(&env->obst, sizeof(*node));
+       phi_t *node = OALLOC(&env->obst, phi_t);
 
        node->next = block->phis;
        node->phi  = phi;
@@ -485,7 +486,7 @@ static int is_input_node(ir_node *pred, ir_node *irn, int index) {
  * @param part  the partition
  * @param env   the environment
  */
-void propagate_blocks(partition_t *part, environment_t *env) {
+static void propagate_blocks(partition_t *part, environment_t *env) {
        block_t         *ready_blocks = NULL;
        unsigned        n_ready       = 0;
        block_t         *bl, *next;
@@ -596,7 +597,7 @@ void propagate_blocks(partition_t *part, environment_t *env) {
  *
  * @param env    the environment
  */
-void propagate(environment_t *env) {
+static void propagate(environment_t *env) {
        partition_t *part, *next;
 
        list_for_each_entry_safe(partition_t, part, next, &env->partitions, part_list) {
@@ -826,7 +827,7 @@ static void apply(ir_graph *irg, partition_t *part) {
                if (is_op_forking(cfop)) {
                        /* a critical edge */
                        ir_node *block = new_r_Block(irg, 1, &ins[i]);
-                       ir_node *jmp   = new_r_Jmp(irg, block);
+                       ir_node *jmp   = new_r_Jmp(block);
                        ins[i] = jmp;
                }
        }
@@ -845,7 +846,7 @@ static void apply(ir_graph *irg, partition_t *part) {
        for (repr_pair = repr->input_pairs; repr_pair != NULL; repr_pair = repr_pair->next) {
                ir_node *input = get_irn_n(repr_pair->irn, repr_pair->index);
                ir_mode *mode  = get_irn_mode(input);
-               ir_node *phi   = new_r_Phi(current_ir_graph, block, n, repr_pair->ins, mode);
+               ir_node *phi   = new_r_Phi(block, n, repr_pair->ins, mode);
 
                set_irn_n(repr_pair->irn, repr_pair->index, phi);
                DEL_ARR_F(repr_pair->ins);
@@ -1088,8 +1089,8 @@ static void check_for_cf_meet(ir_node *block, void *ctx) {
  * Compare two nodes for root ordering.
  */
 static int cmp_nodes(const void *a, const void *b) {
-       ir_node *const *pa     = a;
-       ir_node *const *pb     = b;
+       const ir_node *const *pa = a;
+       const ir_node *const *pb = b;
        const ir_node  *irn_a  = *pa;
        const ir_node  *irn_b  = *pb;
        ir_opcode      code_a  = get_irn_opcode(irn_a);
@@ -1169,6 +1170,7 @@ int shape_blocks(ir_graph *irg) {
        ir_graph      *rem;
        environment_t env;
        partition_t   *part;
+       block_t       *bl;
        int           res, n;
 
        rem = current_ir_graph;
@@ -1246,6 +1248,10 @@ int shape_blocks(ir_graph *irg) {
        //      dump_ir_block_graph(irg, "-after");
        }
 
+       for (bl = env.all_blocks; bl != NULL; bl = bl->all_next) {
+               DEL_ARR_F(bl->roots);
+       }
+
        DEL_ARR_F(env.live_outs);
        del_set(env.opcode2id_map);
        obstack_free(&env.obst, NULL);
@@ -1253,3 +1259,7 @@ int shape_blocks(ir_graph *irg) {
 
        return res;
 }  /* shape_blocks */
+
+ir_graph_pass_t *shape_blocks_pass(const char *name) {
+       return def_graph_pass_ret(name ? name : "shape_blocks", shape_blocks);
+}  /* shape_blocks_pass */