don't crash if a Const node has no tarval set yet
[libfirm] / ir / stat / firmstat.c
index c3ede63..7eb9047 100644 (file)
@@ -148,7 +148,7 @@ static int reg_pressure_cmp(const void *elt, const void *key)
   const reg_pressure_entry_t *e1 = elt;
   const reg_pressure_entry_t *e2 = key;
 
-  return e1->id_name != e2->id_name;
+  return e1->class_name != e2->class_name;
 }
 
 /**
@@ -170,7 +170,7 @@ static int perm_class_cmp(const void *elt, const void *key)
   const perm_class_entry_t *e1 = elt;
   const perm_class_entry_t *e2 = key;
 
-  return e1->id_name != e2->id_name;
+  return e1->class_name != e2->class_name;
 }
 
 /**
@@ -463,17 +463,18 @@ static void perm_class_clear_entry(perm_class_entry_t *elem) {
 /**
  * Returns the associated perm_class entry for a register class.
  *
- * @param cls_id    the register class ident
- * @param hmap      a hash map containing class_name -> perm_class_entry_t
+ * @param class_name  the register class name
+ * @param hmap        a hash map containing class_name -> perm_class_entry_t
  */
-static perm_class_entry_t *perm_class_get_entry(struct obstack *obst, ident *cls_id, hmap_perm_class_entry_t *hmap)
+static perm_class_entry_t *perm_class_get_entry(struct obstack *obst, const char *class_name,
+                                                hmap_perm_class_entry_t *hmap)
 {
   perm_class_entry_t key;
   perm_class_entry_t *elem;
 
-  key.id_name = cls_id;
+  key.class_name = class_name;
 
-  elem = pset_find(hmap, &key, HASH_PTR(cls_id));
+  elem = pset_find(hmap, &key, HASH_PTR(class_name));
   if (elem)
     return elem;
 
@@ -483,9 +484,9 @@ static perm_class_entry_t *perm_class_get_entry(struct obstack *obst, ident *cls
   /* clear new counter */
   perm_class_clear_entry(elem);
 
-  elem->id_name = cls_id;
+  elem->class_name = class_name;
 
-  return pset_insert(hmap, elem, HASH_PTR(cls_id));
+  return pset_insert(hmap, elem, HASH_PTR(class_name));
 }
 
 /**
@@ -1658,47 +1659,45 @@ static void stat_arch_dep_replace_division_by_const(void *ctx, ir_node *node)
   STAT_LEAVE;
 }
 
-/**
+/*
  * Update the register pressure of a block
  *
- * @param ctx        the hook context
- * @param block      the block for which the reg pressure should be set
  * @param irg        the irg containing the block
+ * @param block      the block for which the reg pressure should be set
  * @param pressure   the pressure
- * @param class_name the ident name of the register class
+ * @param class_name the name of the register class
  */
-static void stat_be_block_regpressure(void *ctx, ir_node *block, ir_graph *irg, int pressure, ident *class_name)
+void stat_be_block_regpressure(ir_graph *irg, ir_node *block, int pressure, const char *class_name)
 {
-  if (! status->stat_options)
-    return;
+       if (! status->stat_options)
+               return;
 
-  STAT_ENTER;
-  {
-    graph_entry_t        *graph = graph_get_entry(irg, status->irg_hash);
-    be_block_entry_t     *block_ent;
-    reg_pressure_entry_t *rp_ent;
+       STAT_ENTER;
+       {
+               graph_entry_t        *graph = graph_get_entry(irg, status->irg_hash);
+               be_block_entry_t     *block_ent;
+               reg_pressure_entry_t *rp_ent;
 
-    block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
-       rp_ent    = obstack_alloc(&status->be_data, sizeof(*rp_ent));
-       memset(rp_ent, 0, sizeof(*rp_ent));
+               block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
+               rp_ent    = obstack_alloc(&status->be_data, sizeof(*rp_ent));
+               memset(rp_ent, 0, sizeof(*rp_ent));
 
-       rp_ent->id_name  = class_name;
-    rp_ent->pressure = pressure;
+               rp_ent->class_name = class_name;
+               rp_ent->pressure   = pressure;
 
-    pset_insert(block_ent->reg_pressure, rp_ent, HASH_PTR(class_name));
-  }
-  STAT_LEAVE;
+               pset_insert(block_ent->reg_pressure, rp_ent, HASH_PTR(class_name));
+       }
+       STAT_LEAVE;
 }
 
 /**
  * Update the distribution of ready nodes of a block
  *
- * @param ctx        the hook context
- * @param block      the block for which the reg pressure should be set
  * @param irg        the irg containing the block
+ * @param block      the block for which the reg pressure should be set
  * @param num_ready  the number of ready nodes
  */
-static void stat_be_block_sched_ready(void *ctx, ir_node *block, ir_graph *irg, int num_ready)
+void stat_be_block_sched_ready(ir_graph *irg, ir_node *block, int num_ready)
 {
   if (! status->stat_options)
     return;
@@ -1707,12 +1706,11 @@ static void stat_be_block_sched_ready(void *ctx, ir_node *block, ir_graph *irg,
   {
     graph_entry_t    *graph = graph_get_entry(irg, status->irg_hash);
     be_block_entry_t *block_ent;
-       const counter_t  *cnt_1 = cnt_get_1();
 
     block_ent = be_block_get_entry(&status->be_data, get_irn_node_nr(block), graph->be_block_hash);
 
-    /* add 1 to the counter of corresponding number of ready nodes */
-       stat_add_int_distrib_tbl(block_ent->sched_ready, num_ready, cnt_1);
+    /* increase the counter of corresponding number of ready nodes */
+       stat_inc_int_distrib_tbl(block_ent->sched_ready, num_ready);
   }
   STAT_LEAVE;
 }
@@ -1720,14 +1718,14 @@ static void stat_be_block_sched_ready(void *ctx, ir_node *block, ir_graph *irg,
 /**
  * Update the permutation statistic of a block
  *
- * @param ctx        the hook context
- * @param class_name the ident name of the register class
+ * @param class_name the name of the register class
+ * @param n_regs     number of registers in the register class
  * @param perm       the perm node
  * @param block      the block containing the perm
  * @param size       the size of the perm
  * @param real_size  number of pairs with different registers
  */
-void stat_be_block_stat_perm(void *ctx, ident *class_name, int n_regs, ir_node *perm, ir_node *block,
+void stat_be_block_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block,
                              int size, int real_size)
 {
   if (! status->stat_options)
@@ -1756,14 +1754,14 @@ void stat_be_block_stat_perm(void *ctx, ident *class_name, int n_regs, ir_node *
 /**
  * Update the permutation statistic of a single perm
  *
- * @param ctx        the hook context
- * @param class_name the ident name of the register class
+ * @param class_name the name of the register class
  * @param perm       the perm node
  * @param block      the block containing the perm
  * @param is_chain   1 if chain, 0 if cycle
+ * @param size       length of the cycle/chain
  * @param n_ops      the number of ops representing this cycle/chain after lowering
  */
-void stat_be_block_stat_permcycle(void *ctx, ident *class_name, ir_node *perm, ir_node *block,
+void stat_be_block_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block,
                                   int is_chain, int size, int n_ops)
 {
   if (! status->stat_options)
@@ -1772,7 +1770,6 @@ void stat_be_block_stat_permcycle(void *ctx, ident *class_name, ir_node *perm, i
   STAT_ENTER;
   {
     graph_entry_t      *graph = graph_get_entry(get_irn_irg(block), status->irg_hash);
-       const counter_t    *cnt_1 = cnt_get_1();
     be_block_entry_t   *block_ent;
     perm_class_entry_t *pc_ent;
     perm_stat_entry_t  *ps_ent;
@@ -1783,11 +1780,11 @@ void stat_be_block_stat_permcycle(void *ctx, ident *class_name, ir_node *perm, i
 
     if (is_chain) {
       ps_ent->n_copies += n_ops;
-      stat_add_int_distrib_tbl(ps_ent->chains, size, cnt_1);
+      stat_inc_int_distrib_tbl(ps_ent->chains, size);
     }
     else {
       ps_ent->n_exchg += n_ops;
-      stat_add_int_distrib_tbl(ps_ent->cycles, size, cnt_1);
+      stat_inc_int_distrib_tbl(ps_ent->cycles, size);
     }
   }
   STAT_LEAVE;
@@ -1956,10 +1953,6 @@ void firm_init_stat(unsigned enable_options)
   HOOK(hook_func_call,                          stat_func_call);
   HOOK(hook_arch_dep_replace_mul_with_shifts,   stat_arch_dep_replace_mul_with_shifts);
   HOOK(hook_arch_dep_replace_division_by_const, stat_arch_dep_replace_division_by_const);
-  HOOK(hook_be_block_regpressure,               stat_be_block_regpressure);
-  HOOK(hook_be_block_sched_ready,               stat_be_block_sched_ready);
-  HOOK(hook_be_block_stat_perm,                 stat_be_block_stat_perm);
-  HOOK(hook_be_block_stat_permcycle,            stat_be_block_stat_permcycle);
 
   obstack_init(&status->cnts);
   obstack_init(&status->be_data);
@@ -2055,6 +2048,11 @@ void stat_term(void) {
   }
 }
 
+/* returns 1 if statistics were initialized, 0 otherwise */
+int stat_is_active(void) {
+  return status != (stat_info_t *)&status_disable;
+}
+
 #else
 
 /* initialize the statistics module. */