Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
xstats.cxx
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 /* ====================================================================
00037  * ====================================================================
00038  *
00039  *
00040  * Description:
00041  *
00042  * This contains declarations for all statistics variables exported in
00043  * stats.h.  It also contains 1 public entry point to print out a
00044  * variety of statistics.  This public routine is called from the
00045  * main routine of each process.
00046  *
00047  * ====================================================================
00048  * ====================================================================
00049  */
00050 
00051 #ifdef USE_PCH
00052 #include "common_com_pch.h"
00053 #endif /* USE_PCH */
00054 #pragma hdrstop
00055 
00056 #define USE_STANDARD_TYPES 1
00057 
00058 #include "defs.h"
00059 #include "tracing.h"
00060 #include "glob.h"
00061 #include "opcode.h"
00062 #include "xstats.h"
00063 #include "stab.h"
00064 #include "wio.h"
00065 
00066 UINT32 PU_Olimit;
00067 UINT32 Max_Src_Olimit;   /* Maximum Olimit needed for all PU's in file */
00068 
00069 /* Counters of important data structures */
00070 INT32 PU_WN_Cnt;        /* number of whirl nodes in this PU */
00071 INT32 Total_WN_Cnt;     /* total number of whirl nodes */
00072 INT32 PU_WN_BB_Cnt;     /* number of whirl bbs in this PU */
00073 INT32 PU_WN_Stmt_Cnt;   /* number of whirl stmts in this PU */
00074 INT32 PU_WN_Call_Cnt;   /* number of whirl calls in this PU */
00075 INT32 PU_WN_Loop_Cnt;   /* number of whirl loops in this PU */
00076 INT32 PU_BB_Cnt;        /* number of cg basic-blocks in this PU */
00077 INT32 Total_BB_Cnt;     /* total number of basic-blocks */
00078 INT32 PU_OP_Cnt;        /* number of instructions in this PU */
00079 INT32 Total_OP_Cnt;     /* total number of instructions */
00080 INT32 PU_Size;          /* byte size of this PU */
00081 INT32 Total_Code_Size;  /* total bytes size of all PUs */
00082 INT32 PU_TN_Cnt;        /* number of TNs in this PU */
00083 INT32 Total_TN_Cnt;     /* total number of TNs ever allocated */
00084 
00085 /* Counters for back end: */
00086 INT32 Misaligned_Cnt;   /* Number of misaligned memrefs expanded */
00087 INT32 Temp_Var_Cnt;     /* Number of tempories created */
00088 INT32 Total_Temp_Var_Cnt;
00089 INT32 Spill_Var_Cnt;    /* Number of spill temporaries created */
00090 INT32 Total_Spill_Var_Cnt;
00091 
00092 #ifdef FRONT_END
00093 #if defined(FRONT_END_C) || defined(FRONT_END_CPLUSPLUS)
00094 #define PHASE_NAME "c fe"
00095 #else /* !FRONT_END_C */
00096 #define PHASE_NAME "f77 fe"
00097 #endif /* FRONT_END_C */
00098 #else /* !FRONT_END */
00099 #define PHASE_NAME "be"
00100 #endif /* FRONT_END */
00101 
00102 /* determine # bbs and stmts to be counted for the operator */
00103 void
00104 Count_WN_Operator (OPERATOR opr, TYPE_ID rtype, INT32& bbs, INT32& stmts,
00105                    INT32& calls)
00106 {
00107     /* count nscf stmts as bbs, not stmts */
00108     if (OPERATOR_is_non_scf(opr)) {
00109         ++bbs;
00110     } else if (OPERATOR_is_stmt(opr)) {
00111         if (OPERATOR_is_call(opr)) {
00112             ++bbs;
00113             ++calls;
00114         } else if (opr == OPR_IO) {
00115             /* TODO:  ideally would look at values of IO_ITEMs,
00116              * but then have to pass more than opcode. */
00117             ++bbs;
00118             ++calls;
00119         } else if (! OPERATOR_is_not_executable(opr)) {
00120             ++stmts;
00121             if (MTYPE_is_complex(rtype) && OPERATOR_is_store(opr)) {
00122                 ++stmts;
00123             }
00124         }
00125     } else if (OPERATOR_is_scf(opr)) {
00126         if (opr != OPR_BLOCK) {
00127             /* blocks are counted by parent node */
00128             ++bbs;
00129         }
00130         /* if may create two blocks if else present,
00131          * but can't tell just from opcode */
00132     } else if ((rtype == MTYPE_FQ || rtype == MTYPE_CQ) &&
00133                OPERATOR_is_expression(opr) &&
00134                !OPERATOR_is_load(opr) &&
00135                !OPERATOR_is_leaf(opr) ) {
00136         /* quad operators get turned into calls */
00137         ++bbs;
00138         ++calls;
00139     } else if (opr == OPR_CAND || opr == OPR_CIOR) {
00140         /* these may get expanded to if-then-else sequences,
00141          * or they may be optimized to logical expressions.
00142          * use the halfway average of 1 bb */
00143         ++bbs;
00144     }
00145 }
00146 
00147 
00148 void
00149 Count_WN_Node (WN *node, INT32 *bbs, INT32 *stmts)
00150 {
00151         Count_WN_Operator (WN_operator (node), WN_rtype (node), *bbs, *stmts,
00152                            PU_WN_Call_Cnt);
00153         if (WN_opcode(node) == OPC_IO) {
00154                 INT i;
00155                 for (i=0; i<WN_kid_count(node); i++) {
00156                         WN *kid = WN_kid(node, i);
00157                         if (WN_opcode(kid) == OPC_IO_ITEM
00158                             && (WN_io_item(kid) == IOC_END
00159                              || WN_io_item(kid)==IOC_ERR)
00160 // assuming LDA of label will change to GOTO label
00161                             && WN_opcode(WN_kid0(kid)) == OPC_GOTO)
00162                         {
00163                                 // found implicit branch to label
00164                                 (*bbs)++;
00165                         }
00166                 }
00167         }
00168 }
00169 
00170 
00171 /* ====================================================================
00172  *
00173  * Initialize_Stats
00174  *
00175  * Initialize statistics.
00176  *
00177  * ====================================================================
00178  */
00179 
00180 void
00181 Initialize_Stats ( void )
00182 {
00183   Total_WN_Cnt = 0;
00184   PU_WN_Cnt = 0;
00185   Total_BB_Cnt = 0;
00186   PU_WN_BB_Cnt = 0;
00187   PU_WN_Stmt_Cnt = 0;
00188   PU_WN_Call_Cnt = 0;
00189   PU_WN_Loop_Cnt = 0;
00190   PU_BB_Cnt = 0;
00191   PU_OP_Cnt = 0;
00192   Total_OP_Cnt = 0;
00193   PU_Size = 0;
00194   Total_Code_Size = 0;
00195   PU_TN_Cnt = 0;
00196   Total_TN_Cnt = 0;
00197 
00198   Misaligned_Cnt = 0;   /* Number of misaligned memrefs expanded */
00199   Temp_Var_Cnt = 0;     /* Number of temporaries created */
00200   Total_Temp_Var_Cnt = 0;
00201   Spill_Var_Cnt = 0;    /* Number of spill temporaries created */
00202   Total_Spill_Var_Cnt = 0;
00203   Max_Src_Olimit = 0;
00204 }
00205 
00206 /* ====================================================================
00207  *
00208  * Initialize_PU_Stats
00209  *
00210  * Initialize only the PU statistics.
00211  *
00212  * ====================================================================
00213  */
00214 
00215 void
00216 Initialize_PU_Stats ( void )
00217 {
00218   PU_WN_Cnt = 0;
00219   PU_WN_BB_Cnt = 0;
00220   PU_WN_Stmt_Cnt = 0;
00221   PU_WN_Call_Cnt = 0;
00222   PU_WN_Loop_Cnt = 0;
00223   PU_BB_Cnt = 0;
00224   PU_OP_Cnt = 0;
00225   PU_TN_Cnt = 0;
00226   PU_Size = 0;
00227 
00228   Temp_Var_Cnt = 0;     /* Number of temporaries created */
00229   Spill_Var_Cnt = 0;    /* Number of spill temporaries created */
00230 }
00231 
00232 /* ====================================================================
00233  *
00234  * Print_Stats
00235  *
00236  * Print statistics to the trace file.
00237  *
00238  * ====================================================================
00239  */
00240 
00241 void
00242 Print_PU_Stats ( void )
00243 {
00244     /* only print stats at user's request */
00245     if ( Get_Trace(TKIND_INFO, TINFO_STATS) == 0 ) return;
00246 
00247     fprintf(TFile, "PU %s stats for %s:\n", PHASE_NAME, Orig_PU_Name);
00248     fprintf ( TFile, "WNs in PU:  %d\n", PU_WN_Cnt);
00249 #ifdef BACK_END
00250     fprintf ( TFile, "WN BBs in PU:  %d\n", PU_WN_BB_Cnt);
00251     fprintf ( TFile, "WN Stmts in PU:  %d\n", PU_WN_Stmt_Cnt);
00252     fprintf ( TFile, "WN Calls in PU:  %d\n", PU_WN_Call_Cnt);
00253     fprintf ( TFile, "BBs in PU:  %d\n", PU_BB_Cnt);
00254     fprintf ( TFile, "OPs in PU:  %d\n", PU_OP_Cnt);
00255     fprintf ( TFile, "TNs in PU:  %d\n", PU_TN_Cnt);
00256     fprintf ( TFile, "STs in PU:  %d, PREGs in PU:  %d\n",
00257              Scope_tab[CURRENT_SYMTAB].st_tab->Size (),
00258              Scope_tab[CURRENT_SYMTAB].preg_tab->Size ());
00259     fprintf ( TFile, "%d temporary variables, %d spill temporaries\n", 
00260              Temp_Var_Cnt, Spill_Var_Cnt);
00261     fprintf ( TFile, "Size of PU:  %d bytes\n", PU_Size);
00262 #endif
00263     fprintf (TFile, "\n");
00264 
00265     /* accumulate PU counters */
00266     Total_WN_Cnt += PU_WN_Cnt;
00267     Total_BB_Cnt += PU_BB_Cnt;
00268     Total_OP_Cnt += PU_OP_Cnt;
00269     Total_TN_Cnt += PU_TN_Cnt;
00270     Total_Temp_Var_Cnt += Temp_Var_Cnt;
00271     Total_Spill_Var_Cnt += Spill_Var_Cnt;
00272     Total_Code_Size += PU_Size;
00273 }
00274 
00275 void
00276 Print_Total_Stats ( void )
00277 {
00278   /* only print stats at user's request */
00279   if ( Get_Trace(TKIND_INFO, TINFO_STATS) == 0 ) return;
00280   
00281   fprintf(TFile, "Total %s stats for compilation:\n", PHASE_NAME);
00282   fprintf ( TFile, "WNs in file:  %d\n", Total_WN_Cnt);
00283 #ifdef BACK_END
00284   fprintf ( TFile, "BBs in file:  %d\n", Total_BB_Cnt);
00285   fprintf ( TFile, "OPs in file:  %d\n", Total_OP_Cnt);
00286   fprintf ( TFile, "TNs in file:  %d\n", Total_TN_Cnt);
00287   fprintf ( TFile, "Code size in file:  %d bytes\n", Total_Code_Size);
00288 
00289   fprintf ( TFile, "%d temporary variables, %d spill temporaries\n", 
00290         Total_Temp_Var_Cnt, Total_Spill_Var_Cnt);
00291 
00292   fprintf ( TFile, "Misaligned memory references: %d\n", Misaligned_Cnt);
00293 #endif
00294 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines