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]

[Darwin] PATCH: avoid unnecessary allocation in darwin_make_decl_one_only


This won't make a huge difference in performance, but at least it kills one place where we were being gratuitously inefficient. We're currently allocating a new string every time we make a symbol one-only, even though there are only two distinct strings. This patch fixes that. Bootstrapped on powerpc-apple-darwin7.5.0.

OK to commit to mainline?

--Matt

Index: gcc/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 2.5170
diff -p -r2.5170 ChangeLog
*** gcc/ChangeLog	31 Aug 2004 09:26:18 -0000	2.5170
--- gcc/ChangeLog	31 Aug 2004 17:13:29 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2004-08-31  Matt Austern  <austern@apple.com>
+
+ 	* config/darwin.c (darwin_make_decl_one_only): Allocate section
+ 	names once per compilation, instead of once per symbol.
+ 	
  2004-08-31  Paolo Bonzini  <bonzini@gnu.org>

  	* Makefile.in (build_subdir): New substitution.
Index: gcc/config/darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.84
diff -p -r1.84 darwin.c
*** gcc/config/darwin.c	21 Aug 2004 06:49:16 -0000	1.84
--- gcc/config/darwin.c	31 Aug 2004 17:13:32 -0000
*************** darwin_encode_section_info (tree decl, r
*** 982,999 ****
      SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
  }

void
darwin_make_decl_one_only (tree decl)
{
! static const char *text_section = "__TEXT,__textcoal_nt,coalesced,no_toc";
! static const char *data_section = "__DATA,__datacoal_nt,coalesced,no_toc";


!   const char *sec = TREE_CODE (decl) == FUNCTION_DECL
!     ? text_section
!     : data_section;
    TREE_PUBLIC (decl) = 1;
    DECL_ONE_ONLY (decl) = 1;
!   DECL_SECTION_NAME (decl) = build_string (strlen (sec), sec);
  }

  void
--- 982,1008 ----
      SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
  }

+ static GTY(()) tree textcoal_section = 0;
+ static GTY(()) tree datacoal_section = 0;
+
  void
  darwin_make_decl_one_only (tree decl)
  {
!   tree sec = 0;
!   if (textcoal_section == 0)
!     {
!       static const char *ts = "__TEXT,__textcoal_nt,coalesced,no_toc";
!       static const char *ds = "__DATA,__datacoal_nt,coalesced,no_toc";
!       textcoal_section = build_string (strlen (ts), ts);
!       datacoal_section = build_string (strlen (ds), ds);
!     }

!   sec = TREE_CODE (decl) == FUNCTION_DECL
!     ? textcoal_section
!     : datacoal_section;
    TREE_PUBLIC (decl) = 1;
    DECL_ONE_ONLY (decl) = 1;
!   DECL_SECTION_NAME (decl) = sec;
  }

void


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