remove license stuff from files
[libfirm] / ir / ana / execfreq.c
index be752dd..7950e5c 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.
  */
 
 /**
@@ -35,7 +21,7 @@
 #include "set.h"
 #include "hashptr.h"
 #include "debug.h"
-#include "statev.h"
+#include "statev_t.h"
 #include "dfs_t.h"
 #include "absgraph.h"
 
 
 #define MAX_INT_FREQ 1000000
 
-typedef struct freq_t {
-       double freq;
-} freq_t;
-
-static ir_nodehashmap_t freq_map;
-static struct obstack   obst;
-static hook_entry_t     hook;
+static hook_entry_t hook;
 
 double get_block_execfreq(const ir_node *block)
 {
-       const freq_t *freq = ir_nodehashmap_get(freq_t, &freq_map, block);
-       if (freq == NULL)
-               return 0.0;
-       return freq->freq;
+       return block->attr.block.execfreq;
 }
 
 void set_block_execfreq(ir_node *block, double newfreq)
 {
-       freq_t *freq = ir_nodehashmap_get(freq_t, &freq_map, block);
-       if (freq == NULL) {
-               freq = OALLOC(&obst, freq_t);
-               ir_nodehashmap_insert(&freq_map, block, freq);
-       }
-       freq->freq = newfreq;
+       block->attr.block.execfreq = newfreq;
 }
 
 static void exec_freq_node_info(void *ctx, FILE *f, const ir_node *irn)
@@ -90,14 +62,13 @@ static void exec_freq_node_info(void *ctx, FILE *f, const ir_node *irn)
        (void)ctx;
        if (!is_Block(irn))
                return;
-       fprintf(f, "execution frequency: %g\n", get_block_execfreq(irn));
+       double freq = get_block_execfreq(irn);
+       if (freq != 0.0)
+               fprintf(f, "execution frequency: %g\n", freq);
 }
 
 void init_execfreq(void)
 {
-       ir_nodehashmap_init(&freq_map);
-       obstack_init(&obst);
-
        memset(&hook, 0, sizeof(hook));
        hook.hook._hook_node_info = exec_freq_node_info;
        register_hook(hook_node_info, &hook);
@@ -106,9 +77,6 @@ void init_execfreq(void)
 void exit_execfreq(void)
 {
        unregister_hook(hook_node_info, &hook);
-
-       obstack_free(&obst, NULL);
-       ir_nodehashmap_destroy(&freq_map);
 }
 
 
@@ -258,7 +226,8 @@ void ir_estimate_execfreq(ir_graph *irg)
 
        assure_irg_properties(irg,
                IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES
-               | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
+               | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO
+               | IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE);
 
        /* compute a DFS.
         * using a toposort on the CFG (without back edges) will propagate
@@ -270,9 +239,10 @@ void ir_estimate_execfreq(ir_graph *irg)
        int          size = dfs_get_n_nodes(dfs);
        gs_matrix_t *mat  = gs_new_matrix(size, size);
 
-       ir_node *end_block = get_irg_end_block(irg);
+       ir_node *const start_block = get_irg_start_block(irg);
+       ir_node *const end_block   = get_irg_end_block(irg);
 
-       for (int idx = dfs_get_n_nodes(dfs) - 1; idx >= 0; --idx) {
+       for (int idx = size - 1; idx >= 0; --idx) {
                const ir_node *bb = (ir_node*)dfs_get_post_num_node(dfs, size-idx-1);
 
                /* Sum of (execution frequency of predecessor * probability of cf edge) ... */
@@ -290,8 +260,7 @@ void ir_estimate_execfreq(ir_graph *irg)
                 * Solve A*x = 1*x => (A-I)x = 0
                 */
                if (bb == end_block) {
-                       const ir_node *start_block = get_irg_start_block(irg);
-                       int            s_idx = size - dfs_get_post_num(dfs, start_block)-1;
+                       int const s_idx = size - dfs_get_post_num(dfs, start_block) - 1;
                        gs_matrix_set(mat, s_idx, idx, 1.0);
                }
        }
@@ -302,7 +271,6 @@ void ir_estimate_execfreq(ir_graph *irg)
         * This avoid strange results for e.g. an irg containing a exit()-call
         * which block has no cfg successor.
         */
-       ir_node       *start_block  = get_irg_start_block(irg);
        int            s_idx        = size - dfs_get_post_num(dfs, start_block)-1;
        const ir_node *end          = get_irg_end(irg);
        int            n_keepalives = get_End_n_keepalives(end);
@@ -326,11 +294,11 @@ void ir_estimate_execfreq(ir_graph *irg)
         * (note: start_idx is != 0 in strange cases involving endless loops,
         *  probably a misfeature/bug)
         */
-       int    start_idx  = size-dfs_get_post_num(dfs, get_irg_start_block(irg))-1;
+       int    start_idx  = size - dfs_get_post_num(dfs, start_block) - 1;
        double start_freq = x[start_idx];
        double norm       = start_freq != 0.0 ? 1.0 / start_freq : 1.0;
 
-       for (int idx = dfs_get_n_nodes(dfs) - 1; idx >= 0; --idx) {
+       for (int idx = size - 1; idx >= 0; --idx) {
                ir_node *bb = (ir_node *) dfs_get_post_num_node(dfs, size - idx - 1);
 
                /* take abs because it sometimes can be -0 in case of endless loops */