OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
xstats.cxx
Go to the documentation of this file.
1 /*
2 
3  Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved.
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of version 2 of the GNU General Public License as
7  published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it would be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13  Further, this software is distributed without any warranty that it is
14  free of the rightful claim of any third person regarding infringement
15  or the like. Any license provided herein, whether implied or
16  otherwise, applies only to this software file. Patent licenses, if
17  any, provided herein do not apply to combinations of this program with
18  other software, or any other product whatsoever.
19 
20  You should have received a copy of the GNU General Public License along
21  with this program; if not, write the Free Software Foundation, Inc., 59
22  Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 
24  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky,
25  Mountain View, CA 94043, or:
26 
27  http://www.sgi.com
28 
29  For further information regarding this notice, see:
30 
31  http://oss.sgi.com/projects/GenInfo/NoticeExplan
32 
33 */
34 
35 
36 /* ====================================================================
37  * ====================================================================
38  *
39  *
40  * Description:
41  *
42  * This contains declarations for all statistics variables exported in
43  * stats.h. It also contains 1 public entry point to print out a
44  * variety of statistics. This public routine is called from the
45  * main routine of each process.
46  *
47  * ====================================================================
48  * ====================================================================
49  */
50 
51 #ifdef USE_PCH
52 #include "common_com_pch.h"
53 #endif /* USE_PCH */
54 #pragma hdrstop
55 
56 #define USE_STANDARD_TYPES 1
57 
58 #include "defs.h"
59 #include "tracing.h"
60 #include "glob.h"
61 #include "opcode.h"
62 #include "xstats.h"
63 #include "stab.h"
64 #include "wio.h"
65 
67 UINT32 Max_Src_Olimit; /* Maximum Olimit needed for all PU's in file */
68 
69 /* Counters of important data structures */
70 INT32 PU_WN_Cnt; /* number of whirl nodes in this PU */
71 INT32 Total_WN_Cnt; /* total number of whirl nodes */
72 INT32 PU_WN_BB_Cnt; /* number of whirl bbs in this PU */
73 INT32 PU_WN_Stmt_Cnt; /* number of whirl stmts in this PU */
74 INT32 PU_WN_Call_Cnt; /* number of whirl calls in this PU */
75 INT32 PU_WN_Loop_Cnt; /* number of whirl loops in this PU */
76 INT32 PU_BB_Cnt; /* number of cg basic-blocks in this PU */
77 INT32 Total_BB_Cnt; /* total number of basic-blocks */
78 INT32 PU_OP_Cnt; /* number of instructions in this PU */
79 INT32 Total_OP_Cnt; /* total number of instructions */
80 INT32 PU_Size; /* byte size of this PU */
81 INT32 Total_Code_Size; /* total bytes size of all PUs */
82 INT32 PU_TN_Cnt; /* number of TNs in this PU */
83 INT32 Total_TN_Cnt; /* total number of TNs ever allocated */
84 
85 /* Counters for back end: */
86 INT32 Misaligned_Cnt; /* Number of misaligned memrefs expanded */
87 INT32 Temp_Var_Cnt; /* Number of tempories created */
89 INT32 Spill_Var_Cnt; /* Number of spill temporaries created */
91 
92 #ifdef FRONT_END
93 #if defined(FRONT_END_C) || defined(FRONT_END_CPLUSPLUS)
94 #define PHASE_NAME "c fe"
95 #else /* !FRONT_END_C */
96 #define PHASE_NAME "f77 fe"
97 #endif /* FRONT_END_C */
98 #else /* !FRONT_END */
99 #define PHASE_NAME "be"
100 #endif /* FRONT_END */
101 
102 /* determine # bbs and stmts to be counted for the operator */
103 void
104 Count_WN_Operator (OPERATOR opr, TYPE_ID rtype, INT32& bbs, INT32& stmts,
105  INT32& calls)
106 {
107  /* count nscf stmts as bbs, not stmts */
108  if (OPERATOR_is_non_scf(opr)) {
109  ++bbs;
110  } else if (OPERATOR_is_stmt(opr)) {
111  if (OPERATOR_is_call(opr)) {
112  ++bbs;
113  ++calls;
114  } else if (opr == OPR_IO) {
115  /* TODO: ideally would look at values of IO_ITEMs,
116  * but then have to pass more than opcode. */
117  ++bbs;
118  ++calls;
119  } else if (! OPERATOR_is_not_executable(opr)) {
120  ++stmts;
121  if (MTYPE_is_complex(rtype) && OPERATOR_is_store(opr)) {
122  ++stmts;
123  }
124  }
125  } else if (OPERATOR_is_scf(opr)) {
126  if (opr != OPR_BLOCK) {
127  /* blocks are counted by parent node */
128  ++bbs;
129  }
130  /* if may create two blocks if else present,
131  * but can't tell just from opcode */
132  } else if ((rtype == MTYPE_FQ || rtype == MTYPE_CQ) &&
133  OPERATOR_is_expression(opr) &&
134  !OPERATOR_is_load(opr) &&
135  !OPERATOR_is_leaf(opr) ) {
136  /* quad operators get turned into calls */
137  ++bbs;
138  ++calls;
139  } else if (opr == OPR_CAND || opr == OPR_CIOR) {
140  /* these may get expanded to if-then-else sequences,
141  * or they may be optimized to logical expressions.
142  * use the halfway average of 1 bb */
143  ++bbs;
144  }
145 }
146 
147 
148 void
149 Count_WN_Node (WN *node, INT32 *bbs, INT32 *stmts)
150 {
151  Count_WN_Operator (WN_operator (node), WN_rtype (node), *bbs, *stmts,
153  if (WN_opcode(node) == OPC_IO) {
154  INT i;
155  for (i=0; i<WN_kid_count(node); i++) {
156  WN *kid = WN_kid(node, i);
157  if (WN_opcode(kid) == OPC_IO_ITEM
158  && (WN_io_item(kid) == IOC_END
159  || WN_io_item(kid)==IOC_ERR)
160 // assuming LDA of label will change to GOTO label
161  && WN_opcode(WN_kid0(kid)) == OPC_GOTO)
162  {
163  // found implicit branch to label
164  (*bbs)++;
165  }
166  }
167  }
168 }
169 
170 
171 /* ====================================================================
172  *
173  * Initialize_Stats
174  *
175  * Initialize statistics.
176  *
177  * ====================================================================
178  */
179 
180 void
182 {
183  Total_WN_Cnt = 0;
184  PU_WN_Cnt = 0;
185  Total_BB_Cnt = 0;
186  PU_WN_BB_Cnt = 0;
187  PU_WN_Stmt_Cnt = 0;
188  PU_WN_Call_Cnt = 0;
189  PU_WN_Loop_Cnt = 0;
190  PU_BB_Cnt = 0;
191  PU_OP_Cnt = 0;
192  Total_OP_Cnt = 0;
193  PU_Size = 0;
194  Total_Code_Size = 0;
195  PU_TN_Cnt = 0;
196  Total_TN_Cnt = 0;
197 
198  Misaligned_Cnt = 0; /* Number of misaligned memrefs expanded */
199  Temp_Var_Cnt = 0; /* Number of temporaries created */
200  Total_Temp_Var_Cnt = 0;
201  Spill_Var_Cnt = 0; /* Number of spill temporaries created */
203  Max_Src_Olimit = 0;
204 }
205 
206 /* ====================================================================
207  *
208  * Initialize_PU_Stats
209  *
210  * Initialize only the PU statistics.
211  *
212  * ====================================================================
213  */
214 
215 void
217 {
218  PU_WN_Cnt = 0;
219  PU_WN_BB_Cnt = 0;
220  PU_WN_Stmt_Cnt = 0;
221  PU_WN_Call_Cnt = 0;
222  PU_WN_Loop_Cnt = 0;
223  PU_BB_Cnt = 0;
224  PU_OP_Cnt = 0;
225  PU_TN_Cnt = 0;
226  PU_Size = 0;
227 
228  Temp_Var_Cnt = 0; /* Number of temporaries created */
229  Spill_Var_Cnt = 0; /* Number of spill temporaries created */
230 }
231 
232 /* ====================================================================
233  *
234  * Print_Stats
235  *
236  * Print statistics to the trace file.
237  *
238  * ====================================================================
239  */
240 
241 void
243 {
244  /* only print stats at user's request */
245  if ( Get_Trace(TKIND_INFO, TINFO_STATS) == 0 ) return;
246 
247  fprintf(TFile, "PU %s stats for %s:\n", PHASE_NAME, Orig_PU_Name);
248  fprintf ( TFile, "WNs in PU: %d\n", PU_WN_Cnt);
249 #ifdef BACK_END
250  fprintf ( TFile, "WN BBs in PU: %d\n", PU_WN_BB_Cnt);
251  fprintf ( TFile, "WN Stmts in PU: %d\n", PU_WN_Stmt_Cnt);
252  fprintf ( TFile, "WN Calls in PU: %d\n", PU_WN_Call_Cnt);
253  fprintf ( TFile, "BBs in PU: %d\n", PU_BB_Cnt);
254  fprintf ( TFile, "OPs in PU: %d\n", PU_OP_Cnt);
255  fprintf ( TFile, "TNs in PU: %d\n", PU_TN_Cnt);
256  fprintf ( TFile, "STs in PU: %d, PREGs in PU: %d\n",
257  Scope_tab[CURRENT_SYMTAB].st_tab->Size (),
259  fprintf ( TFile, "%d temporary variables, %d spill temporaries\n",
261  fprintf ( TFile, "Size of PU: %d bytes\n", PU_Size);
262 #endif
263  fprintf (TFile, "\n");
264 
265  /* accumulate PU counters */
273 }
274 
275 void
277 {
278  /* only print stats at user's request */
279  if ( Get_Trace(TKIND_INFO, TINFO_STATS) == 0 ) return;
280 
281  fprintf(TFile, "Total %s stats for compilation:\n", PHASE_NAME);
282  fprintf ( TFile, "WNs in file: %d\n", Total_WN_Cnt);
283 #ifdef BACK_END
284  fprintf ( TFile, "BBs in file: %d\n", Total_BB_Cnt);
285  fprintf ( TFile, "OPs in file: %d\n", Total_OP_Cnt);
286  fprintf ( TFile, "TNs in file: %d\n", Total_TN_Cnt);
287  fprintf ( TFile, "Code size in file: %d bytes\n", Total_Code_Size);
288 
289  fprintf ( TFile, "%d temporary variables, %d spill temporaries\n",
291 
292  fprintf ( TFile, "Misaligned memory references: %d\n", Misaligned_Cnt);
293 #endif
294 }