+ if (stat_is_active()) {
+ stat_be_block_sched_ready(get_irn_irg(block), block, MIN(nodeset_count(ready_set), 5));
+ }
+}
+
+/**
+ * Pass information about a perm to the statistic module.
+ */
+void be_do_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {
+ if (stat_is_active()) {
+ stat_be_block_stat_perm(class_name, n_regs, perm, block, n, real_size);
+ }
+}
+
+/**
+ * Pass information about a cycle or chain in a perm to the statistic module.
+ */
+void be_do_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block, int is_chain, int n_elems, int n_ops) {
+ if (stat_is_active()) {
+ stat_be_block_stat_permcycle(class_name, perm, block, is_chain, n_elems, n_ops);
+ }
+}
+
+/**
+ * Updates nodes statistics.
+ */
+static void do_nodes_stat(ir_node *irn, void *env) {
+ be_stat_phase_t *phase = env;
+ ir_mode *mode;
+ opcode opc;
+ arch_irn_class_t irn_class;
+
+ if (is_Block(irn))
+ return;
+
+ mode = get_irn_mode(irn);
+ opc = get_irn_opcode(irn);
+
+ phase->num_nodes++;
+
+ /* check for nodes we want to ignore */
+ if (be_is_Keep(irn) ||
+ be_is_CopyKeep(irn) ||
+ opc == iro_Start ||
+ opc == iro_End)
+ return;
+
+ if (is_Proj(irn) && (mode != mode_X)) {
+ phase->num_proj++;
+ return;
+ }
+ else if (is_Phi(irn)) {
+ phase->num_phi++;
+ return;
+ }
+ else if (mode_is_datab(mode) || ((mode == mode_T) && ! is_be_node(irn)) || (is_Proj(irn) && (mode == mode_X)))
+ phase->num_data++;
+
+ if (opc == iro_Load)
+ phase->num_load++;
+ else if (opc == iro_Store)
+ phase->num_store++;
+
+ irn_class = arch_irn_classify(phase->arch_env, irn);
+ if (irn_class & arch_irn_class_spill)
+ phase->num_spill++;
+ else if (irn_class & arch_irn_class_reload)
+ phase->num_reload++;
+ else if (irn_class & arch_irn_class_stackparam)
+ phase->num_load++;
+ else if (irn_class & arch_irn_class_load)
+ phase->num_load++;
+ else if (irn_class & arch_irn_class_store)
+ phase->num_store++;
+}
+
+/**
+ * Collects node statistics.
+ *
+ * @param irg the to do statistics for
+ * @param phase the phase to collect the statistic for
+ */
+void be_do_stat_nodes(ir_graph *irg, const char *phase) {
+ be_stat_irg_t *irg_entry;
+ be_stat_phase_t *phase_entry, phase_key;
+
+ irg_entry = find_stat_irg_entry(irg);
+
+ if (! irg_entry)
+ return;
+
+ phase_key.phase = phase;
+ phase_entry = pset_find_ptr(irg_entry->phases, &phase_key);
+
+ if (! phase_entry) {
+ phase_entry = obstack_alloc(&irg_entry->obst, sizeof(*phase_entry));
+ phase_entry = pset_insert(irg_entry->phases, phase_entry, HASH_PTR(phase));
+ }
+ memset(phase_entry, 0, sizeof(*phase_entry));
+
+ phase_entry->phase = phase;
+ phase_entry->arch_env = irg_entry->arch_env;
+
+ irg_walk_blkwise_graph(irg_entry->irg, NULL, do_nodes_stat, phase_entry);
+}
+
+/**
+ * Dumps statistics about nodes (called from dump_snapshot)
+ */
+static void be_dump_node_stat(dumper_t *dmp, graph_entry_t *entry) {
+ be_stat_irg_t *stat_irg = find_stat_irg_entry(entry->irg);
+ be_stat_phase_t *phase;
+
+ if (! stat_irg || ! stat_irg->phases)
+ return;
+
+ fprintf(dmp->f, "===> BE NODE STATISTIC BEGIN <===\n");
+
+ foreach_pset(stat_irg->phases, phase) {
+ fprintf(dmp->f, "--> Phase: %s\n", phase->phase);
+ fprintf(dmp->f, "# nodes: %ld\n", phase->num_nodes);
+ fprintf(dmp->f, "# data nodes: %ld\n", phase->num_data);
+ fprintf(dmp->f, "# Proj: %ld\n", phase->num_proj);
+ fprintf(dmp->f, "# Phi: %ld\n", phase->num_phi);
+ fprintf(dmp->f, "# Load: %ld\n", phase->num_load);
+ fprintf(dmp->f, "# Store: %ld\n", phase->num_store);
+ fprintf(dmp->f, "# Spill: %ld\n", phase->num_spill);
+ fprintf(dmp->f, "# Reload: %ld\n", phase->num_reload);
+ }
+
+ fprintf(dmp->f, "===> BE NODE STATISTIC END <===\n");
+}
+
+/**
+ * Returns a be statistic object for the given irg.
+ */
+void be_stat_init_irg(const arch_env_t *arch_env, ir_graph *irg) {
+ static int reg_func = 1;
+
+ if (stat_is_active()) {
+ be_stat_irg_t *stat_irg;
+
+ if (! be_stat_data)
+ be_stat_data = new_set(cmp_stat_data, 8);
+
+ stat_irg = get_stat_irg_entry(irg);
+ stat_irg->irg = irg;
+ stat_irg->phases = new_pset(cmp_stat_phase, 8);
+ stat_irg->arch_env = arch_env;
+ obstack_init(&stat_irg->obst);
+
+ if (reg_func) {
+ /* first init: register dumper */
+ stat_register_dumper_func(be_dump_node_stat);
+ reg_func = 0;
+ }
+ }