public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Roger Sayle" <roger@eyesopen.com>
To: fortran@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org
Subject: [FORTRAN PATCH] Mark statically constructed constant arrays as       TREE_READONLY
Date: Thu, 04 Jan 2007 23:37:00 -0000	[thread overview]
Message-ID: <2066.68.35.10.103.1167953810.squirrel@mail.eyesopen.com> (raw)

[-- 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;
  

             reply	other threads:[~2007-01-04 23:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-04 23:37 Roger Sayle [this message]
2007-01-05  5:49 ` Steve Kargl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2066.68.35.10.103.1167953810.squirrel@mail.eyesopen.com \
    --to=roger@eyesopen.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).