combos constant dataflow analysis has to be consistent with the localopt; this should...
[libfirm] / ir / ana / execution_frequency.c
index 907f9f3..8765c71 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
  * @date      5.11.2004
  * @version   $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include "execution_frequency.h"
 
-#include "firm_common_t.h"
 #include "set.h"
 #include "pdeq.h"
 #include "hashptr.h"
+#include "error.h"
 
 #include "irprog_t.h"
 #include "irgraph_t.h"
@@ -59,7 +57,8 @@ typedef struct {
 /* We use this set for all nodes in all irgraphs. */
 static set *exec_freq_set = NULL;
 
-static int exec_freq_cmp(const void *e1, const void *e2, size_t size) {
+static int exec_freq_cmp(const void *e1, const void *e2, size_t size)
+{
   reg_exec_freq *ef1 = (reg_exec_freq *)e1;
   reg_exec_freq *ef2 = (reg_exec_freq *)e2;
   (void) size;
@@ -67,18 +66,21 @@ static int exec_freq_cmp(const void *e1, const void *e2, size_t size) {
   return (ef1->reg != ef2->reg);
 }
 
-static INLINE unsigned int exec_freq_hash(reg_exec_freq *e) {
+static inline unsigned int exec_freq_hash(reg_exec_freq *e)
+{
   return HASH_PTR(e->reg);
 }
 
-static INLINE void set_region_exec_freq(void *reg, double freq) {
+static inline void set_region_exec_freq(void *reg, double freq)
+{
   reg_exec_freq ef;
   ef.reg  = reg;
   ef.freq = freq;
   set_insert(exec_freq_set, &ef, sizeof(ef), exec_freq_hash(&ef));
 }
 
-double get_region_exec_freq(void *reg) {
+double get_region_exec_freq(void *reg)
+{
   reg_exec_freq ef, *found;
   ef.reg  = reg;
   assert(exec_freq_set);
@@ -93,11 +95,13 @@ double get_region_exec_freq(void *reg) {
 }
 
 /* Returns the number of times the block is executed. */
-double     get_Block_exec_freq(ir_node *b) {
+double     get_Block_exec_freq(ir_node *b)
+{
   return get_region_exec_freq((void *)b);
 }
 
-double get_irn_exec_freq(ir_node *n) {
+double get_irn_exec_freq(ir_node *n)
+{
   if (!is_Block(n)) n = get_nodes_block(n);
   return get_Block_exec_freq(n);
 }
@@ -127,14 +131,16 @@ static int just_passed_a_Raise = 0;
 static ir_node *Cond_list = NULL;
 
 /* We do not use an extra set, as Projs are not yet in the existing one. */
-void set_ProjX_probability(ir_node *n, Cond_prob prob) {
+static void set_ProjX_probability(ir_node *n, Cond_prob prob)
+{
   reg_exec_freq ef;
   ef.reg  = n;
   ef.prob = prob;
   set_insert(exec_freq_set, &ef, sizeof(ef), exec_freq_hash(&ef));
 }
 
-Cond_prob get_ProjX_probability(ir_node *n) {
+static Cond_prob get_ProjX_probability(ir_node *n)
+{
   reg_exec_freq ef, *found;
   ef.reg  = n;
 
@@ -148,8 +154,8 @@ Cond_prob get_ProjX_probability(ir_node *n) {
 
 /* A walker that only visits the nodes we want to see. */
 
-static void
-my_irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) {
+static void my_irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
+{
   int i;
   set_irn_visited(node, current_ir_graph->visited);
 
@@ -183,7 +189,8 @@ my_irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
 
   post(node, env);
 }
-static void my_irg_walk_current_graph(irg_walk_func *pre, irg_walk_func *post, void *env) {
+static void my_irg_walk_current_graph(irg_walk_func *pre, irg_walk_func *post, void *env)
+{
   inc_irg_visited(current_ir_graph);
   my_irg_walk_2_both(get_irg_end(current_ir_graph), pre, post, env);
 }
@@ -192,12 +199,12 @@ static void my_irg_walk_current_graph(irg_walk_func *pre, irg_walk_func *post, v
 static void walk_pre(ir_node *n, void *env)
 {
   (void) env;
-  if (get_irn_op(n) == op_Raise)
+  if (is_Raise(n))
     just_passed_a_Raise = 1;
 
-  if (   (get_irn_op(n) == op_Proj)
-      && (get_irn_op(get_Proj_pred(n)) == op_Cond)
-      && (just_passed_a_Raise)) {
+  if (get_irn_op(n) == op_Proj  &&
+      is_Cond(get_Proj_pred(n)) &&
+      just_passed_a_Raise) {
     ir_node *other_proj;
     ir_node *c = get_Proj_pred(n);
 
@@ -215,7 +222,7 @@ static void walk_pre(ir_node *n, void *env)
     }
   }
 
-  if (get_irn_op(n) == op_Cond) {
+  if (is_Cond(n)) {
     set_irn_link(n, Cond_list);
     Cond_list = n;
   }
@@ -224,13 +231,14 @@ static void walk_pre(ir_node *n, void *env)
 static void walk_post(ir_node *n, void *env)
 {
   (void) env;
-  if (get_irn_op(n) == op_Raise)
+  if (is_Raise(n))
     just_passed_a_Raise = 0;
 
-  if (   (get_irn_op(n) == op_Proj)
-      && (get_irn_op(get_Proj_pred(n)) == op_Cond)
-      && ((get_ProjX_probability(n) == Cond_prob_exception_taken)    ||
-         (get_ProjX_probability(n) == Cond_prob_was_exception_taken)   )) {
+  if (get_irn_op(n) == op_Proj  &&
+      is_Cond(get_Proj_pred(n)) && (
+        get_ProjX_probability(n) == Cond_prob_exception_taken ||
+        get_ProjX_probability(n) == Cond_prob_was_exception_taken
+      )) {
     just_passed_a_Raise = 1;
   }
 }
@@ -238,7 +246,8 @@ static void walk_post(ir_node *n, void *env)
 /** Precompute which Conds test for an exception.
  *
  *  Operates on current_ir_graph. */
-void precompute_cond_evaluation(void) {
+static void precompute_cond_evaluation(void)
+{
   ir_node *c;
 
   compute_irg_outs(current_ir_graph);
@@ -257,10 +266,12 @@ void precompute_cond_evaluation(void) {
     /* both are exceptions */
     if ((get_ProjX_probability(p0) == Cond_prob_exception_taken) &&
         (get_ProjX_probability(p1) == Cond_prob_exception_taken)   ) {
-      assert(0 && "I tried to avoid these!");
+      panic("I tried to avoid these!");
+#if 0
       /* It's a */
       set_ProjX_probability(p0, Cond_prob_normal);
       set_ProjX_probability(p1, Cond_prob_normal);
+#endif
     }
 
     /* p0 is exception */
@@ -281,7 +292,8 @@ void precompute_cond_evaluation(void) {
   }
 }
 
-int is_fragile_Proj(ir_node *n) {
+int is_fragile_Proj(ir_node *n)
+{
   return is_Proj(n) && (get_ProjX_probability(n) == Cond_prob_exception_taken);
 }
 
@@ -296,7 +308,7 @@ int is_fragile_Proj(ir_node *n) {
 
 static double exception_prob = 0.001;
 
-static INLINE int is_loop_head(ir_node *cond)
+static inline int is_loop_head(ir_node *cond)
 {
   (void) cond;
   return 0;
@@ -306,7 +318,8 @@ static INLINE int is_loop_head(ir_node *cond)
  *
  *  Given all outs of the predecessor region, we can compute the weight of
  *  this single edge. */
-static INLINE double get_weighted_region_exec_freq(void *reg, int pos) {
+static inline double get_weighted_region_exec_freq(void *reg, int pos)
+{
   void *pred_reg        = get_region_in(reg, pos);
   double res, full_freq = get_region_exec_freq (pred_reg);
   int n_outs            = get_region_n_outs    (pred_reg);
@@ -315,7 +328,7 @@ static INLINE double get_weighted_region_exec_freq(void *reg, int pos) {
   ir_node *cfop;
   if (is_ir_node(reg)) {
     cfop = get_Block_cfgpred((ir_node *)reg, pos);
-    if (is_Proj(cfop) && (get_irn_op(get_Proj_pred(cfop)) != op_Cond))
+    if (is_Proj(cfop) && !is_Cond(get_Proj_pred(cfop)))
       cfop = skip_Proj(cfop);
   } else {
     assert(is_ir_loop(reg));
@@ -333,7 +346,8 @@ static INLINE double get_weighted_region_exec_freq(void *reg, int pos) {
   return res;
 }
 
-static INLINE void compute_region_freqency(void *reg, double head_weight) {
+static inline void compute_region_freqency(void *reg, double head_weight)
+{
   int i, n_ins = get_region_n_ins(reg);
   double my_freq = 0;
 
@@ -363,7 +377,8 @@ static void check_proper_head(ir_loop *l, void *reg)
 }
 
 /* Compute the ex freq for current_ir_graph */
-static void compute_frequency(int default_loop_weight) {
+static void compute_frequency(int default_loop_weight)
+{
   ir_loop *outermost_l = get_irg_loop(current_ir_graph);
   pdeq *block_worklist = new_pdeq1(outermost_l);
 
@@ -393,7 +408,8 @@ static void compute_frequency(int default_loop_weight) {
  * irg:                 The graph to be analyzed.
  * default_loop_weight: The number of executions of a loop.
  */
-void compute_execution_frequency(ir_graph *irg, int default_loop_weight, double exception_probability) {
+void compute_execution_frequency(ir_graph *irg, int default_loop_weight, double exception_probability)
+{
   ir_graph *rem = current_ir_graph;
   current_ir_graph = irg;
   exception_prob = exception_probability;
@@ -417,7 +433,8 @@ void compute_execution_frequency(ir_graph *irg, int default_loop_weight, double
 }
 
 
-void compute_execution_frequencies(int default_loop_weight, double exception_probability) {
+void compute_execution_frequencies(int default_loop_weight, double exception_probability)
+{
   int i, n_irgs = get_irp_n_irgs();
   free_intervals();
   for (i = 0; i < n_irgs; ++i) {
@@ -427,7 +444,8 @@ void compute_execution_frequencies(int default_loop_weight, double exception_pro
 }
 
 /** free occupied memory, reset */
-void free_execution_frequency(void) {
+void free_execution_frequency(void)
+{
   int i, n_irgs = get_irp_n_irgs();
   free_intervals();
   del_set(exec_freq_set);
@@ -437,10 +455,12 @@ void free_execution_frequency(void) {
   set_irp_exec_freq_state(exec_freq_none);
 }
 
-exec_freq_state get_irg_exec_freq_state(ir_graph *irg) {
+exec_freq_state get_irg_exec_freq_state(ir_graph *irg)
+{
   return irg->execfreq_state;
 }
-void            set_irg_exec_freq_state(ir_graph *irg, exec_freq_state s) {
+void            set_irg_exec_freq_state(ir_graph *irg, exec_freq_state s)
+{
   if ((get_irp_exec_freq_state() == exec_freq_consistent && s != exec_freq_consistent) ||
       (get_irp_exec_freq_state() == exec_freq_none       && s != exec_freq_none))
     irp->execfreq_state = exec_freq_inconsistent;
@@ -448,21 +468,25 @@ void            set_irg_exec_freq_state(ir_graph *irg, exec_freq_state s) {
 }
 
 /* Sets irg and irp exec freq state to inconsistent if it is set to consistent. */
-void            set_irg_exec_freq_state_inconsistent(ir_graph *irg) {
+void            set_irg_exec_freq_state_inconsistent(ir_graph *irg)
+{
   if (get_irg_exec_freq_state(irg) == exec_freq_consistent)
     set_irg_exec_freq_state(irg, exec_freq_inconsistent);
 }
 
-void set_irp_exec_freq_state(exec_freq_state s) {
+void set_irp_exec_freq_state(exec_freq_state s)
+{
   irp->execfreq_state = s;
 }
 
-exec_freq_state get_irp_exec_freq_state(void) {
+exec_freq_state get_irp_exec_freq_state(void)
+{
   return irp->execfreq_state;
 }
 
 /* Sets irp and all irg exec freq states to inconsistent if it is set to consistent. */
-void            set_irp_exec_freq_state_inconsistent(void) {
+void            set_irp_exec_freq_state_inconsistent(void)
+{
   if (get_irp_exec_freq_state() != exec_freq_none) {
     int i, n_irgs = get_irp_n_irgs();
     set_irp_exec_freq_state(exec_freq_inconsistent);