target/10465: [AIX] allow -mnatural-align option for AIX as well

David Edelsohn dje@watson.ibm.com
Mon May 19 17:48:00 GMT 2003


	I have committed a revised version of your patch appended below,
especially some additional effort to ensure that the new target_flags
variable was not referenced from libobjc.a.  The patch has been
bootstrapped on powerpc-ibm-aix4.3.3.0 with no new regressions.

David

2003-05-18  Kevin B. Hendricks  <kevin.hendricks@sympatico.ca>
	    David Edelsohn  <edelsohn@gnu.org>

	* config/rs6000/rs6000.c (rs6000_alignment_string,
	rs6000_alignment_flags): New variables.
	(rs6000_parse_alignment_option): New function.
	(rs6000_override_options): Call it.
	* config/rs6000/rs6000.h (TARGET_OPTIONS): Add -malign-XXX option.
	(MASK_ALIGN_POWER, MASK_ALIGN_NATURAL, TARGET_ALIGN_NATURAL): New
	macros.
	* config/rs6000/aix.h (ADJUST_FIELD_ALIGN): Always use COMPUTED
	natural alignment if TARGET_NATURAL_ALIGNMENT
	(ROUND_TYPE_ALIGN): Always use default record alignment if
	TAGET_NATURAL_ALIGNMENT.
	* config/rs6000/darwin.h (ADJUST_FIELD_ALIGN): Same
	(ROUND_TYPE_ALIGN): Same.
	* config/rs6000/linux64.h (ADJUST_FIELD_ALIGN): Same
	(ROUND_TYPE_ALIGN): Same.

Index: aix.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/aix.h,v
retrieving revision 1.35
diff -c -p -r1.35 aix.h
*** aix.h	13 Apr 2003 17:51:05 -0000	1.35
--- aix.h	19 May 2003 17:35:44 -0000
***************
*** 128,139 ****
  #define LIB_SPEC "%{pg:-L/lib/profiled -L/usr/lib/profiled}\
  %{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
  
  /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED))
  
  /* AIX increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
--- 128,141 ----
  #define LIB_SPEC "%{pg:-L/lib/profiled -L/usr/lib/profiled}\
  %{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
  
+ /* This now supports a natural alignment mode. */
  /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+   (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED)))
  
  /* AIX increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
***************
*** 142,147 ****
--- 144,150 ----
      || TREE_CODE (STRUCT) == UNION_TYPE			\
      || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
     && TYPE_FIELDS (STRUCT) != 0				\
+    && TARGET_ALIGN_NATURAL == 0                         \
     && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
     ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
     : MAX ((COMPUTED), (SPECIFIED)))
Index: darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/darwin.h,v
retrieving revision 1.35
diff -c -p -r1.35 darwin.h
*** darwin.h	12 May 2003 14:40:19 -0000	1.35
--- darwin.h	19 May 2003 17:35:44 -0000
*************** do {									\
*** 250,261 ****
  /* Fix for emit_group_load (): force large constants to be pushed via regs.  */
  #define ALWAYS_PUSH_CONSTS_USING_REGS_P		1
  
  /* Darwin word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED))
  
  /* Darwin increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
--- 250,263 ----
  /* Fix for emit_group_load (): force large constants to be pushed via regs.  */
  #define ALWAYS_PUSH_CONSTS_USING_REGS_P		1
  
+ /* This now supports a natural alignment mode */
  /* Darwin word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+   (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED)))
  
  /* Darwin increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
*************** do {									\
*** 264,269 ****
--- 266,272 ----
      || TREE_CODE (STRUCT) == UNION_TYPE			\
      || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
     && TYPE_FIELDS (STRUCT) != 0				\
+    && TARGET_ALIGN_NATURAL == 0                         \
     && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
     ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
     : (TARGET_ALTIVEC && TREE_CODE (STRUCT) == VECTOR_TYPE) \
Index: linux64.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/linux64.h,v
retrieving revision 1.38
diff -c -p -r1.38 linux64.h
*** linux64.h	18 May 2003 09:46:17 -0000	1.38
--- linux64.h	19 May 2003 17:35:44 -0000
***************
*** 119,131 ****
  
  #define USER_LABEL_PREFIX  ""
  
  /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #undef  ADJUST_FIELD_ALIGN
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED))
  
  /* AIX increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
--- 119,133 ----
  
  #define USER_LABEL_PREFIX  ""
  
+ /* This now supports a natural alignment mode. */
  /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
  #undef  ADJUST_FIELD_ALIGN
  #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+   (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
    (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
  	      ? get_inner_array_type (FIELD) \
  	      : TREE_TYPE (FIELD)) == DFmode \
!    ? MIN ((COMPUTED), 32) : (COMPUTED)))
  
  /* AIX increases natural record alignment to doubleword if the first
     field is an FP double while the FP fields remain word aligned.  */
***************
*** 135,140 ****
--- 137,143 ----
      || TREE_CODE (STRUCT) == UNION_TYPE			\
      || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
     && TYPE_FIELDS (STRUCT) != 0				\
+    && TARGET_ALIGN_NATURAL == 0                         \
     && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
     ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
     : MAX ((COMPUTED), (SPECIFIED)))
Index: rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.479
diff -c -p -r1.479 rs6000.c
*** rs6000.c	19 May 2003 00:31:06 -0000	1.479
--- rs6000.c	19 May 2003 17:35:44 -0000
*************** static int rs6000_sr_alias_set;
*** 178,183 ****
--- 178,188 ----
  int rs6000_default_long_calls;
  const char *rs6000_longcall_switch;
  
+ /* Control alignment for fields within structures. */
+ /* String from -malign-XXXXX. */
+ const char *rs6000_alignment_string;
+ int rs6000_alignment_flags;
+ 
  struct builtin_description
  {
    /* mask is not const because we're going to alter it below.  This
*************** static rtx altivec_expand_abs_builtin PA
*** 290,295 ****
--- 295,301 ----
  static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
  static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
  static void rs6000_parse_abi_options PARAMS ((void));
+ static void rs6000_parse_alignment_option PARAMS ((void));
  static void rs6000_parse_tls_size_option PARAMS ((void));
  static void rs6000_parse_yes_no_option (const char *, const char *, int *);
  static int first_altivec_reg_to_save PARAMS ((void));
*************** rs6000_override_options (default_cpu)
*** 739,744 ****
--- 745,753 ----
    /* Handle -mabi= options.  */
    rs6000_parse_abi_options ();
  
+   /* Handle -malign-XXXXX option.  */
+   rs6000_parse_alignment_option ();
+ 
    /* Handle generic -mFOO=YES/NO options.  */
    rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
  			      &rs6000_altivec_vrsave);
*************** rs6000_parse_abi_options ()
*** 886,891 ****
--- 895,914 ----
      rs6000_spe_abi = 0;
    else
      error ("unknown ABI specified: '%s'", rs6000_abi_string);
+ }
+ 
+ /* Handle -malign-XXXXXX options.  */
+ static void
+ rs6000_parse_alignment_option ()
+ {
+   if (rs6000_alignment_string == 0
+       || ! strcmp (rs6000_alignment_string, "power"))
+     rs6000_alignment_flags = MASK_ALIGN_POWER;
+   else if (! strcmp (rs6000_alignment_string, "natural"))
+     rs6000_alignment_flags = MASK_ALIGN_NATURAL;
+   else
+     error ("unknown -malign-XXXXX option specified: '%s'",
+ 	   rs6000_alignment_string);
  }
  
  /* Validate and record the size specified with the -mtls-size option.  */
Index: rs6000.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.h,v
retrieving revision 1.274
diff -c -p -r1.274 rs6000.h
*** rs6000.h	15 May 2003 20:01:10 -0000	1.274
--- rs6000.h	19 May 2003 17:35:44 -0000
*************** extern enum processor_type rs6000_cpu;
*** 402,407 ****
--- 402,409 ----
     {"longcall", &rs6000_longcall_switch,				\
      N_("Avoid all range limits on call instructions"), 0},		\
     {"no-longcall", &rs6000_longcall_switch, "", 0},			\
+    {"align-", &rs6000_alignment_string,					\
+     N_("Specify alignment of structure fields default/natural"), 0},	\
     SUBTARGET_OPTIONS							\
  }
  
*************** extern const char *rs6000_altivec_vrsave
*** 443,448 ****
--- 445,469 ----
  extern int rs6000_altivec_vrsave;
  extern const char *rs6000_longcall_switch;
  extern int rs6000_default_long_calls;
+ extern const char* rs6000_alignment_string;
+ extern int rs6000_alignment_flags;
+ 
+ /* Alignment options for fields in structures for sub-targets following
+    AIX-like ABI.
+    ALIGN_POWER word-aligns FP doubles (default AIX ABI).
+    ALIGN_NATURAL doubleword-aligns FP doubles (align to object size).
+ 
+    Override the macro definitions when compiling libobjc to avoid undefined
+    reference to rs6000_alignment_flags due to library's use of GCC alignment
+    macros which use the macros below.  */
+    
+ #ifndef IN_TARGET_LIBS
+ #define MASK_ALIGN_POWER   0x00000000
+ #define MASK_ALIGN_NATURAL 0x00000001
+ #define TARGET_ALIGN_NATURAL (rs6000_alignment_flags & MASK_ALIGN_NATURAL)
+ #else
+ #define TARGET_ALIGN_NATURAL 0
+ #endif
  
  #define TARGET_LONG_DOUBLE_128 (rs6000_long_double_type_size == 128)
  #define TARGET_ALTIVEC_ABI rs6000_altivec_abi



More information about the Gcc-patches mailing list