3 * File name: ir/ir/firmstat.c
4 * Purpose: Statistics for Firm.
8 * Copyright: (c) 2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 #ifdef FIRM_STATISTICS
22 #include "firmstat_t.h"
27 * names of the optimizations
29 static const char *opt_names[] = {
30 "straightening optimization",
32 "algebraic simplification",
34 "Write-After-Write optimization",
35 "Write-After-Read optimization",
36 "Read-After-Write optimization",
37 "Read-After-Read optimization",
40 "Constant evaluation",
41 "Common subexpression elimination",
43 "Architecture dependant optimization",
48 * need this to be static:
49 * Special pseudo Opcodes that we need to count some interesting cases
53 * The Phi0, a node that is created during SSA construction
55 static ir_op _op_Phi0;
57 /** The PhiM, just to count memorty Phi's. */
58 static ir_op _op_PhiM;
60 /** The Mul by Const node. */
61 static ir_op _op_MulC;
63 /** The Div by Const node. */
64 static ir_op _op_DivC;
66 /** The Div by Const node. */
67 static ir_op _op_ModC;
69 /** The Div by Const node. */
70 static ir_op _op_DivModC;
72 /* ---------------------------------------------------------------------------------- */
74 #define STAT_ENTER ++status->recursive
75 #define STAT_LEAVE --status->recursive
76 #define STAT_ENTER_SINGLE do { if (status->recursive > 0) return; ++status->recursive; } while (0)
81 static stat_info_t _status, *status = &_status;
84 * compare two elements of the opcode hash
86 static int opcode_cmp(const void *elt, const void *key)
88 const node_entry_t *e1 = elt;
89 const node_entry_t *e2 = key;
91 return e1->op->code - e2->op->code;
95 * compare two elements of the graph hash
97 static int graph_cmp(const void *elt, const void *key)
99 const graph_entry_t *e1 = elt;
100 const graph_entry_t *e2 = key;
102 return e1->irg != e2->irg;
106 * compare two elements of the optimization hash
108 static int opt_cmp(const void *elt, const void *key)
110 const opt_entry_t *e1 = elt;
111 const opt_entry_t *e2 = key;
113 return e1->op->code != e2->op->code;
117 * compare two elements of the block hash
119 static int block_cmp(const void *elt, const void *key)
121 const block_entry_t *e1 = elt;
122 const block_entry_t *e2 = key;
124 return e1->block_nr != e2->block_nr;
128 * compare two elements of the ir_op hash
130 static int opcode_cmp_2(const void *elt, const void *key)
132 const ir_op *e1 = elt;
133 const ir_op *e2 = key;
135 return e1->code != e2->code;
139 * clears all counter in a node_entry_t
141 static void opcode_clear_entry(node_entry_t *elem)
143 cnt_clr(&elem->cnt_alive);
144 cnt_clr(&elem->new_node);
145 cnt_clr(&elem->into_Id);
149 * Returns the associates node_entry_t for an ir_op
151 static node_entry_t *opcode_get_entry(const ir_op *op, pset *set)
158 elem = pset_find(set, &key, op->code);
162 elem = obstack_alloc(&status->cnts, sizeof(*elem));
165 opcode_clear_entry(elem);
169 return pset_insert(set, elem, op->code);
173 * Returns the associates ir_op for an opcode
175 static ir_op *opcode_find_entry(opcode code, pset *set)
180 return pset_find(set, &key, code);
184 * calculates a hash value for an irg
185 * Addresses are typically aligned at 32bit, so we ignore the lowest bits
187 static INLINE unsigned irg_hash(const ir_graph *irg)
189 return (unsigned)irg >> 3;
193 * clears all counter in a graph_entry_t
195 static void graph_clear_entry(graph_entry_t *elem)
197 cnt_clr(&elem->cnt_walked);
198 cnt_clr(&elem->cnt_walked_blocks);
199 cnt_clr(&elem->cnt_was_inlined);
200 cnt_clr(&elem->cnt_got_inlined);
201 cnt_clr(&elem->cnt_strength_red);
202 cnt_clr(&elem->cnt_edges);
206 * Returns the acssociates graph_entry_t for an irg
208 static graph_entry_t *graph_get_entry(ir_graph *irg, pset *set)
216 elem = pset_find(set, &key, irg_hash(irg));
220 elem = obstack_alloc(&status->cnts, sizeof(*elem));
223 graph_clear_entry(elem);
225 /* new hash table for opcodes here */
226 elem->opcode_hash = new_pset(opcode_cmp, 5);
227 elem->block_hash = new_pset(block_cmp, 5);
230 for (i = 0; i < sizeof(elem->opt_hash)/sizeof(elem->opt_hash[0]); ++i)
231 elem->opt_hash[i] = new_pset(opt_cmp, 4);
233 return pset_insert(set, elem, irg_hash(irg));
237 * clears all counter in an opt_entry_t
239 static void opt_clear_entry(opt_entry_t *elem)
241 cnt_clr(&elem->count);
245 * Returns the associates opt_entry_t for an ir_op
247 static opt_entry_t *opt_get_entry(const ir_op *op, pset *set)
254 elem = pset_find(set, &key, op->code);
258 elem = obstack_alloc(&status->cnts, sizeof(*elem));
260 /* clear new counter */
261 opt_clear_entry(elem);
265 return pset_insert(set, elem, op->code);
269 * clears all counter in a block_entry_t
271 static void block_clear_entry(block_entry_t *elem)
273 cnt_clr(&elem->cnt_nodes);
274 cnt_clr(&elem->cnt_edges);
275 cnt_clr(&elem->cnt_in_edges);
276 cnt_clr(&elem->cnt_out_edges);
280 * Returns the associates block_entry_t for an block
282 static block_entry_t *block_get_entry(long block_nr, pset *set)
287 key.block_nr = block_nr;
289 elem = pset_find(set, &key, block_nr);
293 elem = obstack_alloc(&status->cnts, sizeof(*elem));
295 /* clear new counter */
296 block_clear_entry(elem);
298 elem->block_nr = block_nr;
300 return pset_insert(set, elem, block_nr);
305 * Returns the ir_op for an IR-node,
306 * handles special cases and return pseudo op codes
308 static ir_op *stat_get_irn_op(ir_node *node)
310 ir_op *op = get_irn_op(node);
312 if (op->code == iro_Phi && get_irn_arity(node) == 0) {
313 /* special case, a Phi0 node, count on extra counter */
314 op = status->op_Phi0;
316 else if (op->code == iro_Phi && get_irn_mode(node) == mode_M) {
317 /* special case, a Memory Phi node, count on extra counter */
318 op = status->op_PhiM;
320 else if (op->code == iro_Mul &&
321 (get_irn_op(get_Mul_left(node)) == op_Const || get_irn_op(get_Mul_right(node)) == op_Const)) {
322 /* special case, a Multiply by a const, count on extra counter */
323 op = status->op_MulC ? status->op_MulC : op_Mul;
325 else if (op->code == iro_Div && get_irn_op(get_Div_right(node)) == op_Const) {
326 /* special case, a division by a const, count on extra counter */
327 op = status->op_DivC ? status->op_DivC : op_Div;
329 else if (op->code == iro_Mod && get_irn_op(get_Mod_right(node)) == op_Const) {
330 /* special case, a module by a const, count on extra counter */
331 op = status->op_ModC ? status->op_ModC : op_Mod;
333 else if (op->code == iro_DivMod && get_irn_op(get_DivMod_right(node)) == op_Const) {
334 /* special case, a division/modulo by a const, count on extra counter */
335 op = status->op_DivModC ? status->op_DivModC : op_DivMod;
342 * update the block counter
344 static void count_block_info(ir_node *node, graph_entry_t *graph)
346 ir_op *op = get_irn_op(node);
348 block_entry_t *b_entry;
351 /* check for block */
352 if (op == op_Block) {
353 arity = get_irn_arity(node);
354 b_entry = block_get_entry(get_irn_node_nr(node), graph->block_hash);
356 /* count all incoming edges */
357 for (i = 0; i < arity; ++i) {
358 ir_node *pred = get_irn_n(node, i);
359 ir_node *other_block = get_nodes_block(pred);
360 block_entry_t *b_entry_other = block_get_entry(get_irn_node_nr(other_block), graph->block_hash);
362 cnt_inc(&b_entry->cnt_in_edges); /* an edge coming from another block */
363 cnt_inc(&b_entry_other->cnt_out_edges);
367 else if (op == op_Call) {
371 block = get_nodes_block(node);
372 b_entry = block_get_entry(get_irn_node_nr(block), graph->block_hash);
374 /* we have a new nodes */
375 cnt_inc(&b_entry->cnt_nodes);
377 arity = get_irn_arity(node);
379 for (i = 0; i < arity; ++i) {
380 ir_node *pred = get_irn_n(node, i);
381 ir_node *other_block;
383 if (get_irn_op(pred) == op_Block)
386 other_block = get_nodes_block(pred);
388 if (other_block == block)
389 cnt_inc(&b_entry->cnt_edges); /* a in block edge */
391 block_entry_t *b_entry_other = block_get_entry(get_irn_node_nr(other_block), graph->block_hash);
393 cnt_inc(&b_entry->cnt_in_edges); /* an edge coming from another block */
394 cnt_inc(&b_entry_other->cnt_out_edges);
400 * update info on calls
402 static void count_call(ir_node *call, graph_entry_t *graph)
404 ir_node *ptr = get_Call_ptr(call);
407 /* found a call, is not a leaf function */
410 if (get_irn_op(ptr) == op_SymConst) {
411 if (get_SymConst_kind(ptr) == symconst_addr_ent) {
412 /* ok, we seems to know the entity */
413 ent = get_SymConst_entity(ptr);
415 if (get_entity_irg(ent) == graph->irg)
416 graph->is_recursive = 1;
420 /* check, if it's a chain-call */
422 ir_node *curr = get_irg_end_block(graph->irg);
423 ir_node *block = get_nodes_block(call);
424 int depth = get_Block_dom_depth(block);
426 for (; curr != block && get_Block_dom_depth(curr) > depth;) {
427 curr = get_Block_idom(curr);
429 if (! curr || is_no_Block(curr))
434 graph->is_chain_call = 0;
439 * walker for reachable nodes count
441 static void count_nodes(ir_node *node, void *env)
443 graph_entry_t *graph = env;
446 ir_op *op = stat_get_irn_op(node);
447 int arity = get_irn_arity(node);
449 entry = opcode_get_entry(op, graph->opcode_hash);
451 cnt_inc(&entry->cnt_alive);
452 cnt_add_i(&graph->cnt_edges, arity);
454 /* count block edges */
455 count_block_info(node, graph);
457 /* check for leaf functions */
458 if (get_irn_op(node) == op_Call)
459 count_call(node, graph);
463 * count all alive nodes and edges in a graph
465 static void count_nodes_in_graph(graph_entry_t *global, graph_entry_t *graph)
469 /* clear first the alive counter in the graph */
470 for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
471 cnt_clr(&entry->cnt_alive);
474 /* set pessimistic values */
476 graph->is_recursive = 0;
477 graph->is_chain_call = 1;
479 /* we need dominance info */
480 if (graph->irg != get_const_code_irg())
481 compute_doms(graph->irg);
483 /* count the nodes in the graph */
484 irg_walk_graph(graph->irg, count_nodes, NULL, graph);
487 entry = opcode_get_entry(op_Call, graph->opcode_hash);
489 /* check if we have more than 1 call */
490 if (cnt_gt(entry->cnt_alive, 1))
491 graph->is_chain_call = 0;
494 /* recursive functions are never chain calls, leafs don't have calls */
495 if (graph->is_recursive || graph->is_leaf)
496 graph->is_chain_call = 0;
498 /* assume we walk every graph only ONCE, we could sum here the global count */
499 for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
500 node_entry_t *g_entry = opcode_get_entry(entry->op, global->opcode_hash);
502 /* update the node counter */
503 cnt_add(&g_entry->cnt_alive, &entry->cnt_alive);
506 /* update the edge counter */
507 cnt_add(&global->cnt_edges, &graph->cnt_edges);
513 static void stat_register_dumper(dumper_t *dumper)
515 dumper->next = status->dumper;
516 status->dumper = dumper;
522 static void dump_graph(graph_entry_t *entry)
526 for (dumper = status->dumper; dumper; dumper = dumper->next) {
527 if (dumper->dump_graph)
528 dumper->dump_graph(dumper, entry);
533 * initialise the dumper
535 static void dump_init(const char *name)
539 for (dumper = status->dumper; dumper; dumper = dumper->next) {
541 dumper->init(dumper, name);
548 static void dump_finish(void)
552 for (dumper = status->dumper; dumper; dumper = dumper->next) {
554 dumper->finish(dumper);
558 /* ---------------------------------------------------------------------- */
561 * dumps a opcode hash into human readable form
563 static void simple_dump_opcode_hash(dumper_t *dmp, pset *set)
567 counter_t f_new_node;
571 cnt_clr(&f_new_node);
574 fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id");
575 for (entry = pset_first(set); entry; entry = pset_next(set)) {
576 fprintf(dmp->f, "%-16s %8d %8d %8d\n",
577 get_id_str(entry->op->name), entry->cnt_alive.cnt[0], entry->new_node.cnt[0], entry->into_Id.cnt[0]);
579 cnt_add(&f_alive, &entry->cnt_alive);
580 cnt_add(&f_new_node, &entry->new_node);
581 cnt_add(&f_Id, &entry->into_Id);
583 fprintf(dmp->f, "-------------------------------------------\n");
584 fprintf(dmp->f, "%-16s %8d %8d %8d\n", "Sum",
591 * dumps a optimization hash into human readable form
593 static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index)
595 opt_entry_t *entry = pset_first(set);
598 fprintf(dmp->f, "\n%s:\n", opt_names[index]);
599 fprintf(dmp->f, "%-16s %-8s\n", "Opcode", "deref");
601 for (; entry; entry = pset_next(set)) {
602 fprintf(dmp->f, "%-16s %8d\n",
603 get_id_str(entry->op->name), entry->count.cnt[0]);
609 * dumps the endges count
611 static void simple_dump_edges(dumper_t *dmp, counter_t *cnt)
613 fprintf(dmp->f, "%-16s %8d\n", "Edges", cnt->cnt[0]);
619 static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
622 block_entry_t *b_entry;
625 ir_graph *const_irg = get_const_code_irg();
627 if (entry->irg == const_irg) {
628 fprintf(dmp->f, "\nConst code Irg %p", (void *)entry->irg);
632 fprintf(dmp->f, "\nEntity %s, Irg %p", get_entity_name(entry->ent), (void *)entry->irg);
634 fprintf(dmp->f, "\nIrg %p", (void *)entry->irg);
637 fprintf(dmp->f, " %swalked %d over blocks %d:\n"
640 " strength red: %d\n"
641 " leaf function: %s\n"
643 " chain call : %s\n",
644 entry->is_deleted ? "DELETED " : "",
645 entry->cnt_walked.cnt[0], entry->cnt_walked_blocks.cnt[0],
646 entry->cnt_was_inlined.cnt[0],
647 entry->cnt_got_inlined.cnt[0],
648 entry->cnt_strength_red.cnt[0],
649 entry->is_leaf ? "YES" : "NO",
650 entry->is_recursive ? "YES" : "NO",
651 entry->is_chain_call ? "YES" : "NO"
655 fprintf(dmp->f, "\nGlobals counts:\n");
656 fprintf(dmp->f, "--------------\n");
660 simple_dump_opcode_hash(dmp, entry->opcode_hash);
661 simple_dump_edges(dmp, &entry->cnt_edges);
663 /* effects of optimizations */
667 for (i = 0; i < sizeof(entry->opt_hash)/sizeof(entry->opt_hash[0]); ++i) {
668 simple_dump_opt_hash(dmp, entry->opt_hash[i], i);
671 /* dump block info */
672 fprintf(dmp->f, "\n%12s %12s %12s %12s %12s %12s\n", "Block Nr", "Nodes", "intern E", "incoming E", "outgoing E", "quot");
673 for (b_entry = pset_first(entry->block_hash);
675 b_entry = pset_next(entry->block_hash)) {
676 fprintf(dmp->f, "BLK %12ld %12u %12u %12u %12u %4.8f\n",
678 b_entry->cnt_nodes.cnt[0],
679 b_entry->cnt_edges.cnt[0],
680 b_entry->cnt_in_edges.cnt[0],
681 b_entry->cnt_out_edges.cnt[0],
682 (double)b_entry->cnt_edges.cnt[0] / (double)b_entry->cnt_nodes.cnt[0]
689 * initialise the simple dumper
691 static void simple_init(dumper_t *dmp, const char *name)
695 snprintf(fname, sizeof(fname), "%s.txt", name);
696 dmp->f = fopen(fname, "w");
700 * finishes the simple dumper
702 static void simple_finish(dumper_t *dmp)
709 * the simple human readable dumper
711 static dumper_t simple_dumper = {
719 /* ---------------------------------------------------------------------- */
722 * count the nodes as needed:
724 * 1 normal (data) Phi's
729 static void csv_count_nodes(graph_entry_t *graph, counter_t cnt[])
734 for (i = 0; i < 4; ++i)
737 for (entry = pset_first(graph->opcode_hash); entry; entry = pset_next(graph->opcode_hash)) {
738 if (entry->op == op_Phi) {
740 cnt_add(&cnt[1], &entry->cnt_alive);
742 else if (entry->op == status->op_PhiM) {
744 cnt_add(&cnt[2], &entry->cnt_alive);
746 else if (entry->op == op_Proj) {
748 cnt_add(&cnt[3], &entry->cnt_alive);
751 /* all other nodes */
752 cnt_add(&cnt[0], &entry->cnt_alive);
760 static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry)
766 if (entry->irg && !entry->is_deleted) {
767 ir_graph *const_irg = get_const_code_irg();
769 if (entry->irg == const_irg) {
770 name = "<Const code Irg>";
775 name = get_entity_name(entry->ent);
777 name = "<UNKNOWN IRG>";
780 csv_count_nodes(entry, cnt);
782 fprintf(dmp->f, "%-40s, %p, %d, %d, %d, %d\n",
794 * initialise the simple dumper
796 static void csv_init(dumper_t *dmp, const char *name)
800 snprintf(fname, sizeof(fname), "%s.csv", name);
801 dmp->f = fopen(fname, "a");
805 * finishes the simple dumper
807 static void csv_finish(dumper_t *dmp)
814 * the simple human readable dumper
816 static dumper_t csv_dumper = {
825 /* ---------------------------------------------------------------------- */
828 * helper: get an ir_op from an opcode
830 ir_op *stat_get_op_from_opcode(opcode code)
832 return opcode_find_entry(code, status->ir_op_hash);
835 /* initialize the statistics module. */
836 void init_stat(unsigned enable_options)
838 #define X(a) a, sizeof(a)-1
842 /* enable statistics */
843 status->enable = enable_options & FIRMSTAT_ENABLED;
845 if (! status->enable)
848 obstack_init(&status->cnts);
850 /* build the pseudo-ops */
851 _op_Phi0.code = --pseudo_id;
852 _op_Phi0.name = new_id_from_chars(X("Phi0"));
854 _op_PhiM.code = --pseudo_id;
855 _op_PhiM.name = new_id_from_chars(X("PhiM"));
857 _op_MulC.code = --pseudo_id;
858 _op_MulC.name = new_id_from_chars(X("MulC"));
860 _op_DivC.code = --pseudo_id;
861 _op_DivC.name = new_id_from_chars(X("DivC"));
863 _op_ModC.code = --pseudo_id;
864 _op_ModC.name = new_id_from_chars(X("ModC"));
866 _op_DivModC.code = --pseudo_id;
867 _op_DivModC.name = new_id_from_chars(X("DivModC"));
869 /* create the hash-tables */
870 status->irg_hash = new_pset(graph_cmp, 8);
871 status->ir_op_hash = new_pset(opcode_cmp_2, 1);
873 status->op_Phi0 = &_op_Phi0;
874 status->op_PhiM = &_op_PhiM;
876 if (enable_options & FIRMSTAT_COUNT_STRONG_OP) {
877 status->op_MulC = &_op_MulC;
878 status->op_DivC = &_op_DivC;
879 status->op_ModC = &_op_ModC;
880 status->op_DivModC = &_op_DivModC;
883 status->op_MulC = NULL;
884 status->op_DivC = NULL;
885 status->op_ModC = NULL;
886 status->op_DivModC = NULL;
889 stat_register_dumper(&simple_dumper);
890 stat_register_dumper(&csv_dumper);
892 /* initialize the pattern hash */
893 stat_init_pattern_history(enable_options & FIRMSTAT_PATTERN_ENABLED);
897 /* A new IR op is registered. */
898 void stat_new_ir_op(const ir_op *op)
900 if (! status->enable)
905 graph_entry_t *graph = graph_get_entry(NULL, status->irg_hash);
907 /* execute for side effect :-) */
908 opcode_get_entry(op, graph->opcode_hash);
910 pset_insert(status->ir_op_hash, op, op->code);
915 /* An IR op is freed. */
916 void stat_free_ir_op(const ir_op *op)
918 if (! status->enable)
927 /* A new node is created. */
928 void stat_new_node(ir_node *node)
930 if (! status->enable)
933 /* do NOT count during dead node elimination */
934 if (status->in_dead_node_elim > 0)
940 graph_entry_t *graph;
941 ir_op *op = stat_get_irn_op(node);
943 /* increase global value */
944 graph = graph_get_entry(NULL, status->irg_hash);
945 entry = opcode_get_entry(op, graph->opcode_hash);
946 cnt_inc(&entry->new_node);
948 /* increase local value */
949 graph = graph_get_entry(current_ir_graph, status->irg_hash);
950 entry = opcode_get_entry(op, graph->opcode_hash);
951 cnt_inc(&entry->new_node);
956 /* A node is changed into a Id node */
957 void stat_turn_into_id(ir_node *node)
959 if (! status->enable)
965 graph_entry_t *graph;
966 ir_op *op = stat_get_irn_op(node);
968 /* increase global value */
969 graph = graph_get_entry(NULL, status->irg_hash);
970 entry = opcode_get_entry(op, graph->opcode_hash);
971 cnt_inc(&entry->into_Id);
973 /* increase local value */
974 graph = graph_get_entry(current_ir_graph, status->irg_hash);
975 entry = opcode_get_entry(op, graph->opcode_hash);
976 cnt_inc(&entry->into_Id);
981 /* A new graph was created */
982 void stat_new_graph(ir_graph *irg, entity *ent)
984 if (! status->enable)
989 /* execute for side effect :-) */
990 graph_entry_t * graph = graph_get_entry(irg, status->irg_hash);
993 graph->is_deleted = 0;
995 graph->is_recursive = 0;
996 graph->is_chain_call = 0;
1002 * A graph was deleted
1004 void stat_free_graph(ir_graph *irg)
1006 if (! status->enable)
1011 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1012 graph_entry_t *global = graph_get_entry(NULL, status->irg_hash);
1014 graph->is_deleted = 1;
1016 /* count the nodes of the graph yet, it will be destroyed later */
1017 count_nodes_in_graph(global, graph);
1019 /* count the DAG's */
1020 // count_dags_in_graph(global, graph);
1022 /* calculate the pattern */
1023 stat_calc_pattern_history(irg);
1029 * A walk over a graph is initiated. Do not count walks from statistic code.
1031 void stat_irg_walk(ir_graph *irg, void *pre, void *post)
1033 if (! status->enable)
1038 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1040 cnt_inc(&graph->cnt_walked);
1046 * A walk over a graph in block-wise order is initiated. Do not count walks from statistic code.
1048 void stat_irg_walk_blkwise(ir_graph *irg, void *pre, void *post)
1050 /* for now, do NOT differentiate between blockwise and normal */
1051 stat_irg_walk(irg, pre, post);
1055 * A walk over the graph's blocks is initiated. Do not count walks from statistic code.
1057 void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post)
1059 if (! status->enable)
1064 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1066 cnt_inc(&graph->cnt_walked_blocks);
1072 * called for every node that is removed due to an optimization
1074 static void removed_due_opt(ir_node *n, pset *set)
1076 ir_op *op = stat_get_irn_op(n);
1077 opt_entry_t *entry = opt_get_entry(op, set);
1079 /* increase global value */
1080 cnt_inc(&entry->count);
1084 * Some nodes were optimized into some others due to an optimization
1086 void stat_merge_nodes(
1087 ir_node **new_node_array, int new_num_entries,
1088 ir_node **old_node_array, int old_num_entries,
1091 if (! status->enable)
1097 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1099 for (i = 0; i < old_num_entries; ++i) {
1100 for (j = 0; j < new_num_entries; ++j)
1101 if (old_node_array[i] == new_node_array[j])
1104 /* nodes might be in new and old, these are NOT removed */
1105 if (j >= new_num_entries) {
1106 removed_due_opt(old_node_array[i], graph->opt_hash[opt]);
1114 * A node was lowered into other nodes
1116 void stat_lower(ir_node *node)
1118 if (! status->enable)
1123 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1125 removed_due_opt(node, graph->opt_hash[STAT_LOWERED]);
1131 * A graph was inlined
1133 void stat_inline(ir_node *call, ir_graph *called_irg)
1135 if (! status->enable)
1140 ir_graph *irg = get_irn_irg(call);
1141 graph_entry_t *i_graph = graph_get_entry(called_irg, status->irg_hash);
1142 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1144 cnt_inc(&graph->cnt_got_inlined);
1145 cnt_inc(&i_graph->cnt_was_inlined);
1151 * A graph with tail-recursions was optimized.
1153 void stat_tail_rec(ir_graph *irg)
1155 if (! status->enable)
1165 * Strength reduction was performed on an iteration variable.
1167 void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp)
1169 if (! status->enable)
1174 graph_entry_t *graph = graph_get_entry(irg, status->irg_hash);
1175 cnt_inc(&graph->cnt_strength_red);
1177 removed_due_opt(strong, graph->opt_hash[STAT_OPT_STRENGTH_RED]);
1183 * Start the dead node elimination.
1185 void stat_dead_node_elim_start(ir_graph *irg)
1187 if (! status->enable)
1190 ++status->in_dead_node_elim;
1194 * Stops the dead node elimination.
1196 void stat_dead_node_elim_stop(ir_graph *irg)
1198 if (! status->enable)
1201 --status->in_dead_node_elim;
1205 * A multiply was replaced by a series of Shifts/Adds/Subs
1207 void stat_arch_dep_replace_mul_with_shifts(ir_node *mul)
1209 if (! status->enable)
1214 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1215 removed_due_opt(mul, graph->opt_hash[STAT_OPT_ARCH_DEP]);
1221 * A division was replaced by a series of Shifts/Muls
1223 void stat_arch_dep_replace_div_with_shifts(ir_node *div)
1225 if (! status->enable)
1230 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1231 removed_due_opt(div, graph->opt_hash[STAT_OPT_ARCH_DEP]);
1237 * A modulo was replaced by a series of Shifts/Muls
1239 void stat_arch_dep_replace_mod_with_shifts(ir_node *mod)
1241 if (! status->enable)
1246 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1247 removed_due_opt(mod, graph->opt_hash[STAT_OPT_ARCH_DEP]);
1253 * A DivMod was replaced by a series of Shifts/Muls
1255 void stat_arch_dep_replace_DivMod_with_shifts(ir_node *divmod)
1257 if (! status->enable)
1262 graph_entry_t *graph = graph_get_entry(current_ir_graph, status->irg_hash);
1263 removed_due_opt(divmod, graph->opt_hash[STAT_OPT_ARCH_DEP]);
1268 /* Finish the statistics */
1269 void stat_finish(const char *name)
1271 if (! status->enable)
1276 graph_entry_t *entry;
1277 graph_entry_t *global = graph_get_entry(NULL, status->irg_hash);
1281 /* dump per graph */
1282 for (entry = pset_first(status->irg_hash); entry; entry = pset_next(status->irg_hash)) {
1284 if (entry->irg == NULL) {
1285 /* special entry for the global count */
1289 if (! entry->is_deleted) {
1290 /* the graph is still alive, count the nodes on it */
1291 count_nodes_in_graph(global, entry);
1293 /* count the DAG's */
1294 // count_dags_in_graph(global, entry);
1296 /* calculate the pattern */
1297 stat_calc_pattern_history(entry->irg);
1302 /* clear the counter here:
1303 * we need only the edge counter to be cleared, all others are cumulative
1305 cnt_clr(&entry->cnt_edges);
1309 // dump_graph(global);
1312 stat_finish_pattern_history();
1314 /* clear the global counter here */
1316 node_entry_t *entry;
1318 for (entry = pset_first(global->opcode_hash); entry; entry = pset_next(global->opcode_hash)) {
1319 opcode_clear_entry(entry);
1321 graph_clear_entry(global);
1325 // status->enable = 0;
1332 /* need this for prototypes */
1333 #define FIRM_STATISTICS
1334 #include "firmstat.h"
1336 void init_stat(unsigned enable_options) {}
1338 void stat_finish(const char *name) {}
1340 void stat_new_ir_op(const ir_op *op) {}
1342 void stat_free_ir_op(const ir_op *op) {}
1344 void stat_new_node(ir_node *node) {}
1346 void stat_turn_into_id(ir_node *node) {}
1348 void stat_new_graph(ir_graph *irg, entity *ent) {}
1350 void stat_free_graph(ir_graph *irg) {}
1352 void stat_irg_walk(ir_graph *irg, void *pre, void *post) {}
1354 void stat_irg_block_walk(ir_graph *irg, const ir_node *node, void *pre, void *post) {}
1356 void stat_merge_nodes(
1357 ir_node **new_node_array, int new_num_entries,
1358 ir_node **old_node_array, int old_num_entries,
1359 stat_opt_kind opt) {}
1361 void stat_lower(ir_node *node) {}
1363 void stat_inline(ir_node *call, ir_graph *irg) {}
1365 void stat_tail_rec(ir_graph *irg) {}
1367 void stat_strength_red(ir_graph *irg, ir_node *strong, ir_node *cmp) {}
1369 void stat_dead_node_elim_start(ir_graph *irg) {}
1371 void stat_dead_node_elim_stop(ir_graph *irg) {}
1373 void stat_arch_dep_replace_mul_with_shifts(ir_node *mul) {}
1375 void stat_arch_dep_replace_div_with_shifts(ir_node *div) {}
1377 void stat_arch_dep_replace_mod_with_shifts(ir_node *mod) {}
1379 void stat_arch_dep_replace_DivMod_with_shifts(ir_node *divmod) {}