replaced inline by __inline to allow to be compiled in gcc and msvc modes
[libfirm] / ir / common / statistics.c
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Compute statistics about firm library.
23  * @author   Goetz Lindenmaier
24  * @version  $Id$
25  */
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "statistics.h"
31 #include "irgraph_t.h"
32 #include "irnode_t.h"
33 #include "irprog.h"
34 #include "irgwalk.h"
35
36 /***********************************************************************/
37 /* Statistics about allocated datastructures: counts.                  */
38
39 static void count_nodes(ir_node *n, void *env) {
40   int * counter_ptr = (int *)env;
41   (*counter_ptr)++;
42 }
43
44
45 /** Prints number of irgraphs, number of nodes in them and
46  *  totals. */
47 void print_graph_counts(int verbosity) {
48   int i, counter, total = 0;
49   int view = get_interprocedural_view();
50   ir_graph *old = current_ir_graph;
51
52   set_interprocedural_view(0);
53
54   for (i = 0; i < get_irp_n_irgs(); i++) {
55     counter = 0;
56     irg_walk_graph(get_irp_irg(i), count_nodes, NULL, &counter);
57     if (verbosity == 1)
58       printf(" +%4d nodes in graph %s.\n", counter, get_entity_name(get_irg_entity(get_irp_irg(i))));
59     total += counter;
60   }
61   printf(" +++ There are %d graphs with total %d nodes.\n", get_irp_n_irgs(), total);
62
63   current_ir_graph = old;
64   set_interprocedural_view(view);
65 }
66
67 /** Prints number of types, number of entities and totals.
68  *   */
69 void print_type_counts(int verbosity) {
70   int i, counter, total = 0;
71   for (i = 0; i < get_irp_n_types(); i++) {
72     ir_type *tp = get_irp_type(i);
73     counter = -1;
74     if (is_Class_type(tp)) counter = get_class_n_members(tp);
75     if (is_Struct_type(tp)) counter = get_struct_n_members(tp);
76     if (is_Union_type(tp)) counter = get_union_n_members(tp);
77     if (counter > -1) {
78       if (verbosity == 1)
79     printf(" +%3d entities in %s type %s.\n", counter, get_type_tpop_name(tp), get_type_name(tp));
80       total += counter;
81     }
82   }
83   printf(" +++ There are %d types with total %d entities.\n", get_irp_n_types(), total);
84   printf(" +++ Global type has %d entities\n",
85      get_class_n_members(get_glob_type()));
86
87 }
88
89 /** Prints number of tarvals.
90  *   */
91 void print_tarval_counts(int verbosity) {
92   printf("tarval count not implemented.\n\n");
93 }
94
95 /** Prints number of idents.
96  *   */
97 void print_ident_counts(int verbosity) {
98   printf("ident count not implemented.\n\n");
99 }
100
101
102 void print_all_counts(int verbosity) {
103   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
104   print_graph_counts(verbosity);
105   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
106   print_type_counts(verbosity);
107   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
108   /*
109   print_tarval_counts(verbosity);
110   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
111   print_ident_counts(verbosity);
112   printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
113   */
114 }