+ return env.costs;
+}
+
+
+
+static const arch_env_t *arch_env;
+static be_node_stats_t *stats;
+
+static void node_stat_walker(ir_node *irn, void *data)
+{
+ (void) data;
+
+ /* if the node is a normal phi */
+ if(is_Phi(irn)) {
+ if (get_irn_mode(irn) == mode_M) {
+ (*stats)[BE_STAT_MEM_PHIS]++;
+ } else {
+ (*stats)[BE_STAT_PHIS]++;
+ }
+ } else {
+ arch_irn_class_t classify = arch_irn_classify(arch_env, irn);
+
+ if(classify & arch_irn_class_spill)
+ (*stats)[BE_STAT_SPILLS]++;
+ if(classify & arch_irn_class_reload)
+ (*stats)[BE_STAT_RELOADS]++;
+ if(classify & arch_irn_class_remat)
+ (*stats)[BE_STAT_REMATS]++;
+ if(classify & arch_irn_class_copy)
+ (*stats)[BE_STAT_COPIES]++;
+ if(classify & arch_irn_class_perm)
+ (*stats)[BE_STAT_PERMS]++;
+ }
+}
+
+void be_collect_node_stats(be_node_stats_t *new_stats, be_irg_t *birg)
+{
+ arch_env = birg->main_env->arch_env;
+ stats = new_stats;
+
+ memset(stats, 0, sizeof(*stats));
+ irg_walk_graph(birg->irg, NULL, node_stat_walker, NULL);
+}
+
+void be_subtract_node_stats(be_node_stats_t *stats, be_node_stats_t *sub)
+{
+ int i;
+ for (i = 0; i < BE_STAT_COUNT; ++i) {
+ (*stats)[i] -= (*sub)[i];
+ }
+}
+
+void be_copy_node_stats(be_node_stats_t *dest, be_node_stats_t *src)
+{
+ memcpy(dest, src, sizeof(be_node_stats_t));
+}
+
+static const char *get_stat_name(enum be_stat_tag_t tag)
+{
+ switch(tag) {
+ case BE_STAT_PHIS: return "phis";
+ case BE_STAT_MEM_PHIS: return "mem_phis";
+ case BE_STAT_COPIES: return "copies";
+ case BE_STAT_PERMS: return "perms";
+ case BE_STAT_SPILLS: return "spills";
+ case BE_STAT_RELOADS: return "reloads";
+ case BE_STAT_REMATS: return "remats";
+ default: panic("unknown stat tag found");
+ }
+}
+
+void be_emit_node_stats(be_node_stats_t *stats, const char *prefix)
+{
+ static char buf[256];
+ int i;
+
+ for (i = 0; i < BE_STAT_COUNT; ++i) {
+ snprintf(buf, sizeof(buf), "%s%s", prefix, get_stat_name(i));
+ stat_ev_dbl(buf, (*stats)[i]);
+ }
+}
+
+
+
+static void insn_count_walker(ir_node *irn, void *data)
+{
+ unsigned long *cnt = data;
+
+ switch(get_irn_opcode(irn)) {
+ case iro_Proj:
+ case iro_Phi:
+ case iro_Start:
+ case iro_End:
+ break;
+ default:
+ (*cnt)++;
+ }
+}
+
+unsigned long be_count_insns(ir_graph *irg)
+{
+ unsigned long cnt = 0;
+ irg_walk_graph(irg, insn_count_walker, NULL, &cnt);
+ return cnt;
+}
+
+static void block_count_walker(ir_node *node, void *data)
+{
+ unsigned long *cnt = data;
+ if (node == get_irg_end_block(current_ir_graph))
+ return;
+ (*cnt)++;
+}
+
+unsigned long be_count_blocks(ir_graph *irg)
+{
+ unsigned long cnt = 0;
+ irg_block_walk_graph(irg, block_count_walker, NULL, &cnt);
+ return cnt;
+}