1af3281dcb35760944479a8c18d9643fa4e12bde
[libfirm] / ir / common / statistics.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/statistics.c
4  * Purpose:     Compute statistics about firm library.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2004 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #include "statistics.h"
14 #include "irgraph.h"
15 #include "irnode.h"
16 #include "irprog.h"
17 #include "irgwalk.h"
18
19 /***********************************************************************/
20 /* Statistics about allocated datastructures: counts.                  */
21
22 static void count_nodes(ir_node *n, void *env) {
23   int * counter_ptr = (int *)env;
24   (*counter_ptr)++;
25 }
26
27
28 /** Prints number of irgraphs, number of nodes in them and
29  *  totals. */
30 void print_graph_counts(int verbosity) {
31   int i, counter, total = 0;
32   int view = interprocedural_view;
33   interprocedural_view = 0;
34   ir_graph *old = current_ir_graph;
35
36   for (i = 0; i < get_irp_n_irgs(); i++) {
37     counter = 0;
38     irg_walk_graph(get_irp_irg(i), count_nodes, NULL, &counter);
39     if (verbosity == 1)
40       printf(" +%4d nodes in graph %s.\n", counter, get_entity_name(get_irg_entity(get_irp_irg(i))));
41     total += counter;
42   }
43   printf(" +++ There are %d graphs with total %d nodes.\n", get_irp_n_irgs(), total);
44
45   current_ir_graph = old;
46   interprocedural_view = view;
47 }
48
49 /** Prints number of types, number of entities and totals.
50  *   */
51 void print_type_counts(int verbosity) {
52   int i, counter, total = 0;
53   for (i = 0; i < get_irp_n_types(); i++) {
54     type *tp = get_irp_type(i);
55     counter = -1;
56     if (is_class_type(tp)) counter = get_class_n_members(tp);
57     if (is_struct_type(tp)) counter = get_struct_n_members(tp);
58     if (is_union_type(tp)) counter = get_union_n_members(tp);
59     if (counter > -1) {
60       if (verbosity == 1)
61         printf(" +%3d entities in %s type %s.\n", counter, get_type_tpop_name(tp), get_type_name(tp));
62       total += counter;
63     }
64   }
65   printf(" +++ There are %d types with total %d entities.\n", get_irp_n_types(), total);
66   printf(" +++ Global type has %d entities\n",
67          get_class_n_members(get_glob_type()));
68
69 }
70
71 /** Prints number of tarvals.
72  *   */
73 void print_tarval_counts(int verbosity) {
74   printf("tarval count not implemented.\n\n");
75 }
76
77 /** Prints number of idents.
78  *   */
79 void print_ident_counts(int verbosity) {
80   printf("ident count not implemented.\n\n");
81 }
82
83
84 void print_all_counts(int verbosity) {
85   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
86   print_graph_counts(verbosity);
87   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
88   print_type_counts(verbosity);
89   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
90   /*
91   print_tarval_counts(verbosity);
92   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
93   print_ident_counts(verbosity);
94   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
95   */
96 }