This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: rs6000 -fdata-sections
On Tue, Dec 04, 2001 at 03:17:46PM -0800, Geoff Keating wrote:
>
> I'd appreciate it if you could leave 'prefixes' as a two-dimensional
> array, and leave the definitions of 'readonly' and 'needs_sdata', as
> both of these provide important documentation; I'm really not a big
> fan of the huge 'if ((x && a) || (y && b) || (z && (d || e)))'
> conditions. Rewriting the assignment to 'sec' as a sequence of
> if-then conditions is good. Can you submit a revised patch along
> those lines?
I'll take the liberty of interpreting your request regarding "readonly"
loosely. How's this?
* config/rs6000/rs6000.c (rs6000_unique_section): Simplify and
correct code selecting section.
Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.251
diff -c -r1.251 rs6000.c
*** rs6000.c 2001/12/04 23:23:19 1.251
--- rs6000.c 2001/12/05 03:26:21
***************
*** 9451,9459 ****
tree decl;
int reloc;
{
- int size = int_size_in_bytes (TREE_TYPE (decl));
- int needs_sdata;
- int readonly;
int len;
int sec;
const char *name;
--- 9451,9456 ----
***************
*** 9462,9501 ****
static const char *const prefixes[7][2] =
{
- { ".text.", ".gnu.linkonce.t." },
{ ".rodata.", ".gnu.linkonce.r." },
{ ".sdata2.", ".gnu.linkonce.s2." },
{ ".data.", ".gnu.linkonce.d." },
{ ".sdata.", ".gnu.linkonce.s." },
{ ".bss.", ".gnu.linkonce.b." },
! { ".sbss.", ".gnu.linkonce.sb." }
};
!
! needs_sdata = (TREE_CODE (decl) != FUNCTION_DECL
! && size > 0
! && size <= g_switch_value
! && rs6000_sdata != SDATA_NONE
! && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
!
! if (TREE_CODE (decl) == STRING_CST)
! readonly = ! flag_writable_strings;
! else if (TREE_CODE (decl) == VAR_DECL)
! readonly = (! (flag_pic && reloc)
! && TREE_READONLY (decl)
! && ! TREE_SIDE_EFFECTS (decl)
! && DECL_INITIAL (decl)
! && DECL_INITIAL (decl) != error_mark_node
! && TREE_CONSTANT (DECL_INITIAL (decl)));
else
! readonly = 1;
! if (needs_sdata && rs6000_sdata != SDATA_EABI)
! readonly = 0;
!
! sec = ((TREE_CODE (decl) == FUNCTION_DECL ? 0 : 1)
! + (readonly ? 0 : 2)
! + (needs_sdata ? 1 : 0)
! + (DECL_INITIAL (decl) == 0
! || DECL_INITIAL (decl) == error_mark_node) ? 4 : 0);
STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
--- 9459,9512 ----
static const char *const prefixes[7][2] =
{
{ ".rodata.", ".gnu.linkonce.r." },
{ ".sdata2.", ".gnu.linkonce.s2." },
{ ".data.", ".gnu.linkonce.d." },
{ ".sdata.", ".gnu.linkonce.s." },
{ ".bss.", ".gnu.linkonce.b." },
! { ".sbss.", ".gnu.linkonce.sb." },
! { ".text.", ".gnu.linkonce.t." }
};
!
! if (TREE_CODE (decl) == FUNCTION_DECL)
! sec = 6;
else
! {
! int readwrite;
! int needs_sdata;
! int size;
!
! readwrite = 0;
! if (TREE_CODE (decl) == STRING_CST)
! readwrite = flag_writable_strings;
! else if (TREE_CODE (decl) == VAR_DECL)
! readwrite = ((flag_pic && reloc)
! || ! TREE_READONLY (decl)
! || TREE_SIDE_EFFECTS (decl)
! || ! TREE_CONSTANT (DECL_INITIAL (decl)));
!
! size = int_size_in_bytes (TREE_TYPE (decl));
! needs_sdata = (size > 0
! && size <= g_switch_value
! && rs6000_sdata != SDATA_NONE
! && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
!
! if (DECL_INITIAL (decl) == 0
! || DECL_INITIAL (decl) == error_mark_node)
! sec = 4;
! else if (readwrite)
! sec = 2;
! else
! sec = 0;
!
! if (needs_sdata)
! {
! /* .sdata2 is only for EABI. */
! if (sec == 0 && rs6000_sdata != SDATA_EABI)
! sec = 2;
! sec += 1;
! }
! }
STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
prefix = prefixes[sec][DECL_ONE_ONLY (decl)];