used new hooks instead of firmstat
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Jan 2005 12:06:47 +0000 (12:06 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Jan 2005 12:06:47 +0000 (12:06 +0000)
[r4846]

17 files changed:
ir/ana/cgana.c
ir/ir/irarch.c
ir/ir/irgmod.c
ir/ir/irgopt.c
ir/ir/irgraph.c
ir/ir/irgwalk.c
ir/ir/irgwalk_blk.c
ir/ir/irnode.c
ir/ir/irop.c
ir/ir/iropt.c
ir/ir/iropt_dbg.h
ir/opt/ldstopt.c
ir/opt/reassoc.c
ir/stat/firmstat.c
ir/stat/firmstat.h
ir/stat/firmstat_t.h
ir/stat/pattern_dmp.c

index b1d499b..548ed9e 100644 (file)
@@ -46,7 +46,7 @@
 
 #include "irdump.h"
 
-#include "firmstat.h"
+#include "irhooks.h"
 
 /* Eindeutige Adresse zur Markierung von besuchten Knoten und zur
  * Darstellung der unbekannten Methode. */
index 4d2a3ed..e539e20 100644 (file)
 #include "dbginfo_t.h"
 #include "iropt_dbg.h"
 #include "irflag_t.h"
-#include "firmstat.h"
+#include "irhooks.h"
 #include "ircons.h"
 #include "irarch.h"
-#include "firmstat.h"
 
 #undef DEB
 
@@ -338,7 +337,7 @@ ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn)
   }
 
   if (res != irn)
-    stat_arch_dep_replace_mul_with_shifts(irn);
+    hook_arch_dep_replace_mul_with_shifts(irn);
 
   return res;
 }
@@ -706,7 +705,7 @@ ir_node *arch_dep_replace_div_by_const(ir_node *irn)
   }
 
   if (res != irn)
-    stat_arch_dep_replace_div_by_const(irn);
+    hook_arch_dep_replace_div_by_const(irn);
 
   return res;
 }
@@ -797,7 +796,7 @@ ir_node *arch_dep_replace_mod_by_const(ir_node *irn)
   }
 
   if (res != irn)
-    stat_arch_dep_replace_mod_by_const(irn);
+    hook_arch_dep_replace_mod_by_const(irn);
 
   return res;
 }
@@ -904,7 +903,7 @@ void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn
   }
 
   if (*div)
-    stat_arch_dep_replace_DivMod_by_const(irn);
+    hook_arch_dep_replace_DivMod_by_const(irn);
 }
 
 
index 2f5b173..990986f 100644 (file)
@@ -22,7 +22,7 @@
 # include "irgmod.h"
 # include "array.h"
 # include "ircons.h"
-# include "firmstat.h"
+# include "irhooks.h"
 
 /* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
    from several inputs.
@@ -56,7 +56,7 @@ exchange (ir_node *old, ir_node *nw)
   assert (irg);
   assert(get_irn_op(old)->opar != oparity_dynamic);
 
-  stat_turn_into_id(old);
+  hook_turn_into_id(old);
 
   block = old->in[0];
   if (!block) {
index 2c42725..fab7e1e 100644 (file)
@@ -39,7 +39,7 @@
 #include "cgana.h"
 
 #include "irflag_t.h"
-#include "firmstat.h"
+#include "irhooks.h"
 
 /* Defined in iropt.c */
 pset *new_identities (void);
@@ -508,7 +508,7 @@ dead_node_elimination(ir_graph *irg) {
   struct obstack *rebirth_obst   = NULL;
 
   /* inform statistics that we started a dead-node elimination run */
-  stat_dead_node_elim_start(irg);
+  hook_dead_node_elim_start(irg);
 
   /* Remember external state of current_ir_graph. */
   rem = current_ir_graph;
@@ -546,7 +546,7 @@ dead_node_elimination(ir_graph *irg) {
   }
 
   /* inform statistics that the run is over */
-  stat_dead_node_elim_stop(irg);
+  hook_dead_node_elim_stop(irg);
 
   current_ir_graph = rem;
   set_interprocedural_view(rem_ipview);
@@ -796,7 +796,7 @@ int inline_method(ir_node *call, ir_graph *called_graph) {
   }
 
   /* here we know we WILL inline, so inform the statistics */
-  stat_inline(call, called_graph);
+  hook_inline(call, called_graph);
 
   /* -- Decide how to handle exception control flow: Is there a handler
      for the Call node, or do we branch directly to End on an exception?
index 1cb0a69..9f4c06c 100644 (file)
@@ -31,7 +31,7 @@
 # include "irgmod.h"
 # include "mangle.h"
 # include "irouts.h"
-# include "firmstat.h"
+# include "irhooks.h"
 # include "irgwalk.h"
 
 /**
@@ -124,7 +124,7 @@ new_r_ir_graph (entity *ent, int n_loc)
   res->kind = k_ir_graph;
 
   /* inform statistics here, as blocks will be already build on this graph */
-  stat_new_graph(res, ent);
+  hook_new_graph(res, ent);
 
   current_ir_graph = res;
 
@@ -232,7 +232,7 @@ ir_graph *new_const_code_irg(void) {
   res = alloc_graph();
 
   /* inform statistics here, as blocks will be already build on this graph */
-  stat_new_graph(res, NULL);
+  hook_new_graph(res, NULL);
 
   current_ir_graph = res;
   res->n_loc = 1;       /* Only the memory. */
@@ -297,7 +297,7 @@ void  del_identities (pset *value_table);
    graph, nor the entity standing for this graph. */
 void free_ir_graph (ir_graph *irg) {
 
-  stat_free_graph(irg);
+  hook_free_graph(irg);
   if (irg->outs_state != outs_none) free_outs(irg);
   if (irg->frame_type)  free_type(irg->frame_type);
   if (irg->value_table) del_identities(irg->value_table);
index afa850d..dd98632 100644 (file)
@@ -32,7 +32,7 @@
 #include "irprog.h"
 #include "irgwalk.h"
 #include "typewalk.h"
-#include "firmstat.h"
+#include "irhooks.h"
 #include "ircgcons.h"
 
 #include "eset.h"
@@ -246,7 +246,7 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
   ir_graph * rem = current_ir_graph;
 
-  stat_irg_walk(irg, (void *)pre, (void *)post);
+  hook_irg_walk(irg, (void *)pre, (void *)post);
   current_ir_graph = irg;
   irg_walk(get_irg_end(irg), pre, post, env);
   current_ir_graph = rem;
@@ -430,7 +430,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
   ir_node *block, *pred;
   int i;
 
-  stat_irg_block_walk(current_ir_graph, node, (void *)pre, (void *)post);
+  hook_irg_block_walk(current_ir_graph, node, (void *)pre, (void *)post);
 
   assert(node);
   assert(!get_interprocedural_view());   /* interprocedural_view not implemented, because it
index 9e04aea..cf0e30f 100644 (file)
@@ -18,7 +18,7 @@
 #include "irgwalk.h"
 #include "pdeq.h"
 #include "pset.h"
-#include "firmstat.h"
+#include "irhooks.h"
 
 /**
  * Metadata for block walker
@@ -217,7 +217,7 @@ void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *po
 {
   ir_graph * rem = current_ir_graph;
 
-  stat_irg_walk_blkwise(irg, (void *)pre, (void *)post);
+  hook_irg_walk_blkwise(irg, (void *)pre, (void *)post);
   current_ir_graph = irg;
   irg_walk_blkwise(get_irg_end(irg), pre, post, env);
   current_ir_graph = rem;
index 2a42cb7..e432cbb 100644 (file)
@@ -28,7 +28,7 @@
 #include "irop_t.h"
 #include "irprog_t.h"
 
-#include "firmstat.h"
+#include "irhooks.h"
 
 /* some constants fixing the positions of nodes predecessors
    in the in array */
@@ -155,7 +155,7 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo
   res->node_nr = get_irp_new_node_nr();
 #endif
 
-  stat_new_node(res);
+  hook_new_node(res);
 
   return res;
 }
index ac34f4b..87193e7 100644 (file)
@@ -20,7 +20,7 @@
 
 # include "irop_t.h"
 # include "irnode_t.h"
-# include "firmstat.h"
+# include "irhooks.h"
 
 # include "iropt_t.h"             /* for firm_set_default_operations */
 
@@ -149,12 +149,12 @@ new_ir_op(opcode code, const char *name, op_pin_state p, unsigned flags, op_arit
   firm_set_default_operations(res);
   firm_set_default_copy_attr(res);
 
-  stat_new_ir_op(res);
+  hook_new_ir_op(res);
   return res;
 }
 
 void free_ir_op(ir_op *code) {
-  stat_free_ir_op(code);
+  hook_free_ir_op(code);
   free(code);
 }
 
index dbcbe6c..52a2f0d 100644 (file)
@@ -35,7 +35,7 @@
 # include "dbginfo_t.h"
 # include "iropt_dbg.h"
 # include "irflag_t.h"
-# include "firmstat.h"
+# include "irhooks.h"
 # include "irarch.h"
 # include "hashptr.h"
 
index 0b47025..7f0926b 100644 (file)
@@ -25,7 +25,7 @@
          ir_node *ons[2];                                         \
          ons[0] = oldn;                                           \
          ons[1] = get_Block_cfgpred(oldn, 0);                     \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_STG);    \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_STG);    \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_dead_code); \
        } while(0)
 
@@ -38,7 +38,7 @@
          ir_node *ons[2];                                         \
          ons[0] = oldn;                                           \
          ons[1] = get_Block_cfgpred(oldn, 0);                     \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_STG);    \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_STG);    \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_straightening); \
        } while(0)
 
@@ -52,7 +52,7 @@
          ons[1] = a;                                                 \
          ons[2] = b;                                                 \
          ons[3] = get_Proj_pred(a);                                  \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_IFSIM);     \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_IFSIM);     \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_if_simplification); \
        } while(0)
 
@@ -61,7 +61,7 @@
  */
 #define DBG_OPT_CSTEVAL(oldn, n)                                       \
   do {                                                                 \
-         stat_merge_nodes(&n, 1, &oldn, 1, STAT_OPT_CONST_EVAL);       \
+         hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONST_EVAL);       \
           __dbg_info_merge_pair(n, oldn, dbg_const_eval);              \
   } while(0)
 
@@ -71,7 +71,7 @@
          ons[0] = oldn;                                              \
          ons[1] = a;                                                 \
          ons[2] = b;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_ALGSIM);    \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
   } while(0)
 
@@ -81,7 +81,7 @@
          ons[0] = oldn;                                              \
          ons[1] = pred;                                              \
          ons[2] = n;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_ALGSIM);    \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
   } while(0)
 
@@ -90,7 +90,7 @@
          ir_node *ons[2];                                            \
          ons[0] = oldn;                                              \
          ons[1] = a;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_ALGSIM);    \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
   } while(0)
 
@@ -99,7 +99,7 @@
          ir_node *ons[2];                                            \
          ons[0] = oldn;                                              \
          ons[1] = first_val;                                         \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_PHI);       \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_PHI);       \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_ssa);   \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = oldst;                                             \
          ons[1] = st;                                                \
-         stat_merge_nodes(&st, 1, ons, SIZ(ons), STAT_OPT_WAW);      \
+         hook_merge_nodes(&st, 1, ons, SIZ(ons), HOOK_OPT_WAW);      \
          __dbg_info_merge_sets(&st, 1, ons, SIZ(ons), dbg_write_after_write); \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = store;                                             \
          ons[1] = load;                                              \
-         stat_merge_nodes(&load, 1, ons, SIZ(ons), STAT_OPT_WAR);    \
+         hook_merge_nodes(&load, 1, ons, SIZ(ons), HOOK_OPT_WAR);    \
          __dbg_info_merge_sets(&load, 1, ons, SIZ(ons), dbg_write_after_read); \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = store;                                             \
          ons[1] = load;                                              \
-         stat_merge_nodes(&store, 1, ons, SIZ(ons), STAT_OPT_RAW);   \
+         hook_merge_nodes(&store, 1, ons, SIZ(ons), HOOK_OPT_RAW);   \
          __dbg_info_merge_sets(&store, 1, ons, SIZ(ons), dbg_read_after_write); \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = oldld;                                             \
          ons[1] = ld;                                                \
-         stat_merge_nodes(&ld, 1, ons, SIZ(ons), STAT_OPT_RAR);      \
+         hook_merge_nodes(&ld, 1, ons, SIZ(ons), HOOK_OPT_RAR);      \
          __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_after_read); \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = ld;                                                \
          ons[1] = c;                                                 \
-         stat_merge_nodes(&c, 1, ons, SIZ(ons), STAT_OPT_RC);        \
+         hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_RC);        \
          __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_a_const); \
        } while(0)
 
          ons[0] = oldn;                                              \
          ons[1] = a;                                                 \
          ons[2] = n;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_TUPLE);     \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_TUPLE);     \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = oldn;                                              \
          ons[1] = n;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_ID);        \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ID);        \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
   } while(0)
 
          ir_node *ons[2];                                            \
          ons[0] = oldn;                                              \
          ons[1] = n;                                                 \
-         stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_CSE);       \
+         hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_CSE);       \
          __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_cse);   \
   } while(0)
 
     ons[0] = oldn;                                                  \
     ons[1] = skip_Proj(get_Sel_ptr(oldn));                          \
     ons[2] = n;                                                     \
-    stat_merge_nodes(&n, 1, ons, SIZ(ons), STAT_OPT_POLY_CALL);            \
+    hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_POLY_CALL);            \
     __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_rem_poly_call); \
   } while(0)
 
 #define DBG_OPT_POLY(oldn, n)                                   \
   do {                                                          \
-    stat_merge_nodes(&n, 1, &oldn, 1, STAT_OPT_POLY_CALL);     \
+    hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_POLY_CALL);     \
     __dbg_info_merge_pair(n, oldn, dbg_rem_poly_call);          \
   } while(0)
index 9a77017..ae143ab 100644 (file)
@@ -35,7 +35,7 @@
 # include "iropt_dbg.h"
 # include "irflag_t.h"
 # include "array.h"
-# include "firmstat.h"
+# include "irhooks.h"
 
 #undef IMAX
 #define IMAX(a,b)      ((a) > (b) ? (a) : (b))
index 31f44ab..20af0e9 100644 (file)
@@ -24,7 +24,7 @@
 # include "irflag_t.h"
 # include "irgwalk.h"
 # include "reassoc_t.h"
-# include "firmstat.h"
+# include "irhooks.h"
 
 typedef struct _walker_t {
   int changes;          /* set, if a reassociation take place */
@@ -313,7 +313,7 @@ static void do_reassociation(ir_node *n, void *env)
   walker_t *wenv = env;
   int res;
 
-  stat_reassociate(1);
+  hook_reassociate(1);
 
   /* reassociation must run until fixpoint */
   do {
@@ -334,7 +334,7 @@ static void do_reassociation(ir_node *n, void *env)
     }
   } while (res == 1);
 
-  stat_reassociate(0);
+  hook_reassociate(0);
 }
 
 /*
index e098104..f68870b 100644 (file)
@@ -32,6 +32,7 @@
 #include "dags.h"
 #include "stat_dmp.h"
 #include "xmalloc.h"
+#include "irhooks.h"
 
 /*
  * need this to be static:
@@ -817,80 +818,8 @@ ir_op *stat_get_op_from_opcode(opcode code)
   return opcode_find_entry(code, status->ir_op_hash);
 }
 
-/* initialize the statistics module. */
-void init_stat(unsigned enable_options)
-{
-#define X(a)  a, sizeof(a)-1
-
-  /* enable statistics */
-  status->stat_options = enable_options & FIRMSTAT_ENABLED ? enable_options : 0;
-
-  if (! status->stat_options)
-   return;
-
-  obstack_init(&status->cnts);
-
-  /* create the hash-tables */
-  status->irg_hash   = new_pset(graph_cmp, 8);
-  status->ir_op_hash = new_pset(opcode_cmp_2, 1);
-
-  /* create the wait queue */
-  status->wait_q     = new_pdeq();
-
-  if (enable_options & FIRMSTAT_COUNT_STRONG_OP) {
-    /* build the pseudo-ops */
-    _op_Phi0.code    = get_next_ir_opcode();
-    _op_Phi0.name    = new_id_from_chars(X("Phi0"));
-
-    _op_PhiM.code    = get_next_ir_opcode();
-    _op_PhiM.name    = new_id_from_chars(X("PhiM"));
-
-    _op_ProjM.code   = get_next_ir_opcode();
-    _op_ProjM.name   = new_id_from_chars(X("ProjM"));
-
-    _op_MulC.code    = get_next_ir_opcode();
-    _op_MulC.name    = new_id_from_chars(X("MulC"));
-
-    _op_DivC.code    = get_next_ir_opcode();
-    _op_DivC.name    = new_id_from_chars(X("DivC"));
-
-    _op_ModC.code    = get_next_ir_opcode();
-    _op_ModC.name    = new_id_from_chars(X("ModC"));
-
-    _op_DivModC.code = get_next_ir_opcode();
-    _op_DivModC.name = new_id_from_chars(X("DivModC"));
-
-    status->op_Phi0    = &_op_Phi0;
-    status->op_PhiM    = &_op_PhiM;
-    status->op_ProjM   = &_op_ProjM;
-    status->op_MulC    = &_op_MulC;
-    status->op_DivC    = &_op_DivC;
-    status->op_ModC    = &_op_ModC;
-    status->op_DivModC = &_op_DivModC;
-  }
-  else {
-    status->op_Phi0    = NULL;
-    status->op_PhiM    = NULL;
-    status->op_ProjM   = NULL;
-    status->op_MulC    = NULL;
-    status->op_DivC    = NULL;
-    status->op_ModC    = NULL;
-    status->op_DivModC = NULL;
-  }
-
-  /* register the dumper */
-  stat_register_dumper(&simple_dumper);
-
-  if (enable_options & FIRMSTAT_CSV_OUTPUT)
-    stat_register_dumper(&csv_dumper);
-
-  /* initialize the pattern hash */
-  stat_init_pattern_history(enable_options & FIRMSTAT_PATTERN_ENABLED);
-#undef X
-}
-
-/* A new IR op is registered. */
-void stat_new_ir_op(const ir_op *op)
+/** A new IR op is registered. */
+static void stat_new_ir_op(void *ctx, ir_op *op)
 {
   if (! status->stat_options)
     return;
@@ -907,8 +836,8 @@ void stat_new_ir_op(const ir_op *op)
   STAT_LEAVE;
 }
 
-/* An IR op is freed. */
-void stat_free_ir_op(const ir_op *op)
+/** An IR op is freed. */
+static void stat_free_ir_op(void *ctx, ir_op *op)
 {
   if (! status->stat_options)
     return;
@@ -919,8 +848,8 @@ void stat_free_ir_op(const ir_op *op)
   STAT_LEAVE;
 }
 
-/* A new node is created. */
-void stat_new_node(ir_node *node)
+/** A new node is created. */
+static void stat_new_node(void *ctx, ir_node *node)
 {
   if (! status->stat_options)
     return;
@@ -948,8 +877,8 @@ void stat_new_node(ir_node *node)
   STAT_LEAVE;
 }
 
-/* A node is changed into a Id node */
-void stat_turn_into_id(ir_node *node)
+/** A node is changed into a Id node */
+static void stat_turn_into_id(void *ctx, ir_node *node)
 {
   if (! status->stat_options)
     return;
@@ -973,8 +902,8 @@ void stat_turn_into_id(ir_node *node)
   STAT_LEAVE;
 }
 
-/* A new graph was created */
-void stat_new_graph(ir_graph *irg, entity *ent)
+/** A new graph was created */
+static void stat_new_graph(void *ctx, ir_graph *irg, entity *ent)
 {
   if (! status->stat_options)
     return;
@@ -995,10 +924,10 @@ void stat_new_graph(ir_graph *irg, entity *ent)
   STAT_LEAVE;
 }
 
-/*
+/**
  * A graph will be deleted
  */
-void stat_free_graph(ir_graph *irg)
+static void stat_free_graph(void *ctx, ir_graph *irg)
 {
   if (! status->stat_options)
     return;
@@ -1018,10 +947,10 @@ void stat_free_graph(ir_graph *irg)
   STAT_LEAVE;
 }
 
-/*
+/**
  * A walk over a graph is initiated. Do not count walks from statistic code.
  */
-void stat_irg_walk(ir_graph *irg, void *pre, void *post)
+static void stat_irg_walk(void *ctx, ir_graph *irg, void *pre, void *post)
 {
   if (! status->stat_options)
     return;
@@ -1035,19 +964,19 @@ void stat_irg_walk(ir_graph *irg, void *pre, void *post)
   STAT_LEAVE;
 }
 
-/*
+/**
  * A walk over a graph in block-wise order is initiated. Do not count walks from statistic code.
  */
-void stat_irg_walk_blkwise(ir_graph *irg, void *pre, void *post)
+static void stat_irg_walk_blkwise(void *ctx, ir_graph *irg, void *pre, void *post)
 {
   /* for now, do NOT differentiate between blockwise and normal */
-  stat_irg_walk(irg, pre, post);
+  stat_irg_walk(ctx, irg, pre, post);
 }
 
-/*
+/**
  * A walk over the graph's blocks is initiated. Do not count walks from statistic code.
  */
-void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post)
+static void stat_irg_block_walk(void *ctx, ir_graph *irg, ir_node *node, void *pre, void *post)
 {
   if (! status->stat_options)
     return;
@@ -1073,13 +1002,14 @@ static void removed_due_opt(ir_node *n, pset *set)
   cnt_inc(&entry->count);
 }
 
-/*
+/**
  * Some nodes were optimized into some others due to an optimization
  */
-void stat_merge_nodes(
+static void stat_merge_nodes(
+    void *ctx,
     ir_node **new_node_array, int new_num_entries,
     ir_node **old_node_array, int old_num_entries,
-    stat_opt_kind opt)
+    hook_opt_kind opt)
 {
   if (! status->stat_options)
     return;
@@ -1090,7 +1020,7 @@ void stat_merge_nodes(
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
 
     if (status->reassoc_run)
-      opt = STAT_OPT_REASSOC;
+      opt = HOOK_OPT_REASSOC;
 
     for (i = 0; i < old_num_entries; ++i) {
       for (j = 0; j < new_num_entries; ++j)
@@ -1106,10 +1036,10 @@ void stat_merge_nodes(
   STAT_LEAVE;
 }
 
-/*
+/**
  * reassociation started/stopped.
  */
-void stat_reassociate(int flag)
+static void stat_reassociate(void *ctx, int flag)
 {
   if (! status->stat_options)
     return;
@@ -1121,10 +1051,10 @@ void stat_reassociate(int flag)
   STAT_LEAVE;
 }
 
-/*
+/**
  * A node was lowered into other nodes
  */
-void stat_lower(ir_node *node)
+static void stat_lower(void *ctx, ir_node *node)
 {
   if (! status->stat_options)
     return;
@@ -1133,15 +1063,15 @@ void stat_lower(ir_node *node)
   {
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
 
-    removed_due_opt(node, graph->opt_hash[STAT_LOWERED]);
+    removed_due_opt(node, graph->opt_hash[HOOK_LOWERED]);
   }
   STAT_LEAVE;
 }
 
-/*
+/**
  * A graph was inlined
  */
-void stat_inline(ir_node *call, ir_graph *called_irg)
+static void stat_inline(void *ctx, ir_node *call, ir_graph *called_irg)
 {
   if (! status->stat_options)
     return;
@@ -1158,10 +1088,10 @@ void stat_inline(ir_node *call, ir_graph *called_irg)
   STAT_LEAVE;
 }
 
-/*
+/**
  * A graph with tail-recursions was optimized.
  */
-void stat_tail_rec(ir_graph *irg)
+static void stat_tail_rec(void *ctx, ir_graph *irg)
 {
   if (! status->stat_options)
     return;
@@ -1172,10 +1102,10 @@ void stat_tail_rec(ir_graph *irg)
   STAT_LEAVE;
 }
 
-/*
+/**
  * Strength reduction was performed on an iteration variable.
  */
-void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp)
+static void stat_strength_red(void *ctx, ir_graph *irg, ir_node *strong, ir_node *cmp)
 {
   if (! status->stat_options)
     return;
@@ -1185,15 +1115,15 @@ void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp)
     graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
     cnt_inc(&graph->cnt_strength_red);
 
-    removed_due_opt(strong, graph->opt_hash[STAT_OPT_STRENGTH_RED]);
+    removed_due_opt(strong, graph->opt_hash[HOOK_OPT_STRENGTH_RED]);
   }
   STAT_LEAVE;
 }
 
-/*
+/**
  * Start the dead node elimination.
  */
-void stat_dead_node_elim_start(ir_graph *irg)
+static void stat_dead_node_elim_start(void *ctx, ir_graph *irg)
 {
   if (! status->stat_options)
     return;
@@ -1201,10 +1131,10 @@ void stat_dead_node_elim_start(ir_graph *irg)
   ++status->in_dead_node_elim;
 }
 
-/*
+/**
  * Stops the dead node elimination.
  */
-void stat_dead_node_elim_stop(ir_graph *irg)
+static void stat_dead_node_elim_stop(void *ctx, ir_graph *irg)
 {
   if (! status->stat_options)
     return;
@@ -1212,10 +1142,10 @@ void stat_dead_node_elim_stop(ir_graph *irg)
   --status->in_dead_node_elim;
 }
 
-/*
+/**
  * A multiply was replaced by a series of Shifts/Adds/Subs
  */
-void stat_arch_dep_replace_mul_with_shifts(ir_node *mul)
+static void stat_arch_dep_replace_mul_with_shifts(void *ctx, ir_node *mul)
 {
   if (! status->stat_options)
     return;
@@ -1223,7 +1153,7 @@ void stat_arch_dep_replace_mul_with_shifts(ir_node *mul)
   STAT_ENTER;
   {
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
-    removed_due_opt(mul, graph->opt_hash[STAT_OPT_ARCH_DEP]);
+    removed_due_opt(mul, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
   }
   STAT_LEAVE;
 }
@@ -1231,7 +1161,7 @@ void stat_arch_dep_replace_mul_with_shifts(ir_node *mul)
 /**
  * A division was replaced by a series of Shifts/Muls
  */
-void stat_arch_dep_replace_div_by_const(ir_node *div)
+static void stat_arch_dep_replace_div_by_const(void *ctx, ir_node *div)
 {
   if (! status->stat_options)
     return;
@@ -1239,7 +1169,7 @@ void stat_arch_dep_replace_div_by_const(ir_node *div)
   STAT_ENTER;
   {
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
-    removed_due_opt(div, graph->opt_hash[STAT_OPT_ARCH_DEP]);
+    removed_due_opt(div, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
   }
   STAT_LEAVE;
 }
@@ -1247,7 +1177,7 @@ void stat_arch_dep_replace_div_by_const(ir_node *div)
 /**
  * A modulo was replaced by a series of Shifts/Muls
  */
-void stat_arch_dep_replace_mod_by_const(ir_node *mod)
+static void stat_arch_dep_replace_mod_by_const(void *ctx, ir_node *mod)
 {
   if (! status->stat_options)
     return;
@@ -1255,7 +1185,7 @@ void stat_arch_dep_replace_mod_by_const(ir_node *mod)
   STAT_ENTER;
   {
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
-    removed_due_opt(mod, graph->opt_hash[STAT_OPT_ARCH_DEP]);
+    removed_due_opt(mod, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
   }
   STAT_LEAVE;
 }
@@ -1263,7 +1193,7 @@ void stat_arch_dep_replace_mod_by_const(ir_node *mod)
 /**
  * A DivMod was replaced by a series of Shifts/Muls
  */
-void stat_arch_dep_replace_DivMod_by_const(ir_node *divmod)
+static void stat_arch_dep_replace_DivMod_by_const(void *ctx, ir_node *divmod)
 {
   if (! status->stat_options)
     return;
@@ -1271,7 +1201,7 @@ void stat_arch_dep_replace_DivMod_by_const(ir_node *divmod)
   STAT_ENTER;
   {
     graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
-    removed_due_opt(divmod, graph->opt_hash[STAT_OPT_ARCH_DEP]);
+    removed_due_opt(divmod, graph->opt_hash[HOOK_OPT_ARCH_DEP]);
   }
   STAT_LEAVE;
 }
@@ -1351,57 +1281,104 @@ void stat_finish(const char *name)
   STAT_LEAVE;
 }
 
-#else
-
-/* need this for prototypes */
-#define FIRM_STATISTICS
-#include "firmstat.h"
-
-void init_stat(unsigned enable_options) {}
-
-void stat_finish(const char *name) {}
+static hook_entry_t stat_hooks[hook_last];
 
-void stat_new_ir_op(const ir_op *op) {}
-
-void stat_free_ir_op(const ir_op *op) {}
-
-void stat_new_node(ir_node *node) {}
+/* initialize the statistics module. */
+void init_stat(unsigned enable_options)
+{
+#define X(a)  a, sizeof(a)-1
+#define HOOK(h, fkt) \
+  stat_hooks[h].hook._##h = fkt; register_hook(h, &stat_hooks[h])
 
-void stat_turn_into_id(ir_node *node) {}
+  /* enable statistics */
+  status->stat_options = enable_options & FIRMSTAT_ENABLED ? enable_options : 0;
 
-void stat_new_graph(ir_graph *irg, entity *ent) {}
+  if (! status->stat_options)
+    return;
 
-void stat_free_graph(ir_graph *irg) {}
+  /* register all hooks */
+  HOOK(hook_new_ir_op,                        stat_new_ir_op);
+  HOOK(hook_free_ir_op,                       stat_free_ir_op);
+  HOOK(hook_new_node,                         stat_new_node);
+  HOOK(hook_turn_into_id,                     stat_turn_into_id);
+  HOOK(hook_new_graph,                        stat_new_graph);
+  HOOK(hook_free_graph,                       stat_free_graph);
+  HOOK(hook_irg_walk,                         stat_irg_walk);
+  HOOK(hook_irg_walk_blkwise,                 stat_irg_walk_blkwise);
+  HOOK(hook_irg_block_walk,                   stat_irg_block_walk);
+  HOOK(hook_merge_nodes,                      stat_merge_nodes);
+  HOOK(hook_reassociate,                      stat_reassociate);
+  HOOK(hook_lower,                            stat_lower);
+  HOOK(hook_inline,                           stat_inline);
+  HOOK(hook_tail_rec,                         stat_tail_rec);
+  HOOK(hook_strength_red,                     stat_strength_red);
+  HOOK(hook_dead_node_elim_start,             stat_dead_node_elim_start);
+  HOOK(hook_dead_node_elim_stop,              stat_dead_node_elim_stop);
+  HOOK(hook_arch_dep_replace_mul_with_shifts, stat_arch_dep_replace_mul_with_shifts);
+  HOOK(hook_arch_dep_replace_div_by_const,    stat_arch_dep_replace_div_by_const);
+  HOOK(hook_arch_dep_replace_mod_by_const,    stat_arch_dep_replace_mod_by_const);
+  HOOK(hook_arch_dep_replace_DivMod_by_const, stat_arch_dep_replace_DivMod_by_const);
 
-void stat_irg_walk(ir_graph *irg, void *pre, void *post) {}
+  obstack_init(&status->cnts);
 
-void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post) {}
+  /* create the hash-tables */
+  status->irg_hash   = new_pset(graph_cmp, 8);
+  status->ir_op_hash = new_pset(opcode_cmp_2, 1);
 
-void stat_merge_nodes(
-    ir_node **new_node_array, int new_num_entries,
-    ir_node **old_node_array, int old_num_entries,
-    stat_opt_kind opt) {}
+  /* create the wait queue */
+  status->wait_q     = new_pdeq();
 
-void stat_reassociate(int start) {}
+  if (enable_options & FIRMSTAT_COUNT_STRONG_OP) {
+    /* build the pseudo-ops */
+    _op_Phi0.code    = get_next_ir_opcode();
+    _op_Phi0.name    = new_id_from_chars(X("Phi0"));
 
-void stat_lower(ir_node *node) {}
+    _op_PhiM.code    = get_next_ir_opcode();
+    _op_PhiM.name    = new_id_from_chars(X("PhiM"));
 
-void stat_inline(ir_node *call, ir_graph *irg) {}
+    _op_ProjM.code   = get_next_ir_opcode();
+    _op_ProjM.name   = new_id_from_chars(X("ProjM"));
 
-void stat_tail_rec(ir_graph *irg) {}
+    _op_MulC.code    = get_next_ir_opcode();
+    _op_MulC.name    = new_id_from_chars(X("MulC"));
 
-void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp) {}
+    _op_DivC.code    = get_next_ir_opcode();
+    _op_DivC.name    = new_id_from_chars(X("DivC"));
 
-void stat_dead_node_elim_start(ir_graph *irg) {}
+    _op_ModC.code    = get_next_ir_opcode();
+    _op_ModC.name    = new_id_from_chars(X("ModC"));
 
-void stat_dead_node_elim_stop(ir_graph *irg) {}
+    _op_DivModC.code = get_next_ir_opcode();
+    _op_DivModC.name = new_id_from_chars(X("DivModC"));
 
-void stat_arch_dep_replace_mul_with_shifts(ir_node *mul) {}
+    status->op_Phi0    = &_op_Phi0;
+    status->op_PhiM    = &_op_PhiM;
+    status->op_ProjM   = &_op_ProjM;
+    status->op_MulC    = &_op_MulC;
+    status->op_DivC    = &_op_DivC;
+    status->op_ModC    = &_op_ModC;
+    status->op_DivModC = &_op_DivModC;
+  }
+  else {
+    status->op_Phi0    = NULL;
+    status->op_PhiM    = NULL;
+    status->op_ProjM   = NULL;
+    status->op_MulC    = NULL;
+    status->op_DivC    = NULL;
+    status->op_ModC    = NULL;
+    status->op_DivModC = NULL;
+  }
 
-void stat_arch_dep_replace_div_by_const(ir_node *div) {}
+  /* register the dumper */
+  stat_register_dumper(&simple_dumper);
 
-void stat_arch_dep_replace_mod_by_const(ir_node *mod) {}
+  if (enable_options & FIRMSTAT_CSV_OUTPUT)
+    stat_register_dumper(&csv_dumper);
 
-void stat_arch_dep_replace_DivMod_by_const(ir_node *divmod) {}
+  /* initialize the pattern hash */
+  stat_init_pattern_history(enable_options & FIRMSTAT_PATTERN_ENABLED);
+#undef HOOK
+#undef X
+}
 
-#endif
+#endif /* FIRM_STATISTICS */
index da2a34d..d2fb7ca 100644 (file)
@@ -40,29 +40,6 @@ void stat_finish(const char *name);
 
 #ifdef FIRM_STATISTICS
 
-typedef enum {
-  STAT_OPT_STG,         /**< straightening optimization */
-  STAT_OPT_IFSIM,       /**< if simplification */
-  STAT_OPT_CONST_EVAL,  /**< constant evaluation */
-  STAT_OPT_ALGSIM,      /**< algebraic simplification */
-  STAT_OPT_PHI,         /**< Phi optmization */
-  STAT_OPT_WAW,         /**< Write-After-Write optimization */
-  STAT_OPT_WAR,         /**< Write-After-Read optimization */
-  STAT_OPT_RAW,         /**< Read-After-Write optimization */
-  STAT_OPT_RAR,         /**< Read-After-Read optimization */
-  STAT_OPT_RC,          /**< Read-a-Const optimization */
-  STAT_OPT_TUPLE,              /**< Tuple optimization */
-  STAT_OPT_ID,          /**< ID optimization */
-  STAT_OPT_CSE,         /**< common subexpression elimination */
-  STAT_OPT_STRENGTH_RED,/**< strength reduction */
-  STAT_OPT_ARCH_DEP,    /**< architecture dependent optimization */
-  STAT_OPT_REASSOC,     /**< reassociation */
-  STAT_OPT_POLY_CALL,   /**< polymorphic call optimization */
-  STAT_LOWERED,         /**< lowered */
-
-  STAT_OPT_MAX
-} stat_opt_kind;
-
 /**
  * initialize the statistics module.
  *
@@ -70,149 +47,6 @@ typedef enum {
  */
 void init_stat(unsigned enable_options);
 
-/**
- * A new IR op is registered.
- */
-void stat_new_ir_op(const ir_op *op);
-
-/**
- * An IR op is freed.
- */
-void stat_free_ir_op(const ir_op *op);
-
-/**
- * A new node is created.
- */
-void stat_new_node(ir_node *node);
-
-/**
- * A node is changed into a Id node
- */
-void stat_turn_into_id(ir_node *node);
-
-/**
- * A new graph was created
- */
-void stat_new_graph(ir_graph *irg, entity *ent);
-
-/**
- * A graph was deleted
- */
-void stat_free_graph(ir_graph *irg);
-
-/**
- * A walk over a graph is initiated
- */
-void stat_irg_walk(ir_graph *irg, void *pre, void *post);
-
-/**
- * A walk over a graph in block-wise order is initiated
- */
-void stat_irg_walk_blkwise(ir_graph *irg, void *pre, void *post);
-
-/**
- * A walk over the graph's blocks is initiated
- */
-void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post);
-
-/**
- * Some nodes were optimized into some others due to an optimization
- */
-void stat_merge_nodes(
-    ir_node **new_node_array, int new_num_entries,
-    ir_node **old_node_array, int old_num_entries,
-    stat_opt_kind opt);
-
-/**
- * Reassociation of nodes started/stopped.
- */
-void stat_reassociate(int start);
-
-/**
- * A node was lowered into other nodes
- */
-void stat_lower(ir_node *node);
-
-/**
- * A graph was inlined
- */
-void stat_inline(ir_node *call, ir_graph *irg);
-
-/**
- * A graph with tail-recursions was optimized.
- */
-void stat_tail_rec(ir_graph *irg);
-
-/**
- * Strength reduction was performed on an iteration variable.
- */
-void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp);
-
-/**
- * Start the dead node elimination.
- */
-void stat_dead_node_elim_start(ir_graph *irg);
-
-/**
- * Stops the dead node elimination.
- */
-void stat_dead_node_elim_stop(ir_graph *irg);
-
-/**
- * A multiply was replaced by a series of Shifts/Adds/Subs
- */
-void stat_arch_dep_replace_mul_with_shifts(ir_node *mul);
-
-/**
- * A division was replaced by a series of Shifts/Muls
- */
-void stat_arch_dep_replace_div_by_const(ir_node *div);
-
-/**
- * A modulo was replaced by a series of Shifts/Muls
- */
-void stat_arch_dep_replace_mod_by_const(ir_node *mod);
-
-/**
- * A Divod was replaced by a series of Shifts/Muls
- */
-void stat_arch_dep_replace_DivMod_by_const(ir_node *divmod);
-
-/**
- * helper: get an ir_op from an opcode
- *
- * @param code  the opcode
- *
- * @return  The associated ir_op or NULL if the opcode could not be found.
- */
-ir_op *stat_get_op_from_opcode(opcode code);
-
-#else
-
-#define init_stat(enable_options)
-#define stat_finish(name)
-#define stat_new_ir_op(op)
-#define stat_free_ir_op(op)
-#define stat_new_node(node)
-#define stat_turn_into_id(node)
-#define stat_new_graph(irg, ent)
-#define stat_free_graph(irg)
-#define stat_irg_walk(irg, pre, post)
-#define stat_irg_walk_blkwise(irg, pre, post)
-#define stat_irg_block_walk(irg, node, pre, post)
-#define stat_merge_nodes(new_node_array, new_num_entries, old_node_array, old_num_entries, opt)
-#define stat_reassociate(start)
-#define stat_lower(node)
-#define stat_inline(call, irg)
-#define stat_tail_rec(irg)
-#define stat_strength_red(irg, strong, cmp)
-#define stat_dead_node_elim_start(irg)
-#define stat_dead_node_elim_stop(irg)
-#define stat_arch_dep_replace_mul_with_shifts(irn)
-#define stat_arch_dep_replace_div_by_const(irn)
-#define stat_arch_dep_replace_mod_by_const(irn)
-#define stat_arch_dep_replace_DivMod_by_const(irn)
-
-#endif
+#endif /* FIRM_STATISTICS */
 
 #endif /* _FIRMSTAT_H_ */
index ec167fb..63e48e1 100644 (file)
@@ -24,6 +24,7 @@
 #include "irprog.h"
 #include "irgwalk.h"
 #include "counter.h"
+#include "irhooks.h"
 
 /*
  * just be make some things clear :-), the
@@ -85,7 +86,7 @@ typedef struct _graph_entry_t {
   counter_t               cnt_edges;                   /**< number of DF edges in this graph */
   counter_t               cnt_all_calls;                /**< number of all calls */
   counter_t               cnt_indirect_calls;           /**< number of indirect calls */
-  HASH_MAP(opt_entry_t)   *opt_hash[STAT_OPT_MAX];     /**< hash maps containing opcode counter for optimizations */
+  HASH_MAP(opt_entry_t)   *opt_hash[HOOK_OPT_LAST];    /**< hash maps containing opcode counter for optimizations */
   ir_graph                *irg;                                /**< the graph of this object */
   entity                  *ent;                                /**< the entity of this graph if one exists */
   set                     *address_mark;                /**< a set containing the address marks of the nodes */
@@ -177,6 +178,10 @@ struct _dumper_t {
   dumper_t                *next;               /**< link to the next dumper */
 };
 
+/**
+ * helper: get an ir_op from an opcode
+ */
+ir_op *stat_get_op_from_opcode(opcode code);
 
 /**
  * An entry in a distribution table
index f9ee82f..3d558b0 100644 (file)
@@ -21,7 +21,7 @@
 #include "ident.h"
 #include "irop_t.h"
 #include "irmode.h"
-#include "firmstat.h"
+#include "firmstat_t.h"
 #include "pattern_dmp.h"
 
 /* dumper operations */