* [FORTRAN PATCH] Mark statically constructed constant arrays as TREE_READONLY
@ 2007-01-04 23:37 Roger Sayle
2007-01-05 5:49 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2007-01-04 23:37 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1461 bytes --]
The following minor tweak modifies two places in the gfortran front-end
where we generate constant arrays. For example, in code such as:
program v
integer :: x(4)
x = (/ 3, 1, 4, 1 /)
end program
We internally generate the gimple:
{
static int4 data.3[4] = {3, 1, 4, 1};
__builtin_memcpy (&(*(int4[0:] *) atmp.0.data)[0], &data.3, 16);
}
where the array is marked "static" but not "const". This disables some
middle-end optimizations that can take advantage of the fact that the
array never changes, and causes the compiler to output it in a ".data"
instead of a ".rodata" section.
This trivial patch causes gfortran to set the TREE_READONLY field on the
DECL for "data.3" which allows good things to happen, and places these
potentially large constant arrays in .rodata.
(1) I'm not sure why the middle-end doesn't attempt to recognize this
DECL as immutable, and add the TREE_READONLY annotation itself.
(2) The tree-ssa dumps don't seem to output "const" qualifiers.
The following patch has been tested on x86_64-unknown-linux-gnu with a
full "make bootstrap", including gfortran, and regression tested with a
top-level "make -k check" with no new failures.
Ok for mainline?
2007-01-04 Roger Sayle <roger@eyesopen.com>
* trans-array.c (gfc_trans_array_constructor_value): Make the
static const "data" array as TREE_READONLY.
* trans-stmt.c (gfc_trans_character_select): Likewise.
Roger
--
[-- Attachment #2: patchf2.txt --]
[-- Type: text/plain, Size: 862 bytes --]
Index: trans-array.c
===================================================================
*** trans-array.c (revision 120354)
--- trans-array.c (working copy)
*************** gfc_trans_array_constructor_value (stmtb
*** 1224,1229 ****
--- 1224,1230 ----
TREE_STATIC (tmp) = 1;
TREE_CONSTANT (tmp) = 1;
TREE_INVARIANT (tmp) = 1;
+ TREE_READONLY (tmp) = 1;
DECL_INITIAL (tmp) = init;
init = tmp;
Index: trans-stmt.c
===================================================================
*** trans-stmt.c (revision 120354)
--- trans-stmt.c (working copy)
*************** gfc_trans_character_select (gfc_code *co
*** 1445,1450 ****
--- 1445,1451 ----
TREE_CONSTANT (tmp) = 1;
TREE_INVARIANT (tmp) = 1;
TREE_STATIC (tmp) = 1;
+ TREE_READONLY (tmp) = 1;
DECL_INITIAL (tmp) = init;
init = tmp;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FORTRAN PATCH] Mark statically constructed constant arrays as TREE_READONLY
2007-01-04 23:37 [FORTRAN PATCH] Mark statically constructed constant arrays as TREE_READONLY Roger Sayle
@ 2007-01-05 5:49 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2007-01-05 5:49 UTC (permalink / raw)
To: Roger Sayle; +Cc: fortran, gcc-patches
On Thu, Jan 04, 2007 at 04:36:50PM -0700, Roger Sayle wrote:
>
> 2007-01-04 Roger Sayle <roger@eyesopen.com>
>
> * trans-array.c (gfc_trans_array_constructor_value): Make the
> static const "data" array as TREE_READONLY.
> * trans-stmt.c (gfc_trans_character_select): Likewise.
>
OK.
--
Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-05 5:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-04 23:37 [FORTRAN PATCH] Mark statically constructed constant arrays as TREE_READONLY Roger Sayle
2007-01-05 5:49 ` Steve Kargl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).