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]

Re: Trim down INSN_ADDRESSES memory usage


> > On Thu, Jan 22, 2004 at 11:37:54AM +0100, Jan Hubicka wrote:
> > > ! #define INSN_ADDRESSES(id) insn_addresses_[id]
> > 
> > You should validate ID.
> 
> OK, what would be best way to validate it and still make it possible to
> be LHS preferably without {( uglyness, like we do for RTL checking?

Hi,
I am testing the attached patch, it should get bounds checking right.

Honza

2004-01-22  Jan Hubicka  <jh@suse.cz>
	* flan.c (insn_address_): Turn into integer array.
	(insn_adeddresses_size): New.
	(init_insn_lengths): deallocate array
	(shorten_branches): Allocate array.
	(insn_addresses_new): New function.
	* insn-addr.h (insn_addresses_, insn_addresses_size): Declare
	(INSN_ADDRESSES_DEFN, INSN_ADDRESSES_ALLOCm INSN_ADDRESSES_FREE): Kill.
	(INSN_ADDRESSES, INSN_ADDRESSES_SIZE, INSN_ADDRESSES_NEW): Rewrite.
Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.306
diff -c -3 -p -r1.306 final.c
*** final.c	18 Jan 2004 22:37:26 -0000	1.306
--- final.c	21 Jan 2004 18:24:00 -0000
*************** dbr_sequence_length (void)
*** 314,320 ****
  
  static int *insn_lengths;
  
! varray_type insn_addresses_;
  
  /* Max uid for which the above arrays are valid.  */
  static int insn_lengths_max_uid;
--- 314,321 ----
  
  static int *insn_lengths;
  
! int *insn_addresses_;
! unsigned int insn_addresses_size;
  
  /* Max uid for which the above arrays are valid.  */
  static int insn_lengths_max_uid;
*************** init_insn_lengths (void)
*** 364,370 ****
        insn_lengths_max_uid = 0;
      }
  #ifdef HAVE_ATTR_length
!   INSN_ADDRESSES_FREE ();
  #endif
    if (uid_align)
      {
--- 365,372 ----
        insn_lengths_max_uid = 0;
      }
  #ifdef HAVE_ATTR_length
!   free (insn_addresses_);
!   insn_addresses_ = 0;
  #endif
    if (uid_align)
      {
*************** shorten_branches (rtx first ATTRIBUTE_UN
*** 880,886 ****
    insn_lengths_max_uid = max_uid;
    /* Syntax errors can lead to labels being outside of the main insn stream.
       Initialize insn_addresses, so that we get reproducible results.  */
!   INSN_ADDRESSES_ALLOC (max_uid);
  
    varying_length = xcalloc (max_uid, sizeof (char));
  
--- 882,889 ----
    insn_lengths_max_uid = max_uid;
    /* Syntax errors can lead to labels being outside of the main insn stream.
       Initialize insn_addresses, so that we get reproducible results.  */
!   insn_addresses_ = xmalloc (max_uid * sizeof (*insn_addresses_));
!   insn_addresses_size = max_uid;
  
    varying_length = xcalloc (max_uid, sizeof (char));
  
*************** shorten_branches (rtx first ATTRIBUTE_UN
*** 1296,1301 ****
--- 1299,1325 ----
  }
  
  #ifdef HAVE_ATTR_length
+ 
+ /* Given the insn and address, record it into insn_addresses array.  */
+ void
+ insn_addresses_new (rtx insn, int addr)
+ {
+   unsigned insn_uid = INSN_UID ((insn));
+ 
+   if (INSN_ADDRESSES_SET_P ())
+     {
+       if (insn_addresses_size <= insn_uid)
+ 	{
+ 	  insn_addresses_size = (insn_uid * 17 + 16) / 16;
+ 	  insn_addresses_ = xrealloc (insn_addresses_,
+ 				     insn_addresses_size *
+ 				     sizeof (*insn_addresses_));
+ 
+ 	}
+       insn_addresses_[insn_uid] = addr;
+     }
+ }
+ 
  /* Given the body of an INSN known to be generated by an ASM statement, return
     the number of machine instructions likely to be generated for this insn.
     This is used to compute its length.  */
Index: insn-addr.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/insn-addr.h,v
retrieving revision 1.6
diff -c -3 -p -r1.6 insn-addr.h
*** insn-addr.h	4 Jun 2002 07:07:48 -0000	1.6
--- insn-addr.h	22 Jan 2004 20:34:58 -0000
*************** Software Foundation, 59 Temple Place - S
*** 23,50 ****
  
  #include "varray.h"
  
! extern GTY(()) varray_type insn_addresses_;
  extern int insn_current_address;
  
! #define INSN_ADDRESSES_DEFN() varray_type insn_addresses_
! #define INSN_ADDRESSES(id) VARRAY_INT (insn_addresses_, (id))
! #define INSN_ADDRESSES_ALLOC(size) \
!   VARRAY_INT_INIT (insn_addresses_, (size), "insn_addresses")
! #define INSN_ADDRESSES_FREE() (insn_addresses_ = 0)
  #define INSN_ADDRESSES_SET_P() (insn_addresses_ != 0)
! #define INSN_ADDRESSES_SIZE() VARRAY_SIZE (insn_addresses_)
! #define INSN_ADDRESSES_NEW(insn, addr) do \
!   {									\
!     unsigned insn_uid__ = INSN_UID ((insn));				\
!     int insn_addr__ = (addr);						\
! 									\
!     if (INSN_ADDRESSES_SET_P ())					\
!       {									\
! 	if (INSN_ADDRESSES_SIZE () <= insn_uid__)			\
! 	  VARRAY_GROW (insn_addresses_, insn_uid__ + 1);		\
! 	INSN_ADDRESSES (insn_uid__) = insn_addr__;			\
!       }									\
!   }									\
! while (0)
  
  #endif /* ! GCC_INSN_ADDR_H */
--- 23,42 ----
  
  #include "varray.h"
  
! extern int *insn_addresses_;
! extern unsigned int insn_addresses_size;
  extern int insn_current_address;
+ extern void insn_addresses_new (rtx, int);
  
! #ifdef ENABLE_CHECKING
! #define INSN_ADDRESSES(id) \
!    insn_addresses_[(unsigned int)(id) < insn_addresses_size \
!    		   ? (id) : (abort (), 0)]
! #else
! #define INSN_ADDRESSES(id) insn_addresses_[(id)]
! #endif
  #define INSN_ADDRESSES_SET_P() (insn_addresses_ != 0)
! #define INSN_ADDRESSES_SIZE() insn_addresses_size
! #define INSN_ADDRESSES_NEW(insn, addr) insn_addresses_new (insn, addr)
  
  #endif /* ! GCC_INSN_ADDR_H */


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