beloopana: Remove duplicate comments.
[libfirm] / ir / opt / gvn_pre.c
index e4bc76b..0bdd8fd 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -108,7 +94,7 @@ typedef struct elim_pair {
 /** environment for the GVN-PRE algorithm */
 typedef struct pre_env {
        ir_graph       *graph;        /* current graph */
-       struct obstack *obst;         /* obstack to allocate on */
+       struct obstack  obst;         /* obstack to allocate on */
        ir_node        *start_block;  /* start block of the current graph */
        ir_node        *end_block;    /* end block of the current graph */
        ir_node        *end_node;     /* end node of the current graph */
@@ -214,7 +200,7 @@ static void dump_value_set(ir_valueset_t *set, const char *txt, ir_node *block)
                ++i;
        }
        DB((dbg, LEVEL_2, "\n}\n"));
-}  /* dump_value_set */
+}
 
 /**
  * Dump all exp_gen value sets.
@@ -423,7 +409,7 @@ static ir_node *identify_or_remember(ir_node *irn)
  */
 static void alloc_block_info(ir_node *block, pre_env *env)
 {
-       block_info *info = OALLOC(env->obst, block_info);
+       block_info *info = OALLOC(&env->obst, block_info);
 
        set_irn_link(block, info);
        info->exp_gen    = ir_valueset_new(16);
@@ -440,7 +426,7 @@ static void alloc_block_info(ir_node *block, pre_env *env)
 
        info->next = env->list;
        env->list  = info;
-}  /* alloc_block_info */
+}
 
 static void free_block_info(block_info *block_info)
 {
@@ -1228,7 +1214,7 @@ static void update_new_set(ir_node *block, ir_node *idom)
        if (updated)
                dump_value_set(curr_info->avail_out, "Updated [Avail_out]", block);
 #endif
-} /* update_new_set */
+}
 
 /**
  * Checks if hoisting irn is greedy.
@@ -1575,7 +1561,8 @@ static void update_new_set_walker(ir_node *block, void *ctx)
  */
 static void hoist_high(ir_node *block, void *ctx)
 {
-       pre_env                *env        = (pre_env*)ctx;
+       (void)ctx;
+
        block_info             *curr_info;
        ir_valueset_iterator_t  iter;
        ir_node                *expr;
@@ -1591,9 +1578,6 @@ static void hoist_high(ir_node *block, void *ctx)
                ir_valueset_del(curr_info->new_set);
        curr_info->new_set = ir_valueset_new(16);
 
-       if (block == env->start_block)
-               return;
-
        if (arity < 2)
                return;
 
@@ -1792,7 +1776,7 @@ static void eliminate(ir_node *irn, void *ctx)
                        DB((dbg, LEVEL_3, "Elim %+F(%+F) avail %+F\n", irn, value, expr));
 
                        if (expr != NULL && expr != irn) {
-                               elim_pair *p = OALLOC(env->obst, elim_pair);
+                               elim_pair *p = OALLOC(&env->obst, elim_pair);
 
                                p->old_node = irn;
                                p->new_node = expr;
@@ -1806,7 +1790,7 @@ static void eliminate(ir_node *irn, void *ctx)
                        }
                }
        }
-}  /* eliminate */
+}
 
 /**
  * Do all the recorded changes and optimize
@@ -1856,7 +1840,7 @@ static void eliminate_nodes(elim_pair *pairs, ir_nodeset_t *keeps)
        foreach_ir_nodeset(keeps, m_phi, iter) {
                remove_End_keepalive(end, m_phi);
        }
-}  /* eliminate_nodes */
+}
 
 
 /* --------------------------------------------------------
@@ -1925,7 +1909,7 @@ static void gvn_pre(ir_graph *irg, pre_env *env)
 #if HOIST_HIGH
        /* An attempt to reduce lifetimes by hoisting already hoisted values
           even higher if their operands die. */
-       dom_tree_walk_irg(irg, hoist_high, NULL, env);
+       dom_tree_walk_irg(irg, hoist_high, NULL, NULL);
        /* update avail_out for elimination */
        dom_tree_walk_irg(irg, update_new_set_walker, NULL, env);
 #endif
@@ -1948,7 +1932,6 @@ static void gvn_pre(ir_graph *irg, pre_env *env)
  */
 void do_gvn_pre(ir_graph *irg)
 {
-       struct obstack        obst;
        pre_env               env;
        ir_nodeset_t          keeps;
        optimization_state_t  state;
@@ -1978,9 +1961,7 @@ void do_gvn_pre(ir_graph *irg)
        DEBUG_ONLY(init_stats();)
 
        /* setup environment */
-       obstack_init(&obst);
        env.graph        = irg;
-       env.obst         = &obst;
        env.list         = NULL;
        env.start_block  = get_irg_start_block(irg);
        env.end_block    = get_irg_end_block(irg);
@@ -1988,6 +1969,7 @@ void do_gvn_pre(ir_graph *irg)
        env.pairs        = NULL;
        env.keeps        = &keeps;
        env.last_idx     = get_irg_last_idx(irg);
+       obstack_init(&env.obst);
 
        /* Detect and set links of infinite loops to non-zero. */
        analyse_loops(irg);
@@ -2022,7 +2004,7 @@ void do_gvn_pre(ir_graph *irg)
 
        DEBUG_ONLY(free_stats();)
        ir_nodehashmap_destroy(&value_map);
-       obstack_free(&obst, NULL);
+       obstack_free(&env.obst, NULL);
        ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_LOOP_LINK);
 
        /* Pin the graph again.