+/* ---------------------------------------------------------------------- */
+
+/**
+ * dumps a opcode hash into human readable form
+ */
+static void simple_dump_opcode_hash(dumper_t *dmp, pset *set)
+{
+ node_entry_t *entry;
+ counter_t f_alive;
+ counter_t f_new_node;
+ counter_t f_Id;
+
+ cnt_clr(&f_alive);
+ cnt_clr(&f_new_node);
+ cnt_clr(&f_Id);
+
+ fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id");
+ for (entry = pset_first(set); entry; entry = pset_next(set)) {
+ fprintf(dmp->f, "%-16s %8d %8d %8d\n",
+ get_id_str(entry->op->name), entry->cnt_alive.cnt[0], entry->new_node.cnt[0], entry->into_Id.cnt[0]);
+
+ cnt_add(&f_alive, &entry->cnt_alive);
+ cnt_add(&f_new_node, &entry->new_node);
+ cnt_add(&f_Id, &entry->into_Id);
+ }
+ fprintf(dmp->f, "-------------------------------------------\n");
+ fprintf(dmp->f, "%-16s %8d %8d %8d\n", "Sum",
+ f_alive.cnt[0],
+ f_new_node.cnt[0],
+ f_Id.cnt[0]);
+}
+
+/**
+ * dumps a optimization hash into human readable form
+ */
+static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index)
+{
+ opt_entry_t *entry = pset_first(set);
+
+ if (entry) {
+ fprintf(dmp->f, "\n%s:\n", opt_names[index]);
+ fprintf(dmp->f, "%-16s %-8s\n", "Opcode", "deref");
+
+ for (; entry; entry = pset_next(set)) {
+ fprintf(dmp->f, "%-16s %8d\n",
+ get_id_str(entry->op->name), entry->count.cnt[0]);
+ }
+ }
+}
+
+/**
+ * dumps the endges count
+ */
+static void simple_dump_edges(dumper_t *dmp, counter_t *cnt)
+{
+ fprintf(dmp->f, "%-16s %8d\n", "Edges", cnt->cnt[0]);
+}
+
+/**
+ * dumps the IRG
+ */
+static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
+{
+ int dump_opts = 1;
+
+ if (entry->irg) {
+ ir_graph *const_irg = get_const_code_irg();
+
+ if (entry->irg == const_irg) {
+ fprintf(dmp->f, "\nConst code Irg %p", (void *)entry->irg);
+ }
+ else {
+ if (entry->ent)
+ fprintf(dmp->f, "\nEntity %s, Irg %p", get_entity_name(entry->ent), (void *)entry->irg);
+ else
+ fprintf(dmp->f, "\nIrg %p", (void *)entry->irg);
+ }
+
+ fprintf(dmp->f, " %swalked %d over blocks %d was inlined %d got inlined %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]
+ );
+ }
+ else {
+ fprintf(dmp->f, "\nGlobals counts:\n");
+ dump_opts = 0;
+ }
+
+ simple_dump_opcode_hash(dmp, entry->opcode_hash);
+ simple_dump_edges(dmp, &entry->cnt_edges);
+
+ /* effects of optimizations */
+ if (dump_opts) {
+ int i;
+
+ for (i = 0; i < sizeof(entry->opt_hash)/sizeof(entry->opt_hash[0]); ++i) {
+ simple_dump_opt_hash(dmp, entry->opt_hash[i], i);
+ }
+ }
+}
+
+/**
+ * initialise the simple dumper
+ */
+static void simple_init(dumper_t *dmp, const char *name)
+{
+ dmp->f = fopen(name, "w");
+}
+
+/**
+ * finishes the simple dumper
+ */
+static void simple_finish(dumper_t *dmp)
+{
+ fclose(dmp->f);
+ dmp->f = NULL;
+}
+
+/**
+ * the simple human readable dumper
+ */
+static dumper_t simple_dumper = {
+ simple_dump_graph,
+ simple_init,
+ simple_finish,
+ NULL,
+ NULL,
+};
+
+/* ---------------------------------------------------------------------- */
+
+/**
+ * count the nodes as needed:
+ *
+ * 1 normal (data) Phi's
+ * 2 memory Phi's
+ * 3 Proj
+ * 0 all other nodes
+ */
+static void csv_count_nodes(graph_entry_t *graph, counter_t cnt[])
+{
+ node_entry_t *entry;
+ int i;
+
+ for (i = 0; i < 4; ++i)
+ cnt_clr(&cnt[i]);
+
+ for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
+ if (entry->op == op_Phi) {
+ /* normal Phi */
+ cnt_add(&cnt[1], &entry->cnt_alive);
+ }
+ else if (entry->op == status->op_PhiM) {
+ /* memory Phi */
+ cnt_add(&cnt[2], &entry->cnt_alive);
+ }
+ else if (entry->op == op_Proj) {
+ /* Proj */
+ cnt_add(&cnt[3], &entry->cnt_alive);
+ }
+ else {
+ /* all other nodes */
+ cnt_add(&cnt[0], &entry->cnt_alive);
+ }
+ }
+}
+
+/**
+ * dumps the IRG
+ */
+static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry)
+{
+ const char *name;
+
+ counter_t cnt[4];
+
+ if (entry->irg) {
+ ir_graph *const_irg = get_const_code_irg();
+
+ if (entry->irg == const_irg) {
+ name = "<Const code Irg>";
+ return;
+ }
+ else {
+ if (entry->ent)
+ name = get_entity_name(entry->ent);
+ else
+ name = "<UNKNOWN IRG>";
+ }
+
+ csv_count_nodes(entry, cnt);
+
+ fprintf(dmp->f, "%-40s, %p, %d, %d, %d, %d\n",
+ name,
+ entry->irg,
+ cnt[0].cnt[0],
+ cnt[1].cnt[0],
+ cnt[2].cnt[0],
+ cnt[3].cnt[0]
+ );
+ }
+}
+
+/**
+ * initialise the simple dumper
+ */
+static void csv_init(dumper_t *dmp, const char *name)
+{
+ dmp->f = fopen(name, "a");
+}
+
+/**
+ * finishes the simple dumper
+ */
+static void csv_finish(dumper_t *dmp)
+{
+ fclose(dmp->f);
+ dmp->f = NULL;
+}
+
+/**
+ * the simple human readable dumper
+ */
+static dumper_t csv_dumper = {
+ csv_dump_graph,
+ csv_init,
+ csv_finish,
+ NULL,
+ NULL,
+};
+
+