pressure stats
authorAdam Szalkowski <adam@ipd.info.uni-karlsruhe.de>
Fri, 9 Jun 2006 09:06:18 +0000 (09:06 +0000)
committerAdam Szalkowski <adam@ipd.info.uni-karlsruhe.de>
Fri, 9 Jun 2006 09:06:18 +0000 (09:06 +0000)
ir/be/Makefile.in
ir/be/bepressurestat.c [new file with mode: 0644]
ir/be/bepressurestat.h [new file with mode: 0644]
ir/be/bespillremat.c

index 80d004d..15920fb 100644 (file)
@@ -31,10 +31,11 @@ SOURCES +=  Makefile.in besched.h belistsched.h belistsched.c \
        beabi.c beabi.h beabi_t.h benodesets.c benodesets.h \
        bemachnode.c bemachnode.h beinsn.c bestat.h bestat.c \
        beschedmris.h beschedmris.c bespillmorgan.c bespillmorgan.h \
-       beverify.h beverify.c bespillremat.c \
+       beverify.h beverify.c bespillremat.c bepressurestat.c bepressurestat.h \
        bespillappel.c bessadestrsimple.c beifg_clique.c beifg_list.c beifg_pointer.c
 
 
+
 include $(topdir)/MakeRules
 
 CPPFLAGS +=    -I$(top_srcdir)/ir/adt   -I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common  \
diff --git a/ir/be/bepressurestat.c b/ir/be/bepressurestat.c
new file mode 100644 (file)
index 0000000..0eb07db
--- /dev/null
@@ -0,0 +1,138 @@
+/** vim: set sw=4 ts=4:
+ * @file   bepressurestat.c
+ * @date   2006-04-06
+ * @author Adam M. Szalkowski
+ *
+ * Register Pressure Statistics
+ *
+ * Copyright (C) 2006 Universitaet Karlsruhe
+ * Released under the GPL
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <math.h>
+
+#include "hashptr.h"
+#include "debug.h"
+#include "obst.h"
+#include "set.h"
+#include "list.h"
+#include "pmap.h"
+
+#include "irprintf.h"
+#include "irgwalk.h"
+#include "irdump_t.h"
+#include "irnode_t.h"
+#include "ircons_t.h"
+#include "irloop_t.h"
+#include "phiclass.h"
+#include "iredges.h"
+#include "execfreq.h"
+
+#include <libcore/lc_bitset.h>
+
+#include "be_t.h"
+#include "belive_t.h"
+#include "besched_t.h"
+#include "beirgmod.h"
+#include "bearch.h"
+#include "benode_t.h"
+#include "beutil.h"
+#include "bespillremat.h"
+#include "bespill.h"
+
+#include "bechordal_t.h"
+
+#define MAXPRESSURE 128
+
+typedef struct _regpressure_ana_t {
+       const arch_register_class_t  *cls;
+       const be_chordal_env_t       *chordal_env;
+       unsigned int                 *stat;
+       DEBUG_ONLY(firm_dbg_module_t * dbg);
+} regpressure_ana_t;
+
+static INLINE int
+has_reg_class(const regpressure_ana_t * ra, const ir_node * irn)
+{
+       return chordal_has_class(ra->chordal_env, irn);
+}
+
+static INLINE int
+regpressure(pset * live)
+{
+       int pressure = pset_count(live);
+
+       return (pressure>MAXPRESSURE)?MAXPRESSURE:pressure;
+}
+
+static void
+regpressureanawalker(ir_node * bb, void * data)
+{
+  regpressure_ana_t  *ra = data;
+  pset               *live = pset_new_ptr_default();
+  const ir_node      *irn;
+  irn_live_t         *li;
+  unsigned int       *stat = ra->stat;
+  int                 i;
+
+  live_foreach(bb, li) {
+    ir_node        *value = (ir_node *) li->irn;
+
+    if (live_is_end(li) && has_reg_class(ra, value)) {
+      pset_insert_ptr(live, value);
+    }
+  }
+  stat[regpressure(live)]++;
+
+  sched_foreach_reverse(bb, irn) {
+
+    if(is_Phi(irn)) break;
+
+    if(has_reg_class(ra, irn)) {
+      pset_remove_ptr(live, irn);
+    }
+
+    for(i=get_irn_arity(irn)-1; i>=0; --i) {
+      ir_node  *arg = get_irn_n(irn, i);
+
+      if(has_reg_class(ra, arg)) {
+                 pset_insert_ptr(live, arg);
+      }
+    }
+
+    if(!is_Proj(irn)) stat[regpressure(live)]++;
+  }
+}
+
+void
+be_analyze_regpressure(const be_chordal_env_t * chordal_env, const char * suffix)
+{
+  regpressure_ana_t   ra;
+  unsigned int        stat[MAXPRESSURE+1];
+  unsigned int        i;
+  char                fname[256];
+  FILE               *f;
+
+  ir_snprintf(fname, sizeof(fname), "%F_%s%s_pressure.stat", chordal_env->irg, chordal_env->cls->name, suffix);
+  f = fopen(fname, "w");
+  assert(f);
+
+  FIRM_DBG_REGISTER(ra.dbg, "firm.be.regpressureana");
+
+  ra.chordal_env = chordal_env;
+  ra.cls = chordal_env->cls;
+  ra.stat = stat;
+
+  memset(stat, 0, sizeof(stat));
+
+  irg_block_walk_graph(chordal_env->irg, regpressureanawalker, NULL, &ra);
+
+  for(i=0; i<=MAXPRESSURE; ++i) {
+    fprintf(f,"%d\n",stat[i]);
+  }
+
+  fclose(f);
+}
diff --git a/ir/be/bepressurestat.h b/ir/be/bepressurestat.h
new file mode 100644 (file)
index 0000000..a2bb0e6
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef PRESSURE_STAT_H_
+#define PRESSURE_STAT_H_
+
+void
+be_analyze_regpressure(const be_chordal_env_t * chordal_env, const char * suffix);
+
+#endif
index 3efbf99..e86bbcb 100644 (file)
@@ -48,6 +48,7 @@
 #include "beutil.h"
 #include "bespillremat.h"
 #include "bespill.h"
+#include "bepressurestat.h"
 
 #include "bechordal_t.h"
 
@@ -2999,6 +3000,8 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
        set_irg_link(chordal_env->irg, &si);
        compute_doms(chordal_env->irg);
 
+       be_analyze_regpressure(chordal_env, "-pre");
+
 #ifdef COLLECT_REMATS
        /* collect remats */
        DBG((si.dbg, LEVEL_1, "Collecting remats\n"));
@@ -3101,6 +3104,8 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
        irg_block_walk_graph(chordal_env->irg, walker_pressure_annotator, NULL, &si);
        dump_pressure_graph(&si, dump_suffix3);
 
+       be_analyze_regpressure(chordal_env, "-post");
+
        free_dom(chordal_env->irg);
        del_pset(si.inverse_ops);
        del_pset(si.all_possible_remats);