This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Provide macro to override limiting field alignment
- From: Fred Forsman <forsman at apple dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Cc: Fred Forsman <forsman at apple dot com>
- Date: Mon, 10 Dec 2001 16:26:44 -0800
- Subject: [PATCH] Provide macro to override limiting field alignment
This patch introduces a macro (LIMIT_FIELD_ALIGN) to limit the alignment
of fields to maximum_field_alignment. This macro does not change the
behavior of the compiler unless the macro is defined to do something
else. The macro provides a hook to override the normal alignment
behavior, needed on the PowerPC to handle vector data. This macro
functions in much the same way as the other macros allowing
target-specific handling of alignment.
Fred Forsman
Apple Computer, Inc.
2001-12-10 Fred Forsman <forsman@apple.com>
Provide a macro for limiting the alignment of fields to
allow overriding of this behavior (needed for PowerPC vector
data alignment).
* stor-layout.c: Define LIMIT_FIELD_ALIGN macro if not
already defined.
(layout_decl): Use LIMIT_FIELD_ALIGN macro.
(place_field): Use LIMIT_FIELD_ALIGN macro (2 cases).
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.114
diff -c -3 -p -r1.114 stor-layout.c
*** stor-layout.c 2001/12/08 19:43:07 1.114
--- stor-layout.c 2001/12/10 23:16:38
*************** tree sizetype_tab[(int) TYPE_KIND_LAST];
*** 46,51 ****
--- 46,59 ----
The value is measured in bits. */
unsigned int maximum_field_alignment;
+ /* Macro to limit the alignment of fields to maximum_field_alignment.
+ It also provides an opportunity to override this behavior in cases
+ that require something other than the usual maximum alignment. */
+ #ifndef LIMIT_FIELD_ALIGN
+ #define LIMIT_FIELD_ALIGN(DESIRED_ALIGN) \
+ MIN (DESIRED_ALIGN, (unsigned) maximum_field_alignment)
+ #endif
+
/* If non-zero, the alignment of a bitstring or (power-)set value, in
bits.
May be overridden by front-ends. */
unsigned int set_alignment = 0;
*************** layout_decl (decl, known_align)
*** 388,394 ****
{
DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
if (maximum_field_alignment != 0)
! DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
else if (DECL_PACKED (decl))
{
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
--- 396,402 ----
{
DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
if (maximum_field_alignment != 0)
! DECL_ALIGN (decl) = LIMIT_FIELD_ALIGN (DECL_ALIGN (decl));
else if (DECL_PACKED (decl))
{
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
*************** place_field (rli, field)
*** 800,806 ****
unsigned int type_align = TYPE_ALIGN (type);
if (maximum_field_alignment != 0)
! type_align = MIN (type_align, maximum_field_alignment);
else if (DECL_PACKED (field))
type_align = MIN (type_align, BITS_PER_UNIT);
--- 808,814 ----
unsigned int type_align = TYPE_ALIGN (type);
if (maximum_field_alignment != 0)
! type_align = LIMIT_FIELD_ALIGN (type_align);
else if (DECL_PACKED (field))
type_align = MIN (type_align, BITS_PER_UNIT);
*************** place_field (rli, field)
*** 915,921 ****
HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
if (maximum_field_alignment != 0)
! type_align = MIN (type_align, maximum_field_alignment);
/* ??? This test is opposite the test in the containing if
statement, so this code is unreachable currently. */
else if (DECL_PACKED (field))
--- 923,929 ----
HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
if (maximum_field_alignment != 0)
! type_align = LIMIT_FIELD_ALIGN (type_align);
/* ??? This test is opposite the test in the containing if
statement, so this code is unreachable currently. */
else if (DECL_PACKED (field))