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]

[PATCH] SHF_MERGE support for gcc (take 3)


Hi!

This is an updated version of the SHF_MERGE patch, which fixes one bug
(it apparently did not work if HOST_WIDE_INT was larger than host word size
due to missing cast) and allows frontends to override what kind of constant
merging they want by default.
For !optimize, the default is always -fno-merge-constants, otherwise
the default is -fmerge-constants, unless overridden (the f/com.c hunk below
overrides it for Fortran, Ada should do probably the same).
Bootstrapped on i386-redhat-linux, no regressions.
Ok to commit?

Attached is a test script I used (is there something correspoinding to
'Additional sources' in gcc.dg framework?).
The script first of all tests for correctness, then checks what kind of
merging was done and what not (these are just printed on stdout, don't
result in an abort()), including whether string suffix merging is done or
not (you need a binutils patch I posted today so that { "foobar", "bar" } is
changed into { "foobar", "foobar" + 3 } by the linker (of course not limited
to an object scope)).

	Jakub
2001-05-04  Jakub Jelinek  <jakub@redhat.com>

	* configure.in: Check whether assembler supports section merging.
	* config.in: Rebuilt.
	* configure: Rebuilt.
	* varasm.c (variable_section, output_constant_pool): Pass alignment
	to SELECT_SECTION and SELECT_RTX_SECTION.
	* toplev.c (flag_merge_constants): New.
	(f_options): Add -fmerge-constants and -fmerge-all-constants
	options.
	(toplev_main): Default to -fno-merge-constants if not optimizing.
	* flags.h (flag_merge_constants): Add extern.
	* invoke.texi (-fmerge-constants, -fmerge-all-constants): Document.
	* tm.texi (SELECT_SECTION, SELECT_RTX_SECTION): Document added third
	argument.
	* config/elfos.h (EXTRA_SECTIONS): Add new sections.
	(EXTRA_SECTION_FUNCTIONS): Add CONST_STR_SECTION_FUNCTION and
	CONST_VAR_SECTION_FUNCTION.
	(USE_GAS_SUBSECTION_ORDERING, CONST_STR_SECTION_FUNCTION,
	CONST_VAR_SECTION_FUNCTION): Define.
	(SELECT_RTX_SECTION, SELECT_SECTION): Add third macro argument.
	Put constant into special SHF_MERGE sections if the linker should
	attempt to merge duplicates.
	* config/ia64/sysv4.h (EXTRA_SECTIONS): Add new sections.
	(EXTRA_SECTION_FUNCTIONS): Add CONST_STR_SECTION_FUNCTION and
	CONST_VAR_SECTION_FUNCTION.
	(SELECT_RTX_SECTION, SELECT_SECTION): Add third macro argument.
	Put constant into special SHF_MERGE sections if the linker should
	attempt to merge duplicates.
	* config/nextstep.h: Add third argument to SELECT_RTX_SECTION and
	SELECT_SECTION.
	* config/svr3.h: Likewise.
	* config/darwin.h: Likewise.
	* config/alpha/elf.h: Likewise.
	* config/arm/aof.h: Likewise.
	* config/arm/linux-elf.h: Likewise.
	* config/avr/avr.h: Likewise.
	* config/c4x/c4x.h: Likewise.
	* config/d30v/d30v.h: Likewise.
	* config/i386/dgux.h: Likewise.
	* config/i386/osfrose.h: Likewise.
	* config/i386/sco5.h: Likewise.
	* config/i386/svr3gas.h: Likewise.
	* config/m32r/m32r.h: Likewise.
	* config/m68k/m68k.h: Likewise.
	* config/m88k/dgux.h: Likewise.
	* config/m88k/m88k.h: Likewise.
	* config/mcore/mcore-pe.h: Likewise.
	* config/mips/mips.h: Likewise.
	* config/pa/pa-linux.h: Likewise.
	* config/pa/pa.h: Likewise.
	* config/romp/romp.h: Likewise.
	* config/rs6000/aix.h: Likewise.
	* config/rs6000/sysv4.h: Likewise.
	* config/sparc/sparc.h: Likewise.
	* config/sparc/sysv4.h: Likewise.
	* config/v850/v850.h: Likewise.
	* config/vax/vms.h: Likewise.

	* com.c (ffe_init_options): Default to -fmerge-all-constants
	if optimizing.

--- gcc/config/elfos.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/elfos.h	Thu May  3 20:46:54 2001
@@ -282,7 +282,15 @@ Boston, MA 02111-1307, USA.  */
    includes this file.  */
 
 #undef  EXTRA_SECTIONS
+#ifdef HAVE_GAS_SHF_MERGE
+#define EXTRA_SECTIONS in_const, in_ctors, in_dtors,	\
+  in_const_cst1, in_const_cst2, in_const_cst4, 		\
+  in_const_cst8, in_const_cst16, in_const_str1 = 256,	\
+  in_const_str2 = 256 + 32, in_const_str4 = 256 + 2*32,	\
+  in_const_str8 = 256 + 3*32
+#else
 #define EXTRA_SECTIONS in_const, in_ctors, in_dtors
+#endif
 
 /* A default list of extra section function definitions.  For targets
    that use additional sections (e.g. .tdesc) you should override this
@@ -292,10 +300,143 @@ Boston, MA 02111-1307, USA.  */
 #define EXTRA_SECTION_FUNCTIONS		\
   CONST_SECTION_FUNCTION		\
   CTORS_SECTION_FUNCTION		\
-  DTORS_SECTION_FUNCTION
+  DTORS_SECTION_FUNCTION		\
+  CONST_STR_SECTION_FUNCTION		\
+  CONST_VAR_SECTION_FUNCTION
 
 #define READONLY_DATA_SECTION() const_section ()
 
+#ifdef HAVE_GAS_SUBSECTION_ORDERING
+#define USE_GAS_SUBSECTION_ORDERING 1
+#else
+#define USE_GAS_SUBSECTION_ORDERING 0
+#endif
+
+#ifdef HAVE_GAS_SHF_MERGE
+#define CONST_STR_SECTION_FUNCTION					\
+extern void const_str_section PARAMS ((tree, unsigned HOST_WIDE_INT));	\
+									\
+void									\
+const_str_section (decl, align)						\
+     tree decl;								\
+     unsigned HOST_WIDE_INT align;					\
+{									\
+  enum in_section in;							\
+  enum machine_mode mode;						\
+  const char *str;							\
+  int i, j, len, unit;							\
+									\
+  if (flag_merge_constants						\
+      && USE_CONST_SECTION						\
+      && TREE_CODE (decl) == STRING_CST					\
+      && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE			\
+      && align <= 256)							\
+    {									\
+      mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));			\
+      switch (GET_MODE_BITSIZE (mode))					\
+	{								\
+	case 8: in = in_const_str1; break;				\
+	case 16: in = in_const_str2; break;				\
+	case 32: in = in_const_str4; break;				\
+	case 64: in = in_const_str8; break;				\
+	default: in = no_section; break;				\
+	}								\
+      if (align < GET_MODE_BITSIZE (mode))				\
+	align = GET_MODE_BITSIZE (mode);				\
+      if (in != no_section)						\
+	{								\
+	  str = TREE_STRING_POINTER (decl);				\
+	  len = TREE_STRING_LENGTH (decl);				\
+	  unit = GET_MODE_SIZE (mode);					\
+	  /* Check for embedded NUL characters.  */			\
+	  for (i = 0; i < len; i += unit)				\
+	    {								\
+	      for (j = 0; j < unit; j++)				\
+		if (str [i + j] != '\0')				\
+		  break;						\
+	      if (j == unit)						\
+		break;							\
+	    }								\
+	  if (i == len - unit)						\
+	    {								\
+	      unit = GET_MODE_BITSIZE (mode) / 8;			\
+	      if (!i && GET_MODE_BITSIZE (mode) < align)		\
+		{							\
+		  /* A "" string with requested alignment greater than	\
+		     character size might cause a problem:		\
+		     if some other string required even bigger		\
+		     alignment than "", then linker might think the	\
+		     "" is just part of padding after some other string	\
+		     and not put it into the hash table initially.	\
+		     But this means "" could have smaller alignment	\
+		     than requested.  */				\
+		  if (USE_GAS_SUBSECTION_ORDERING)			\
+		    fprintf (asm_out_file,				\
+"\t.section\t.rodata.str%d.%d,\"ams\",@progbits,%d\n\t.subsection\t-1",	\
+			     unit, (int) (align / 8), unit);		\
+		  else							\
+		    const_section ();					\
+		  return;						\
+		}							\
+	      in = (enum in_section) ((int) in + align / 8);		\
+	      if (in_section != in)					\
+		{							\
+		  fprintf (asm_out_file,				\
+"\t.section\t.rodata.str%d.%d,\"ams\",@progbits,%d\n",			\
+			   unit, (int) (align / 8), unit);		\
+		  in_section = in;					\
+		}							\
+	      return;							\
+	    }								\
+	}								\
+    }									\
+  const_section ();							\
+}
+
+#define CONST_VAR_SECTION_FUNCTION					\
+extern void const_var_section						\
+  PARAMS ((enum machine_mode, unsigned HOST_WIDE_INT));			\
+									\
+void									\
+const_var_section (mode, align)						\
+     enum machine_mode mode;						\
+     unsigned HOST_WIDE_INT align;					\
+{									\
+  if (flag_merge_constants && mode != VOIDmode && mode != BLKmode	\
+      && GET_MODE_BITSIZE (mode) <= align)				\
+    {									\
+      enum in_section in;						\
+									\
+      switch (align)							\
+	{								\
+	case 8: in = in_const_cst1; break;				\
+	case 16: in = in_const_cst2; break;				\
+	case 32: in = in_const_cst4; break;				\
+	case 64: in = in_const_cst8; break;				\
+	case 128: in = in_const_cst16; break;				\
+	default: in = no_section; break;				\
+	}								\
+      if (in_section != no_section)					\
+	{								\
+	  if (in_section != in)						\
+	    {								\
+	      fprintf (asm_out_file,					\
+"\t.section\t.rodata.cst%d,\"am\",@progbits,%d\n",			\
+		       (int) (align / 8), (int) (align / 8));		\
+	      in_section = in;						\
+	    }								\
+	  return;							\
+	}								\
+    }									\
+  const_section ();							\
+}
+#else
+#define CONST_STR_SECTION_FUNCTION
+#define CONST_VAR_SECTION_FUNCTION
+#define const_str_section(DECL,ALIGN) const_section ()
+#define const_var_section(MODE,ALIGN) const_section ()
+#endif
+
 #define CONST_SECTION_FUNCTION					\
 void								\
 const_section ()						\
@@ -468,11 +609,14 @@ dtors_section ()						\
 /* A C statement or statements to switch to the appropriate
    section for output of RTX in mode MODE.  RTX is some kind
    of constant in RTL.  The argument MODE is redundant except
-   in the case of a `const_int' rtx.  Currently, these always
-   go into the const section.  */
+   in the case of a `const_int' rtx.
+   If assembler supports SHF_MERGE sections, put it into
+   a .rodata.cstN section where N is size of the constant,
+   otherwise into const section.  */
 
 #undef  SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE, RTX) const_section ()
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN)	\
+  const_var_section ((MODE), (ALIGN))
 
 /* A C statement or statements to switch to the appropriate
    section for output of DECL.  DECL is either a `VAR_DECL' node
@@ -480,12 +624,12 @@ dtors_section ()						\
    the initial value of DECL requires link-time relocations.  */
 
 #undef SELECT_SECTION
-#define SELECT_SECTION(DECL, RELOC)				\
+#define SELECT_SECTION(DECL, RELOC, ALIGN)			\
 {								\
   if (TREE_CODE (DECL) == STRING_CST)				\
     {								\
       if (! flag_writable_strings)				\
-	const_section ();					\
+	const_str_section ((DECL), (ALIGN));			\
       else							\
 	data_section ();					\
     }								\
@@ -497,8 +641,15 @@ dtors_section ()						\
 	  || (DECL_INITIAL (DECL) != error_mark_node		\
 	      && !TREE_CONSTANT (DECL_INITIAL (DECL))))		\
 	data_section ();					\
-      else							\
+      else if (flag_merge_constants < 2)			\
+	/* C and C++ don't allow different variables to share	\
+	   the same location.  -fmerge-all-constants allows	\
+	   even that (at the expense of not conforming.  */	\
 	const_section ();					\
+      else if (TREE_CODE (DECL_INITIAL (DECL)) == STRING_CST)	\
+	const_str_section (DECL_INITIAL (DECL), (ALIGN));	\
+      else							\
+	const_var_section (DECL_MODE (DECL), (ALIGN));		\
     }								\
   else if (TREE_CODE (DECL) == CONSTRUCTOR)			\
     {								\
--- gcc/config/nextstep.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/nextstep.h	Thu May  3 20:14:04 2001
@@ -455,7 +455,7 @@ objc_section_init ()				\
 #define READONLY_DATA_SECTION const_section
 
 #undef	SELECT_SECTION
-#define SELECT_SECTION(exp,reloc)				\
+#define SELECT_SECTION(exp,reloc,align)				\
   do								\
     {								\
       if (TREE_CODE (exp) == STRING_CST)			\
@@ -573,7 +573,7 @@ objc_section_init ()				\
   while (0)
 
 #undef	SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(mode, rtx)					\
+#define SELECT_RTX_SECTION(mode, rtx, align)				\
   do									\
     {									\
       if (GET_MODE_SIZE(mode) == 8)					\
--- gcc/config/svr3.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/svr3.h	Thu May  3 20:14:04 2001
@@ -341,7 +341,7 @@ dtors_section ()							\
    or a constant of some sort.  RELOC indicates whether forming
    the initial value of DECL requires link-time relocations.  */
 
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
@@ -371,4 +371,4 @@ dtors_section ()							\
    in the case of a `const_int' rtx.  Currently, these always
    go into the const section.  */
 
-#define SELECT_RTX_SECTION(MODE,RTX) const_section()
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN) const_section()
--- gcc/config/darwin.h.jj	Thu May  3 20:07:24 2001
+++ gcc/config/darwin.h	Thu May  3 20:14:04 2001
@@ -512,7 +512,7 @@ void alias_section (name, alias)			\
 #define READONLY_DATA_SECTION const_section
 
 #undef	SELECT_SECTION
-#define SELECT_SECTION(exp,reloc)				\
+#define SELECT_SECTION(exp,reloc,align)				\
   do								\
     {								\
       if (TREE_CODE (exp) == STRING_CST)			\
@@ -636,7 +636,7 @@ void alias_section (name, alias)			\
   while (0)
 
 #undef	SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(mode, rtx)					\
+#define SELECT_RTX_SECTION(mode, rtx, align)				\
   do									\
     {									\
       if (GET_MODE_SIZE (mode) == 8)					\
--- gcc/config/alpha/elf.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/alpha/elf.h	Thu May  3 20:14:04 2001
@@ -436,7 +436,7 @@ void FN ()					\
    while (0)
 
 #undef  SELECT_SECTION
-#define SELECT_SECTION(DECL, RELOC)		\
+#define SELECT_SECTION(DECL, RELOC, ALIGN)	\
   do						\
     {						\
       typedef void (*sec_fn) PARAMS ((void));	\
@@ -503,7 +503,7 @@ void FN ()					\
    go into the const section.  */
 
 #undef  SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE, RTX) \
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN) \
    const_section()
 
 /* Define the strings used for the special svr4 .type and .size directives.
--- gcc/config/arm/aof.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/arm/aof.h	Thu May  3 20:14:04 2001
@@ -55,7 +55,7 @@ Boston, MA 02111-1307, USA.  */
 char *aof_text_section ();
 #define TEXT_SECTION_ASM_OP aof_text_section ()
 
-#define SELECT_RTX_SECTION(MODE,RTX) text_section ();
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN) text_section ();
 
 char *aof_data_section ();
 #define DATA_SECTION_ASM_OP aof_data_section ()
--- gcc/config/arm/linux-elf.h.jj	Thu May  3 20:07:25 2001
+++ gcc/config/arm/linux-elf.h	Thu May  3 20:14:04 2001
@@ -150,7 +150,7 @@ const_section ()							\
    section for output of DECL.  DECL is either a `VAR_DECL' node
    or a constant of some sort.  RELOC indicates whether forming
    the initial value of DECL requires link-time relocations.  */
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
@@ -217,7 +217,7 @@ const_section ()							\
    of constant in RTL.  The argument MODE is redundant except
    in the case of a `const_int' rtx.  Currently, these always
    go into the const section.  */
-#define SELECT_RTX_SECTION(MODE,RTX) const_section ()
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN) const_section ()
 
 /* On svr4, we *do* have support for the .init and .fini sections, and we
    can put stuff in there to be executed before and after `main'.  We let
--- gcc/config/avr/avr.h.jj	Thu May  3 20:07:27 2001
+++ gcc/config/avr/avr.h	Thu May  3 20:14:04 2001
@@ -2027,7 +2027,7 @@ progmem_section (void)							      \
    If these items should be placed in the text section, this macro
    should not be defined.  */
 
-/* `SELECT_SECTION (EXP, RELOC)'
+/* `SELECT_SECTION (EXP, RELOC, ALIGN)'
    A C statement or statements to switch to the appropriate section
    for output of EXP.  You can assume that EXP is either a `VAR_DECL'
    node or a constant of some sort.  RELOC indicates whether the
@@ -2038,7 +2038,7 @@ progmem_section (void)							      \
    Do not define this macro if you put all read-only variables and
    constants in the read-only data section (usually the text section).  */
 
-/* `SELECT_RTX_SECTION (MODE, RTX)'
+/* `SELECT_RTX_SECTION (MODE, RTX, ALIGN)'
    A C statement or statements to switch to the appropriate section
    for output of RTX in mode MODE.  You can assume that RTX is some
    kind of constant in RTL.  The argument MODE is redundant except in
--- gcc/config/c4x/c4x.h.jj	Thu May  3 20:07:28 2001
+++ gcc/config/c4x/c4x.h	Thu May  3 20:14:04 2001
@@ -2118,7 +2118,7 @@ dtors_section ()							\
    or a constant of some sort.  RELOC indicates whether forming
    the initial value of DECL requires link-time relocations.  */
 
-#define SELECT_SECTION(DECL, RELOC)					\
+#define SELECT_SECTION(DECL, RELOC, ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
@@ -2163,7 +2163,7 @@ dtors_section ()							\
    in the case of a `const_int' rtx.  Currently, these always
    go into the const section.  */
 
-#define SELECT_RTX_SECTION(MODE, RTX) const_section()
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN) const_section()
 
 
 /* Overall Framework of an Assembler File.  */
--- gcc/config/d30v/d30v.h.jj	Thu May  3 20:07:30 2001
+++ gcc/config/d30v/d30v.h	Thu May  3 20:14:04 2001
@@ -3945,7 +3945,7 @@ extern const char *d30v_branch_cost_stri
    the read-only data section (usually the text section).
 
    Defined in svr4.h.  */
-/* #define SELECT_SECTION(EXP, RELOC) */
+/* #define SELECT_SECTION(EXP, RELOC, ALIGN) */
 
 /* A C statement or statements to switch to the appropriate section for output
    of RTX in mode MODE.  You can assume that RTX is some kind of constant in
@@ -3957,7 +3957,7 @@ extern const char *d30v_branch_cost_stri
    section.
 
    Defined in svr4.h.  */
-/* #define SELECT_RTX_SECTION(MODE, RTX) */
+/* #define SELECT_RTX_SECTION(MODE, RTX, ALIGN) */
 
 /* Define this macro if jump tables (for `tablejump' insns) should be output in
    the text section, along with the assembler instructions.  Otherwise, the
--- gcc/config/i386/dgux.h.jj	Thu May  3 20:07:30 2001
+++ gcc/config/i386/dgux.h	Thu May  3 20:14:04 2001
@@ -232,7 +232,7 @@ Boston, MA 02111-1307, USA.  */
 
 /* Must use data section for relocatable constants when pic.  */
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)            \
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)      \
 {                                               \
   if (flag_pic && symbolic_operand (RTX, VOIDmode)) \
     data_section ();                            \
--- gcc/config/i386/osfrose.h.jj	Thu May  3 20:07:30 2001
+++ gcc/config/i386/osfrose.h	Thu May  3 20:14:04 2001
@@ -571,7 +571,7 @@ while (0)
    and select that section.  */
 
 #undef	SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE, RTX)					\
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN)				\
 do									\
   {									\
     if (MODE == Pmode && HALF_PIC_P () && HALF_PIC_ADDRESS_P (RTX))	\
@@ -582,7 +582,7 @@ do									\
 while (0)
 
 #undef	SELECT_SECTION
-#define SELECT_SECTION(DECL, RELOC)					\
+#define SELECT_SECTION(DECL, RELOC, ALIGN)				\
 {									\
   if (RELOC && HALF_PIC_P ())						\
     data_section ();							\
--- gcc/config/i386/sco5.h.jj	Thu May  3 20:07:30 2001
+++ gcc/config/i386/sco5.h	Thu May  3 20:14:04 2001
@@ -374,7 +374,7 @@ do {									\
 
 /* Must use data section for relocatable constants when pic.  */
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)					\
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)				\
 {									\
   if (TARGET_ELF) {							\
     if (flag_pic && symbolic_operand (RTX, VOIDmode))			\
@@ -663,7 +663,7 @@ dtors_section ()							\
    : 0))
 
 #undef SELECT_SECTION
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TARGET_ELF && flag_pic && RELOC)					\
      data_section ();							\
--- gcc/config/i386/svr3gas.h.jj	Thu May  3 20:07:30 2001
+++ gcc/config/i386/svr3gas.h	Thu May  3 20:14:04 2001
@@ -231,7 +231,7 @@ dtors_section ()							\
    or a constant of some sort.  RELOC indicates whether forming
    the initial value of DECL requires link-time relocations.  */
 
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
@@ -261,7 +261,7 @@ dtors_section ()							\
    in the case of a `const_int' rtx.  Currently, these always
    go into the const section.  */
 
-#define SELECT_RTX_SECTION(MODE,RTX) const_section()
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN) const_section()
 
 /* This is copied from i386/sysv3.h.  */
 
--- gcc/config/ia64/sysv4.h.jj	Thu May  3 20:07:31 2001
+++ gcc/config/ia64/sysv4.h	Thu May  3 20:14:04 2001
@@ -182,12 +182,12 @@ do {									\
 /* We override svr4.h so that we can support the sdata section.  */
 
 #undef SELECT_SECTION
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
       if (! flag_writable_strings)					\
-	const_section ();						\
+	const_str_section ((DECL), (ALIGN));				\
       else								\
 	data_section ();						\
     }									\
@@ -196,13 +196,20 @@ do {									\
       if (XSTR (XEXP (DECL_RTL (DECL), 0), 0)[0]			\
 	  == SDATA_NAME_FLAG_CHAR)					\
         sdata_section ();						\
-      /* ??? We need the extra ! RELOC check, because the default is to \
+      /* ??? We need the extra RELOC check, because the default is to	\
 	 only check RELOC if flag_pic is set, and we don't set flag_pic \
 	 (yet?).  */							\
-      else if (DECL_READONLY_SECTION (DECL, RELOC) && ! (RELOC))	\
+      else if (!DECL_READONLY_SECTION (DECL, RELOC) || (RELOC))		\
+	data_section ();						\
+      else if (flag_merge_constants < 2)				\
+	/* C and C++ don't allow different variables to share		\
+	   the same location.  -fmerge-all-constants allows		\
+	   even that (at the expense of not conforming.  */		\
 	const_section ();						\
+      else if (TREE_CODE (DECL_INITIAL (DECL)) == STRING_CST)		\
+	const_str_section (DECL_INITIAL (DECL), (ALIGN));		\
       else								\
-	data_section ();						\
+	const_var_section (DECL_MODE (DECL), (ALIGN));			\
     }									\
   /* This could be a CONSTRUCTOR containing ADDR_EXPR of a VAR_DECL,	\
      in which case we can't put it in a shared library rodata.  */	\
@@ -216,7 +223,7 @@ do {									\
 
 extern unsigned int ia64_section_threshold;
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE, RTX)					\
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN)				\
 {									\
   if (GET_MODE_SIZE (MODE) > 0						\
       && GET_MODE_SIZE (MODE) <= ia64_section_threshold)		\
@@ -224,11 +231,19 @@ extern unsigned int ia64_section_thresho
   else if (flag_pic && symbolic_operand ((RTX), (MODE)))		\
     data_section ();							\
   else									\
-    const_section ();							\
+    const_var_section ((MODE), (ALIGN));				\
 }
 
 #undef EXTRA_SECTIONS
+#ifdef HAVE_GAS_SHF_MERGE
+#define EXTRA_SECTIONS in_const, in_ctors, in_dtors,			\
+  in_sdata, in_sbss, in_const_cst1, in_const_cst2, in_const_cst4,	\
+  in_const_cst8, in_const_cst16, 					\
+  in_const_str1 = 256, in_const_str2 = 256 + 32,			\
+  in_const_str4 = 256 + 2*32, in_const_str8 = 256 + 3*32
+#else
 #define EXTRA_SECTIONS in_const, in_ctors, in_dtors, in_sdata, in_sbss
+#endif
 
 #undef EXTRA_SECTION_FUNCTIONS
 #define EXTRA_SECTION_FUNCTIONS						\
@@ -236,7 +251,9 @@ extern unsigned int ia64_section_thresho
   CTORS_SECTION_FUNCTION						\
   DTORS_SECTION_FUNCTION						\
   SDATA_SECTION_FUNCTION						\
-  SBSS_SECTION_FUNCTION
+  SBSS_SECTION_FUNCTION							\
+  CONST_STR_SECTION_FUNCTION						\
+  CONST_VAR_SECTION_FUNCTION
 
 #define SDATA_SECTION_ASM_OP "\t.sdata"
 
--- gcc/config/m32r/m32r.h.jj	Thu May  3 20:07:31 2001
+++ gcc/config/m32r/m32r.h	Thu May  3 20:14:04 2001
@@ -1630,7 +1630,8 @@ sbss_section ()								\
    or a constant of some sort.  RELOC indicates whether the initial value
    of EXP requires link-time relocations.  */
 #undef  SELECT_SECTION
-#define SELECT_SECTION(EXP, RELOC) m32r_select_section ((EXP), (RELOC))
+#define SELECT_SECTION(EXP, RELOC, ALIGN) \
+  m32r_select_section ((EXP), (RELOC))
 
 /* A C statement or statements to switch to the appropriate section for
    output of RTX in mode MODE.  You can assume that RTX
--- gcc/config/m68k/m68k.h.jj	Thu May  3 20:07:32 2001
+++ gcc/config/m68k/m68k.h	Thu May  3 20:14:04 2001
@@ -323,7 +323,7 @@ extern int target_flags;
 /* This is how to align an instruction for optimal branching. */
 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) (m68k_align_jumps)
 
-#define SELECT_RTX_SECTION(MODE, X)					\
+#define SELECT_RTX_SECTION(MODE, X, ALIGN)				\
 {									\
   if (!flag_pic)							\
     readonly_data_section();						\
--- gcc/config/m88k/dgux.h.jj	Thu May  3 20:07:32 2001
+++ gcc/config/m88k/dgux.h	Thu May  3 20:14:04 2001
@@ -294,7 +294,7 @@ func_ptr __DTOR_END__[1] = { (func_ptr) 
 
 /* Must use data section for relocatable constants when pic.  */
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)            \
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)      \
 {                                               \
   if (flag_pic && symbolic_operand (RTX))       \
     data_section ();                            \
--- gcc/config/m88k/m88k.h.jj	Thu May  3 20:07:33 2001
+++ gcc/config/m88k/m88k.h	Thu May  3 20:14:04 2001
@@ -2528,7 +2528,7 @@ sdata_section ()							\
 
    For strings, the section is selected before the segment info is encoded.  */
 #undef	SELECT_SECTION
-#define SELECT_SECTION(DECL,RELOC)					\
+#define SELECT_SECTION(DECL,RELOC,ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
--- gcc/config/mcore/mcore-pe.h.jj	Thu May  3 20:07:33 2001
+++ gcc/config/mcore/mcore-pe.h	Thu May  3 20:14:04 2001
@@ -81,7 +81,7 @@ rdata_section ()						\
    or a constant of some sort.  RELOC indicates whether forming
    the initial value of DECL requires link-time relocations.  */
 #undef  SELECT_SECTION
-#define SELECT_SECTION(DECL, RELOC)					\
+#define SELECT_SECTION(DECL, RELOC, ALIGN)				\
 {									\
   if (TREE_CODE (DECL) == STRING_CST)					\
     {									\
@@ -111,7 +111,7 @@ rdata_section ()						\
    in the case of a `const_int' rtx.  Currently, these always
    go into the const section.  */
 #undef  SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE, RTX) rdata_section ()
+#define SELECT_RTX_SECTION(MODE, RTX, ALIGN) rdata_section ()
 
 #define MCORE_EXPORT_NAME(STREAM, NAME)			\
   do							\
--- gcc/config/mips/mips.h.jj	Thu May  3 20:07:35 2001
+++ gcc/config/mips/mips.h	Thu May  3 20:15:06 2001
@@ -4526,10 +4526,12 @@ rdata_section ()							\
    and select that section.  */
 
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)	mips_select_rtx_section (MODE, RTX)
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)	\
+  mips_select_rtx_section (MODE, RTX)
 
 #undef SELECT_SECTION
-#define SELECT_SECTION(DECL, RELOC)	mips_select_section (DECL, RELOC)
+#define SELECT_SECTION(DECL, RELOC, ALIGN)	\
+  mips_select_section (DECL, RELOC)
 
 
 /* Store in OUTPUT a string (made with alloca) containing
--- gcc/config/pa/pa-linux.h.jj	Thu May  3 20:07:35 2001
+++ gcc/config/pa/pa-linux.h	Thu May  3 20:14:04 2001
@@ -57,7 +57,7 @@ Boston, MA 02111-1307, USA.  */
 
 /* Put plabels into the data section so we can relocate them.  */
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)	\
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)	\
   if (flag_pic && function_label_operand (RTX, MODE))	\
     data_section ();					\
   else							\
--- gcc/config/pa/pa.h.jj	Thu May  3 20:07:36 2001
+++ gcc/config/pa/pa.h	Thu May  3 20:14:04 2001
@@ -1451,7 +1451,7 @@ do { 									\
    library.  Since we can't know at compile time if a symbol will be
    satisfied by a shared library or main program we put any symbolic
    constant into the normal data section.  */
-#define SELECT_RTX_SECTION(MODE,RTX)	\
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)	\
   if (symbolic_operand (RTX, MODE))	\
     data_section ();			\
   else					\
@@ -1461,7 +1461,7 @@ do { 									\
    in the read-only data section to a symbol defined in a shared
    library.  Therefore, expressions that might require a reloc can
    not be placed in the read-only data section.  */
-#define SELECT_SECTION(EXP,RELOC) \
+#define SELECT_SECTION(EXP,RELOC,ALIGN) \
   if (TREE_CODE (EXP) == VAR_DECL \
       && TREE_READONLY (EXP) \
       && !TREE_THIS_VOLATILE (EXP) \
--- gcc/config/romp/romp.h.jj	Thu May  3 20:07:36 2001
+++ gcc/config/romp/romp.h	Thu May  3 20:14:04 2001
@@ -717,7 +717,7 @@ struct rt_cargs {int gregs, fregs; };
 
    On ROMP, all constants are in the data area.  */
 
-#define SELECT_RTX_SECTION(MODE, X)	data_section ()
+#define SELECT_RTX_SECTION(MODE, X, ALIGN)	data_section ()
 
 /* This macro generates the assembly code for function entry.
    FILE is a stdio stream to output the code to.
--- gcc/config/rs6000/aix.h.jj	Thu May  3 20:07:37 2001
+++ gcc/config/rs6000/aix.h	Thu May  3 20:14:04 2001
@@ -219,7 +219,7 @@ toc_section ()						\
    On the RS/6000, we have a special section for all variables except those
    that are static.  */
 
-#define SELECT_SECTION(EXP,RELOC)			\
+#define SELECT_SECTION(EXP,RELOC,ALIGN)			\
 {							\
   if ((TREE_CODE (EXP) == STRING_CST			\
        && ! flag_writable_strings)			\
@@ -274,7 +274,7 @@ toc_section ()						\
    However, if this is being placed in the TOC it must be output as a
    toc entry.  */
 
-#define SELECT_RTX_SECTION(MODE, X)			\
+#define SELECT_RTX_SECTION(MODE, X, ALIGN)		\
 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE))	\
     toc_section ();					\
   else							\
--- gcc/config/rs6000/sysv4.h.jj	Thu May  3 20:07:37 2001
+++ gcc/config/rs6000/sysv4.h	Thu May  3 20:14:04 2001
@@ -573,7 +573,7 @@ fini_section ()								\
 
 /* Override elfos.h definition.  */
 #undef	SELECT_RTX_SECTION
-#define	SELECT_RTX_SECTION(MODE, X) rs6000_select_rtx_section (MODE, X)
+#define	SELECT_RTX_SECTION(MODE, X, ALIGN) rs6000_select_rtx_section (MODE, X)
 
 /* A C statement or statements to switch to the appropriate
    section for output of DECL.  DECL is either a `VAR_DECL' node
@@ -582,7 +582,7 @@ fini_section ()								\
 
 /* Override elfos.h definition.  */
 #undef	SELECT_SECTION
-#define	SELECT_SECTION(DECL, RELOC) rs6000_select_section (DECL, RELOC)
+#define	SELECT_SECTION(DECL, RELOC, ALIGN) rs6000_select_section (DECL, RELOC)
 
 /* A C statement to build up a unique section name, expressed as a
    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
--- gcc/config/sparc/sparc.h.jj	Thu May  3 20:07:38 2001
+++ gcc/config/sparc/sparc.h	Thu May  3 20:14:04 2001
@@ -911,7 +911,7 @@ if (TARGET_ARCH64				\
 #endif
 
 /* This is defined differently for v9 in a cover file.  */
-#define SELECT_SECTION(T,RELOC)						\
+#define SELECT_SECTION(T,RELOC,ALIGN)					\
 {									\
   if (TREE_CODE (T) == VAR_DECL)					\
     {									\
@@ -944,7 +944,7 @@ if (TARGET_ARCH64				\
 /* Use text section for a constant
    unless we need more alignment than that offers.  */
 /* This is defined differently for v9 in a cover file.  */
-#define SELECT_RTX_SECTION(MODE, X)		\
+#define SELECT_RTX_SECTION(MODE, X, ALIGN)	\
 {						\
   if (GET_MODE_BITSIZE (MODE) <= MAX_TEXT_ALIGN \
       && ! (flag_pic && (symbolic_operand ((X), (MODE)) || SUNOS4_SHARED_LIBRARIES)))  \
--- gcc/config/sparc/sysv4.h.jj	Thu May  3 20:07:39 2001
+++ gcc/config/sparc/sysv4.h	Thu May  3 20:14:04 2001
@@ -79,7 +79,7 @@ Boston, MA 02111-1307, USA.  */
 
 /* Must use data section for relocatable constants when pic.  */
 #undef SELECT_RTX_SECTION
-#define SELECT_RTX_SECTION(MODE,RTX)		\
+#define SELECT_RTX_SECTION(MODE,RTX,ALIGN)	\
 {						\
   if (flag_pic && symbolic_operand ((RTX), (MODE))) \
     data_section ();				\
--- gcc/config/v850/v850.h.jj	Thu May  3 20:07:39 2001
+++ gcc/config/v850/v850.h	Thu May  3 20:14:04 2001
@@ -1179,7 +1179,7 @@ zbss_section ()								\
    Do not define this macro if you put all read-only variables and
    constants in the read-only data section (usually the text section).  */
 #undef  SELECT_SECTION
-#define SELECT_SECTION(EXP, RELOC)					\
+#define SELECT_SECTION(EXP, RELOC, ALIGN)				\
 do {									\
   if (TREE_CODE (EXP) == VAR_DECL)					\
     {									\
@@ -1242,7 +1242,7 @@ do {									\
 
    Do not define this macro if you put all constants in the read-only
    data section.  */
-/* #define SELECT_RTX_SECTION(MODE, RTX) */
+/* #define SELECT_RTX_SECTION(MODE, RTX, ALIGN) */
 
 /* Output at beginning/end of assembler file.  */
 #undef ASM_FILE_START
--- gcc/config/vax/vms.h.jj	Thu May  3 20:07:40 2001
+++ gcc/config/vax/vms.h	Thu May  3 20:14:04 2001
@@ -249,7 +249,7 @@ const_section ()					\
    Since this macro is used in a number of places, we must also be able
    to decide where to place string constants.  */
 
-#define SELECT_SECTION(T,RELOC)						\
+#define SELECT_SECTION(T,RELOC,ALIGN)					\
 {									\
   if (TREE_CODE (T) == VAR_DECL)					\
     {									\
--- gcc/f/com.c.jj	Thu May  3 20:03:39 2001
+++ gcc/f/com.c	Fri May  4 00:25:11 2001
@@ -14657,6 +14657,7 @@ ffe_init_options ()
   flag_move_all_movables = 1;
   flag_reduce_all_givs = 1;
   flag_argument_noalias = 2;
+  flag_merge_constants = 2;
   flag_errno_math = 0;
   flag_complex_divide_method = 1;
 }
--- gcc/varasm.c.jj	Thu May  3 20:07:24 2001
+++ gcc/varasm.c	Thu May  3 20:14:04 2001
@@ -452,7 +452,7 @@ variable_section (decl, reloc)
 	 for them.  */
 
 #ifdef SELECT_SECTION
-      SELECT_SECTION (decl, reloc);
+      SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
 #else
       if (DECL_READONLY_SECTION (decl, reloc))
 	readonly_data_section ();
@@ -3214,13 +3214,19 @@ output_constant_def_contents (exp, reloc
 {
   int align;
 
+  /* Align the location counter as required by EXP's data type.  */
+  align = TYPE_ALIGN (TREE_TYPE (exp));
+#ifdef CONSTANT_ALIGNMENT
+  align = CONSTANT_ALIGNMENT (exp, align);
+#endif
+
   if (IN_NAMED_SECTION (exp))
     named_section (exp, NULL, reloc);
   else
     {
       /* First switch to text section, except for writable strings.  */
 #ifdef SELECT_SECTION
-      SELECT_SECTION (exp, reloc);
+      SELECT_SECTION (exp, reloc, align);
 #else
       if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
 	  || (flag_pic && reloc))
@@ -3230,12 +3236,6 @@ output_constant_def_contents (exp, reloc
 #endif
     }
 
-  /* Align the location counter as required by EXP's data type.  */
-  align = TYPE_ALIGN (TREE_TYPE (exp));
-#ifdef CONSTANT_ALIGNMENT
-  align = CONSTANT_ALIGNMENT (exp, align);
-#endif
-
   if (align > BITS_PER_UNIT)
     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
 
@@ -3786,7 +3786,7 @@ output_constant_pool (fnname, fndecl)
 
       /* First switch to correct section.  */
 #ifdef SELECT_RTX_SECTION
-      SELECT_RTX_SECTION (pool->mode, x);
+      SELECT_RTX_SECTION (pool->mode, x, pool->align * BITS_PER_UNIT);
 #else
       readonly_data_section ();
 #endif
--- gcc/configure.in.jj	Thu May  3 20:07:14 2001
+++ gcc/configure.in	Thu May  3 20:14:04 2001
@@ -1402,6 +1402,26 @@ if test x"$gcc_cv_as_leb128" = xyes; the
 fi
 AC_MSG_RESULT($gcc_cv_as_leb128)
 
+AC_MSG_CHECKING(assembler section merging support)
+gcc_cv_as_shf_merge=no
+if test x$gcc_cv_gas_major_version != x -a x$gcc_cv_gas_minor_version != x; then
+  if test "$gcc_cv_gas_major_version" -eq 2 -a "$gcc_cv_gas_minor_version" -ge 12 -o "$gcc_cv_gas_major_version" -gt 2 && grep 'obj_format = elf' ../gas/Makefile > /dev/null; then
+    gcc_cv_as_subsections="working SHF_MERGE support"
+  fi
+elif test x$gcc_cv_as != x; then
+	# Check if we support SHF_MERGE sections
+	echo '.section .rodata.str, "ams", @progbits, 1' > conftest.s
+	if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1; then
+		gcc_cv_as_shf_merge=yes
+	fi
+	rm -f conftest.s conftest.o
+fi
+if test x"$gcc_cv_as_shf_merge" = xyes; then
+	AC_DEFINE(HAVE_GAS_SHF_MERGE, 1,
+[Define if your assembler supports marking sections with SHF_MERGE flag.])
+fi
+AC_MSG_RESULT($gcc_cv_as_shf_merge)
+
 case "$target" in 
   sparc*-*-*)
     AC_CACHE_CHECK([assembler .register pseudo-op support],
--- gcc/config.in.jj	Thu May  3 20:07:13 2001
+++ gcc/config.in	Thu May  3 20:14:04 2001
@@ -469,6 +469,9 @@
 /* Define if your assembler supports .uleb128. */
 #undef HAVE_AS_LEB128
 
+/* Define if your assembler supports marking sections with SHF_MERGE flag. */
+#undef HAVE_GAS_SHF_MERGE
+
 /* Define if your assembler supports .register. */
 #undef HAVE_AS_REGISTER_PSEUDO_OP
 
--- gcc/tm.texi.jj	Thu May  3 20:07:23 2001
+++ gcc/tm.texi	Thu May  3 20:14:04 2001
@@ -5354,25 +5354,26 @@ If these items should be placed in the t
 not be defined.
 
 @findex SELECT_SECTION
-@item SELECT_SECTION (@var{exp}, @var{reloc})
+@item SELECT_SECTION (@var{exp}, @var{reloc}, @var{align})
 A C statement or statements to switch to the appropriate section for
 output of @var{exp}.  You can assume that @var{exp} is either a
 @code{VAR_DECL} node or a constant of some sort.  @var{reloc}
 indicates whether the initial value of @var{exp} requires link-time
 relocations.  Select the section by calling @code{text_section} or one
-of the alternatives for other sections.
+of the alternatives for other sections.  @var{align} is the constant
+alignment in bits.
 
 Do not define this macro if you put all read-only variables and
 constants in the read-only data section (usually the text section).
 
 @findex SELECT_RTX_SECTION
-@item SELECT_RTX_SECTION (@var{mode}, @var{rtx})
+@item SELECT_RTX_SECTION (@var{mode}, @var{rtx}, @var{align})
 A C statement or statements to switch to the appropriate section for
 output of @var{rtx} in mode @var{mode}.  You can assume that @var{rtx}
 is some kind of constant in RTL.  The argument @var{mode} is redundant
 except in the case of a @code{const_int} rtx.  Select the section by
 calling @code{text_section} or one of the alternatives for other
-sections.
+sections.  @var{align} is the constant alignment in bits.
 
 Do not define this macro if you put all constants in the read-only
 data section.
--- gcc/configure.jj	Thu May  3 20:07:14 2001
+++ gcc/configure	Thu May  3 20:14:05 2001
@@ -6819,6 +6819,29 @@ EOF
 fi
 echo "$ac_t""$gcc_cv_as_leb128" 1>&6
 
+echo $ac_n "checking assembler section merging support""... $ac_c" 1>&6
+echo "configure:6569: checking assembler section merging support" >&5
+gcc_cv_as_shf_merge=no
+if test x$gcc_cv_gas_major_version != x -a x$gcc_cv_gas_minor_version != x; then
+  if test "$gcc_cv_gas_major_version" -eq 2 -a "$gcc_cv_gas_minor_version" -ge 12 -o "$gcc_cv_gas_major_version" -gt 2 && grep 'obj_format = elf' ../gas/Makefile > /dev/null; then
+    gcc_cv_as_subsections="working SHF_MERGE support"
+  fi
+elif test x$gcc_cv_as != x; then
+	# Check if we support SHF_MERGE sections
+	echo '.section .rodata.str, "ams", @progbits, 1' > conftest.s
+	if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1; then
+		gcc_cv_as_shf_merge=yes
+	fi
+	rm -f conftest.s conftest.o
+fi
+if test x"$gcc_cv_as_shf_merge" = xyes; then
+	cat >> confdefs.h <<\EOF
+#define HAVE_GAS_SHF_MERGE 1
+EOF
+
+fi
+echo "$ac_t""$gcc_cv_as_shf_merge" 1>&6
+
 case "$target" in 
   sparc*-*-*)
     echo $ac_n "checking assembler .register pseudo-op support""... $ac_c" 1>&6
--- gcc/toplev.c.jj	Thu May  3 20:07:24 2001
+++ gcc/toplev.c	Thu May  3 20:19:15 2001
@@ -895,6 +895,11 @@ int flag_bounded_pointers = 0;
    For CHILL: defaults to off.  */
 int flag_bounds_check = 0;
 
+/* This will attempt to merge constant section constants, if 1 only
+   string constants and constants from constant pool, if 2 also constant
+   variables.  */
+int flag_merge_constants = 1;
+
 /* If one, renumber instruction UIDs to reduce the number of
    unused UIDs if there are a lot of instructions.  If greater than
    one, unconditionally renumber instruction UIDs.  */
@@ -1136,6 +1141,10 @@ lang_independent_options f_options[] =
    "Align all labels" },
   {"align-functions", &align_functions, 0,
    "Align the start of functions" },
+  {"merge-constants", &flag_merge_constants, 1,
+   "Attempt to merge identical constants accross compilation units"},
+  {"merge-all-constants", &flag_merge_constants, 2,
+   "Attempt to merge identical constants and constant variables" },
   {"check-memory-usage", &flag_check_memory_usage, 1,
    "Generate code to check every memory access" },
   {"prefix-function-name", &flag_prefix_function_name, 1,
@@ -4709,6 +4718,11 @@ toplev_main (argc, argv)
 		}
 	    }
 	}
+    }
+
+  if (!optimize)
+    {
+      flag_merge_constants = 0;
     }
 
   if (optimize >= 1)
--- gcc/flags.h.jj	Thu May  3 20:07:16 2001
+++ gcc/flags.h	Thu May  3 20:14:06 2001
@@ -550,6 +550,11 @@ extern int flag_bounded_pointers;
    For CHILL: defaults to off.  */
 extern int flag_bounds_check;
 
+/* This will attempt to merge constant section constants, if 1 only
+   string constants and constants from constant pool, if 2 also constant
+   variables.  */
+extern int flag_merge_constants;
+
 /* If one, renumber instruction UIDs to reduce the number of
    unused UIDs if there are a lot of instructions.  If greater than
    one, unconditionally renumber instruction UIDs.  */
--- gcc/invoke.texi.jj	Thu May  3 20:07:20 2001
+++ gcc/invoke.texi	Thu May  3 20:14:06 2001
@@ -253,8 +253,8 @@ in the following sections.
 -fexpensive-optimizations  -ffast-math  -ffloat-store @gol
 -fforce-addr  -fforce-mem  -ffunction-sections  -fgcse  -fgcse-lm -fgcse-sm @gol
 -finline-functions  -finline-limit=@var{n}  -fkeep-inline-functions @gol
--fkeep-static-consts  -fmove-all-movables @gol
--fno-default-inline  -fno-defer-pop @gol
+-fkeep-static-consts  -fmerge-constants  -fmerge-all-constants @gol
+-fmove-all-movables  -fno-default-inline  -fno-defer-pop @gol
 -fno-function-cse   -fno-guess-branch-probability @gol
 -fno-inline  -fno-math-errno  -fno-peephole @gol
 -funsafe-math-optimizations -fno-trapping-math @gol
@@ -3054,6 +3054,23 @@ on, even if the variables aren't referen
 GCC enables this option by default.  If you want to force the compiler to
 check if the variable was referenced, regardless of whether or not
 optimization is turned on, use the @samp{-fno-keep-static-consts} option.
+
+@item -fmerge-constants
+Attempt to merge identical constants (string constants and floating point
+constants) accross compilation units.
+
+This option is default for optimized compilation if assembler and linker
+support it.  Use @samp{-fno-merge-constants} to inhibit this behaviour.
+
+@item -fmerge-all-constants
+Attempt to merge identical constants and identical variables.
+
+This option implies @samp{-fmerge-constants}.  In addition to
+@samp{-fmerge-constants} this considers e.g. even constant initialized
+arrays or initialized constant variables with integral or floating point
+types.  Languages like C or C++ require each non-automatic variable to
+have distinct location, so using this option will result in non-conforming
+behaviour.
 
 @item -fno-function-cse
 Do not put function addresses in registers; make each instruction that
#!/bin/sh
cat > merge1.c <<EOF
char *p[] = { "foobar", "bar" };
char *q = "ar";
char *r = "foobar"+2;
const char s[] = "baaarbaz";
char *t = "r";
const long double k = 7.0L;

double foo(double *a, double *b, double *c)
{
  if (p[0][0] != 'f' || p[0][1] != 'o' || p[0][2] != 'o' || p[0][3] != 'b' || p[0][4] != 'a' || p[0][5] != 'r' || p[0][6])
    abort ();
  if (p[1][0] != 'b' || p[1][1] != 'a' || p[1][2] != 'r' || p[1][3])
    abort ();
  if (q[0] != 'a' || q[1] != 'r' || q[2])
    abort ();
  if (r[-2] != 'f' || r[-1] != 'o' || r[0] != 'o' || r[1] != 'b' || r[2] != 'a' || r[3] != 'r' || r[4])
    abort ();
  if (s[0] != 'b' || s[1] != 'a' || s[2] != 'a' || s[3] != 'a' || s[4] != 'r' || s[5] != 'b' || s[6] != 'a' || s[7] != 'z' || s[8])
    abort ();
  if (t[0] != 'r' || t[1])
    abort ();
  *a = 0.0; *b = 4.0; *c = 16.0;
  return 64.0;
}
EOF
cat > merge2.c <<EOF
extern char *p[], *q, *r, *t;
extern const char s[];
char *o = "aarbaz";
char *u = "foobar";
char *v = "bar";
char *w = "foobar"+2;
const char x[] = "baaarbaz";
char *y = "r";
char *z = "rbaz";
const long double l = 7.0L;

double bar(double *a, double *b, double *c)
{
  if (o[0] != 'a' || o[1] != 'a' || o[2] != 'r' || o[3] != 'b' || o[4] != 'a' || o[5] != 'z' || o[6])
    abort ();
  if (p[0][0] != 'f' || p[0][1] != 'o' || p[0][2] != 'o' || p[0][3] != 'b' || p[0][4] != 'a' || p[0][5] != 'r' || p[0][6])
    abort ();
  if (p[1][0] != 'b' || p[1][1] != 'a' || p[1][2] != 'r' || p[1][3])
    abort ();
  if (q[0] != 'a' || q[1] != 'r' || q[2])
    abort ();
  if (r[-2] != 'f' || r[-1] != 'o' || r[0] != 'o' || r[1] != 'b' || r[2] != 'a' || r[3] != 'r' || r[4])
    abort ();
  if (s[0] != 'b' || s[1] != 'a' || s[2] != 'a' || s[3] != 'a' || s[4] != 'r' || s[5] != 'b' || s[6] != 'a' || s[7] != 'z' || s[8])
    abort ();
  if (t[0] != 'r' || t[1])
    abort ();
  if (u[0] != 'f' || u[1] != 'o' || u[2] != 'o' || u[3] != 'b' || u[4] != 'a' || u[5] != 'r' || u[6])
    abort ();
  if (v[0] != 'b' || v[1] != 'a' || v[2] != 'r' || v[3])
    abort ();
  if (w[-2] != 'f' || w[-1] != 'o' || w[0] != 'o' || w[1] != 'b' || w[2] != 'a' || w[3] != 'r' || w[4])
    abort ();
  if (x[0] != 'b' || x[1] != 'a' || x[2] != 'a' || x[3] != 'a' || x[4] != 'r' || x[5] != 'b' || x[6] != 'a' || x[7] != 'z' || x[8])
    abort ();
  if (y[0] != 'r' || y[1])
    abort ();
  if (z[0] != 'r' || z[1] != 'b' || z[2] != 'a' || z[3] != 'z' || z[4])
    abort ();
  *a = 0.0; *b = 4.0; *c = 16.0;
  return 64.0;
}
EOF
cat > merge3.c <<EOF
#include <stdio.h>

extern char *o, *p[], *q, *r, *t, *u, *v, *w, *y, *z;
extern const char s[], x[];
extern const long double k, l;

extern double foo(double *a, double *b, double *c);
extern double bar(double *a, double *b, double *c);

int main()
{
  double a, b, c, d, e, f, g, h;

  a = foo(&b, &c, &d);
  e = bar(&f, &g, &h);
  if (a != e || b != f || c != g || d != h)
    abort ();
  if (a <= 63.0 || a >= 65.0 || b <= -1.0 || b >= 1.0 || c <= 3.0 || c >= 5.0 || d <= 15.0 || d >= 17.0)
    abort ();
  if (k != l || k <= 6.0L || k >= 8.0L)
    abort ();
#ifdef __OPTIMIZE__
  /* Unless -fno-merge-constants, these should be always merged.  */
  if (p[0] != u || p[1] != v || r != w || t != y)
    puts ("linker does not support constant merging apparently");
  /* In C, const variables should be distinct objects, which is overridden
     with -fmerge-all-constants.  */
  if (s != x || &k != &l)
    puts ("-fmerge-all-constants not specified");
  /* These optimizations may or may not happen (e.g. depending on whether
     linker supports it and what the required alignment of string constants
     is.  */
  if (v != u + 3 || w != u + 2 || y != v + 2 || q != v + 1 || z != o + 2)
    puts ("linker does not support suffix merging or the strings constants require alignment");
  if (o != x + 2)
    puts ("-fmerge-all-constants not specified or linker does not support suffix merging");
#endif
  exit (0);
}
EOF
${CC-gcc} -O2 -o mergetest1 merge1.c merge2.c merge3.c -fno-merge-constants; ./mergetest1
${CC-gcc} -O2 -o mergetest2 merge1.c merge2.c merge3.c -fmerge-constants; ./mergetest2
${CC-gcc} -O2 -o mergetest3 merge1.c merge2.c merge3.c -fmerge-all-constants; ./mergetest3

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