move backend into libfirm
[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 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #include "statistics.h"
18 #include "irgraph_t.h"
19 #include "irnode_t.h"
20 #include "irprog.h"
21 #include "irgwalk.h"
22
23 /***********************************************************************/
24 /* Statistics about allocated datastructures: counts.                  */
25
26 static void count_nodes(ir_node *n, void *env) {
27   int * counter_ptr = (int *)env;
28   (*counter_ptr)++;
29 }
30
31
32 /** Prints number of irgraphs, number of nodes in them and
33  *  totals. */
34 void print_graph_counts(int verbosity) {
35   int i, counter, total = 0;
36   int view = get_interprocedural_view();
37   ir_graph *old = current_ir_graph;
38
39   set_interprocedural_view(0);
40
41   for (i = 0; i < get_irp_n_irgs(); i++) {
42     counter = 0;
43     irg_walk_graph(get_irp_irg(i), count_nodes, NULL, &counter);
44     if (verbosity == 1)
45       printf(" +%4d nodes in graph %s.\n", counter, get_entity_name(get_irg_entity(get_irp_irg(i))));
46     total += counter;
47   }
48   printf(" +++ There are %d graphs with total %d nodes.\n", get_irp_n_irgs(), total);
49
50   current_ir_graph = old;
51   set_interprocedural_view(view);
52 }
53
54 /** Prints number of types, number of entities and totals.
55  *   */
56 void print_type_counts(int verbosity) {
57   int i, counter, total = 0;
58   for (i = 0; i < get_irp_n_types(); i++) {
59     ir_type *tp = get_irp_type(i);
60     counter = -1;
61     if (is_Class_type(tp)) counter = get_class_n_members(tp);
62     if (is_Struct_type(tp)) counter = get_struct_n_members(tp);
63     if (is_Union_type(tp)) counter = get_union_n_members(tp);
64     if (counter > -1) {
65       if (verbosity == 1)
66     printf(" +%3d entities in %s type %s.\n", counter, get_type_tpop_name(tp), get_type_name(tp));
67       total += counter;
68     }
69   }
70   printf(" +++ There are %d types with total %d entities.\n", get_irp_n_types(), total);
71   printf(" +++ Global type has %d entities\n",
72      get_class_n_members(get_glob_type()));
73
74 }
75
76 /** Prints number of tarvals.
77  *   */
78 void print_tarval_counts(int verbosity) {
79   printf("tarval count not implemented.\n\n");
80 }
81
82 /** Prints number of idents.
83  *   */
84 void print_ident_counts(int verbosity) {
85   printf("ident count not implemented.\n\n");
86 }
87
88
89 void print_all_counts(int verbosity) {
90   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
91   print_graph_counts(verbosity);
92   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
93   print_type_counts(verbosity);
94   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
95   /*
96   print_tarval_counts(verbosity);
97   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
98   print_ident_counts(verbosity);
99   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
100   */
101 }