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]
Other format: [Raw text]

[FORTRAN PATCH] Mark statically constructed constant arrays as TREE_READONLY


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: patchf2.txt
Description: Text document


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