This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] detailed rtx allocation stats


This patch adds detailed rtx allocation stats to -fmem-report.  
It prints for each rtx type the number of allocations and the total
memory gcalloced in bytes.

The code is only enabled when GATHER_STATISTICS is defined.

Given that GCC allocates a lot of memory, it should be useful to see
how the allocated memory is used.

An interesting observation: when compiling the code from PR8361 on
x86-linux the total memory allocated is ~ 422MB, of which ~105MB are
used for trees and ~38MB for rtxes.  



2003-11-25  Dan Nicolaescu  <dann@ics.uci.edu>

	* rtl.c (rtx_alloc_counts,rtx_alloc_sizes,
	  rtvec_alloc_counts,rtx_alloc_sizes): New static vars.
	* rtl.c (dump_rtx_statistics): New function.
	* rtl.h (dump_rtx_statistics): Declare it.
	* rtl.h (finalize): Call it.	

Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.438
diff -c -3 -p -r1.438 rtl.h
*** rtl.h	21 Nov 2003 06:52:23 -0000	1.438
--- rtl.h	25 Nov 2003 19:23:02 -0000
*************** extern void set_reg_attrs_for_parm (rtx,
*** 1457,1462 ****
--- 1457,1463 ----
  extern rtx rtx_alloc (RTX_CODE);
  extern rtvec rtvec_alloc (int);
  extern rtx copy_rtx (rtx);
+ extern void dump_rtx_statistics (void);
  
  /* In emit-rtl.c */
  extern rtx copy_rtx_if_shared (rtx);
Index: rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.c,v
retrieving revision 1.128
diff -c -3 -p -r1.128 rtl.c
*** rtl.c	18 Oct 2003 18:45:15 -0000	1.128
--- rtl.c	25 Nov 2003 19:23:02 -0000
*************** const char * const reg_note_name[] =
*** 138,143 ****
--- 138,151 ----
    "REG_VTABLE_REF"
  };
  
+ 
+ #ifdef GATHER_STATISTICS
+ static int rtx_alloc_counts[(int) LAST_AND_UNUSED_RTX_CODE];
+ static int rtx_alloc_sizes[(int) LAST_AND_UNUSED_RTX_CODE];
+ static int rtvec_alloc_counts;
+ static int rtvec_alloc_sizes;
+ #endif
+ 
  
  /* Allocate an rtx vector of N elements.
     Store the length, and initialize all elements to zero.  */
*************** rtvec_alloc (int n)
*** 152,157 ****
--- 160,171 ----
    memset (&rt->elem[0], 0, n * sizeof (rtx));
  
    PUT_NUM_ELEM (rt, n);
+ 
+ #ifdef GATHER_STATISTICS
+   rtvec_alloc_counts++;
+   rtvec_alloc_sizes += n * sizeof (rtx);
+ #endif
+ 
    return rt;
  }
  
*************** rtx_alloc (RTX_CODE code)
*** 171,176 ****
--- 185,196 ----
  
    memset (rt, 0, RTX_HDR_SIZE);
    PUT_CODE (rt, code);
+ 
+ #ifdef GATHER_STATISTICS
+   rtx_alloc_counts[code]++;
+   rtx_alloc_sizes[code] += RTX_SIZE (code);
+ #endif
+ 
    return rt;
  }
  
*************** rtx_equal_p (rtx x, rtx y)
*** 416,421 ****
--- 436,471 ----
  	}
      }
    return 1;
+ }
+ 
+ void dump_rtx_statistics (void)
+ {
+ #ifdef GATHER_STATISTICS
+   int i;
+   int total_counts = 0;
+   int total_sizes = 0;
+   fprintf (stderr, "\nRTX Kind               Count      Bytes\n");
+   fprintf (stderr, "---------------------------------------\n");
+   for (i = 0; i < LAST_AND_UNUSED_RTX_CODE; i++)
+     if (rtx_alloc_counts[i])
+       {
+         fprintf (stderr, "%-20s %7d %10d\n", GET_RTX_NAME (i),
+                  rtx_alloc_counts[i], rtx_alloc_sizes[i]);
+         total_counts += rtx_alloc_counts[i];
+         total_sizes += rtx_alloc_sizes[i];
+       }
+   if (rtvec_alloc_counts)
+     {
+       fprintf (stderr, "%-20s %7d %10d\n", "rtvec",
+                rtvec_alloc_counts, rtvec_alloc_sizes);
+       total_counts += rtvec_alloc_counts;
+       total_sizes += rtvec_alloc_sizes;
+     }
+   fprintf (stderr, "---------------------------------------\n");
+   fprintf (stderr, "%-20s %7d %10d\n",
+            "Total", total_counts, total_sizes);
+   fprintf (stderr, "---------------------------------------\n");
+ #endif  
  }
  
  #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007)
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.845
diff -c -3 -p -r1.845 toplev.c
*** toplev.c	21 Nov 2003 04:05:05 -0000	1.845
--- toplev.c	25 Nov 2003 19:23:02 -0000
*************** finalize (void)
*** 4561,4566 ****
--- 4561,4567 ----
        ggc_print_statistics ();
        stringpool_statistics ();
        dump_tree_statistics ();
+       dump_rtx_statistics ();
      }
  
    /* Free up memory for the benefit of leak detectors.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]