Added cnt_eq() and cnt_gt() to compare conters with unsigned values
[libfirm] / ir / stat / firmstat.c
index a4c9391..9ed5080 100644 (file)
@@ -34,16 +34,39 @@ static const char *opt_names[] = {
   "Write-After-Write optimization",
   "Write-After-Read optimization",
   "Read-After-Write optimization",
+  "Read-After-Read optimization",
   "Tuple optimization",
   "ID optimization",
   "Constant evaluation",
+  "Strength reduction",
+  "Architecture dependant optimization",
   "Lowered",
 };
 
+/*
+ * need this to be static:
+ * Special pseudo Opcodes that we need to count some interesting cases
+ */
+
 /**
- * need this to be static
+ * The Phi0, a node that is created during SSA construction
  */
-static ir_op _op_Phi0, _op_PhiM;
+static ir_op _op_Phi0;
+
+/** The PhiM, just to count memorty Phi's. */
+static ir_op _op_PhiM;
+
+/** The Mul by Const node. */
+static ir_op _op_MulC;
+
+/** The Div by Const node. */
+static ir_op _op_DivC;
+
+/** The Div by Const node. */
+static ir_op _op_ModC;
+
+/** The Div by Const node. */
+static ir_op _op_DivModC;
 
 /* ---------------------------------------------------------------------------------- */
 
@@ -172,8 +195,9 @@ static void graph_clear_entry(graph_entry_t *elem)
 {
   cnt_clr(&elem->cnt_walked);
   cnt_clr(&elem->cnt_walked_blocks);
-  cnt_clr(&elem->cnt_got_inlined);
   cnt_clr(&elem->cnt_was_inlined);
+  cnt_clr(&elem->cnt_got_inlined);
+  cnt_clr(&elem->cnt_strength_red);
   cnt_clr(&elem->cnt_edges);
 }
 
@@ -280,7 +304,7 @@ static block_entry_t *block_get_entry(long block_nr, pset *set)
  * Returns the ir_op for an IR-node,
  * handles special cases and return pseudo op codes
  */
-static ir_op *stat_get_irn_op(const ir_node *node)
+static ir_op *stat_get_irn_op(ir_node *node)
 {
   ir_op *op = get_irn_op(node);
 
@@ -292,6 +316,24 @@ static ir_op *stat_get_irn_op(const ir_node *node)
     /* special case, a Memory Phi node, count on extra counter */
     op = status->op_PhiM;
   }
+  else if (op->code == iro_Mul &&
+           (get_irn_op(get_Mul_left(node)) == op_Const || get_irn_op(get_Mul_right(node)) == op_Const)) {
+    /* special case, a Multiply by a const, count on extra counter */
+    op = status->op_MulC ? status->op_MulC : op_Mul;
+  }
+  else if (op->code == iro_Div && get_irn_op(get_Div_right(node)) == op_Const) {
+    /* special case, a division by a const, count on extra counter */
+    op = status->op_DivC ? status->op_DivC : op_Div;
+  }
+  else if (op->code == iro_Mod && get_irn_op(get_Mod_right(node)) == op_Const) {
+    /* special case, a module by a const, count on extra counter */
+    op = status->op_ModC ? status->op_ModC : op_Mod;
+  }
+  else if (op->code == iro_DivMod && get_irn_op(get_DivMod_right(node)) == op_Const) {
+    /* special case, a division/modulo by a const, count on extra counter */
+    op = status->op_DivModC ? status->op_DivModC : op_DivMod;
+  }
+
   return op;
 }
 
@@ -527,11 +569,12 @@ static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
         fprintf(dmp->f, "\nIrg %p", (void *)entry->irg);
     }
 
-    fprintf(dmp->f, " %swalked %d over blocks %d was inlined %d got inlined %d:\n",
+    fprintf(dmp->f, " %swalked %d over blocks %d was inlined %d got inlined %d strength red %d:\n",
         entry->deleted ? "DELETED " : "",
         entry->cnt_walked.cnt[0], entry->cnt_walked_blocks.cnt[0],
         entry->cnt_was_inlined.cnt[0],
-        entry->cnt_got_inlined.cnt[0]
+        entry->cnt_got_inlined.cnt[0],
+       entry->cnt_strength_red.cnt[0]
     );
   }
   else {
@@ -646,7 +689,7 @@ static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry)
 
   counter_t cnt[4];
 
-  if (entry->irg) {
+  if (entry->irg && !entry->deleted) {
     ir_graph *const_irg = get_const_code_irg();
 
     if (entry->irg == const_irg) {
@@ -737,6 +780,18 @@ void init_stat(unsigned enable_options)
   _op_PhiM.code = --pseudo_id;
   _op_PhiM.name = new_id_from_chars(X("PhiM"));
 
+  _op_MulC.code = --pseudo_id;
+  _op_MulC.name = new_id_from_chars(X("MulC"));
+
+  _op_DivC.code = --pseudo_id;
+  _op_DivC.name = new_id_from_chars(X("DivC"));
+
+  _op_ModC.code = --pseudo_id;
+  _op_ModC.name = new_id_from_chars(X("ModC"));
+
+  _op_DivModC.code = --pseudo_id;
+  _op_DivModC.name = new_id_from_chars(X("DivModC"));
+
   /* create the hash-tables */
   status->irg_hash   = new_pset(graph_cmp, 8);
   status->ir_op_hash = new_pset(opcode_cmp_2, 1);
@@ -744,6 +799,19 @@ void init_stat(unsigned enable_options)
   status->op_Phi0    = &_op_Phi0;
   status->op_PhiM    = &_op_PhiM;
 
+  if (enable_options & FIRMSTAT_COUNT_STRONG_OP) {
+    status->op_MulC    = &_op_MulC;
+    status->op_DivC    = &_op_DivC;
+    status->op_ModC    = &_op_ModC;
+    status->op_DivModC = &_op_DivModC;
+  }
+  else {
+    status->op_MulC    = NULL;
+    status->op_DivC    = NULL;
+    status->op_ModC    = NULL;
+    status->op_DivModC = NULL;
+  }
+
   stat_register_dumper(&simple_dumper);
   stat_register_dumper(&csv_dumper);
 
@@ -783,7 +851,7 @@ void stat_free_ir_op(const ir_op *op)
 }
 
 /* A new node is created. */
-void stat_new_node(const ir_node *node)
+void stat_new_node(ir_node *node)
 {
   if (! status->enable)
     return;
@@ -812,7 +880,7 @@ void stat_new_node(const ir_node *node)
 }
 
 /* A node is changed into a Id node */
-void stat_turn_into_id(const ir_node *node)
+void stat_turn_into_id(ir_node *node)
 {
   if (! status->enable)
     return;
@@ -872,7 +940,7 @@ void stat_free_graph(ir_graph *irg)
     count_nodes_in_graph(global, graph);
 
     /* count the DAG's */
-    count_dags_in_graph(global, graph);
+//    count_dags_in_graph(global, graph);
 
     /* calculate the pattern */
     stat_calc_pattern_history(irg);
@@ -928,7 +996,7 @@ void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *po
  */
 static void removed_due_opt(ir_node *n, pset *set)
 {
-  ir_op *op          = get_irn_op(n);
+  ir_op *op          = stat_get_irn_op(n);
   opt_entry_t *entry = opt_get_entry(op, set);
 
   /* increase global value */
@@ -1002,6 +1070,38 @@ 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)
+{
+  if (! status->enable)
+    return;
+
+  STAT_ENTER;
+  {
+  }
+  STAT_LEAVE;
+}
+
+/*
+ * Strength reduction was performed on an iteration variable.
+ */
+void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp)
+{
+  if (! status->enable)
+    return;
+
+  STAT_ENTER;
+  {
+    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]);
+  }
+  STAT_LEAVE;
+}
+
 /*
  * Start the dead node elimination.
  */
@@ -1024,6 +1124,22 @@ 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)
+{
+  if (! status->enable)
+    return;
+
+  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]);
+  }
+  STAT_LEAVE;
+}
+
 /* Finish the statistics */
 void stat_finish(const char *name)
 {
@@ -1050,7 +1166,7 @@ void stat_finish(const char *name)
         count_nodes_in_graph(global, entry);
 
         /* count the DAG's */
-        count_dags_in_graph(global, entry);
+//        count_dags_in_graph(global, entry);
 
         /* calculate the pattern */
         stat_calc_pattern_history(entry->irg);
@@ -1100,9 +1216,9 @@ void stat_new_ir_op(const ir_op *op) {}
 
 void stat_free_ir_op(const ir_op *op) {}
 
-void stat_new_node(const ir_node *node) {}
+void stat_new_node(ir_node *node) {}
 
-void stat_turn_into_id(const ir_node *node) {}
+void stat_turn_into_id(ir_node *node) {}
 
 void stat_new_graph(ir_graph *irg, entity *ent) {}
 
@@ -1121,8 +1237,14 @@ void stat_lower(ir_node *node) {}
 
 void stat_inline(ir_node *call, ir_graph *irg) {}
 
+void stat_tail_rec(ir_graph *irg) {}
+
+void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp) {}
+
 void stat_dead_node_elim_start(ir_graph *irg) {}
 
 void stat_dead_node_elim_stop(ir_graph *irg) {}
 
+void stat_arch_dep_replace_mul_with_shifts(ir_node *mul) {}
+
 #endif