public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
@ 2011-06-01 11:34 Richard Guenther
  2011-06-01 16:00 ` Eric Botcazou
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Richard Guenther @ 2011-06-01 11:34 UTC (permalink / raw)
  To: gcc-patches; +Cc: fortran, java


This patch defers the control over size_t and sizetype to the
middle-end which in turn consults the target.  This removes
various inconsistencies for frontends that do not seem to care
about size_t and will allow simplifying the global tree initialization.

Bootstrapped on x86_64-unknown-linux-gnu for all languages, testing
in progress.

Ok for trunk?  (the change is worthwhile from an LTO and middle-end
perspective and I'll apply leeway to frontends that appear to be
unmaintained - hello Java)

Thanks,
Richard.

2011-06-01  Richard Guenther  <rguenther@suse.de>

	* tree.c (build_common_tree_nodes): Also initialize size_type_node.
	Call set_sizetype from here.

	c-family/
	* c-common.c (c_common_nodes_and_builtins): Do not set
	size_type_node or call set_sizetype.

	go/
	* go-lang.c (go_langhook_init): Do not set
	size_type_node or call set_sizetype.

	fortran/
	* f95-lang.c (gfc_init_decl_processing): Do not set
	size_type_node or call set_sizetype.

	java/
	* decl.c (java_init_decl_processing): Properly initialize
	size_type_node.

	lto/
	* lto-lang.c (lto_init): Do not set
	size_type_node or call set_sizetype.

	ada/
	* gcc-interface/misc.c (gnat_init): Do not set
	size_type_node or call set_sizetype.

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 174520)
+++ gcc/tree.c	(working copy)
@@ -9142,6 +9142,7 @@ build_common_tree_nodes (bool signed_cha
         int128_unsigned_type_node = make_unsigned_type (128);
       }
 #endif
+
   /* Define a boolean type.  This type only represents boolean values but
      may be larger than char depending on the value of BOOL_TYPE_SIZE.
      Front ends which want to override this size (i.e. Java) can redefine
@@ -9151,6 +9152,17 @@ build_common_tree_nodes (bool signed_cha
   TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
   TYPE_PRECISION (boolean_type_node) = 1;
 
+  /* Define what type to use for size_t.  */
+  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
+    size_type_node = unsigned_type_node;
+  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
+    size_type_node = long_unsigned_type_node;
+  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
+    size_type_node = long_long_unsigned_type_node;
+  else
+    gcc_unreachable ();
+  set_sizetype (size_type_node);
+
   /* Fill in the rest of the sized types.  Reuse existing type nodes
      when possible.  */
   intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 174520)
+++ gcc/c-family/c-common.c	(working copy)
@@ -4666,13 +4666,7 @@ c_common_nodes_and_builtins (void)
 					 TYPE_DECL, NULL_TREE,
 					 widest_unsigned_literal_type_node));
 
-  /* `unsigned long' is the standard type for sizeof.
-     Note that stddef.h uses `unsigned long',
-     and this must agree, even if long and int are the same size.  */
-  size_type_node =
-    TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
   signed_size_type_node = c_common_signed_type (size_type_node);
-  set_sizetype (size_type_node);
 
   pid_type_node =
     TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
Index: gcc/go/go-lang.c
===================================================================
--- gcc/go/go-lang.c	(revision 174520)
+++ gcc/go/go-lang.c	(working copy)
@@ -87,15 +87,6 @@ go_langhook_init (void)
 {
   build_common_tree_nodes (false);
 
-  /* The sizetype may be "unsigned long" or "unsigned long long".  */
-  if (TYPE_MODE (long_unsigned_type_node) == ptr_mode)
-    size_type_node = long_unsigned_type_node;
-  else if (TYPE_MODE (long_long_unsigned_type_node) == ptr_mode)
-    size_type_node = long_long_unsigned_type_node;
-  else
-    size_type_node = long_unsigned_type_node;
-  set_sizetype (size_type_node);
-
   build_common_tree_nodes_2 (0);
 
   /* We must create the gogo IR after calling build_common_tree_nodes
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c	(revision 174520)
+++ gcc/fortran/f95-lang.c	(working copy)
@@ -590,9 +590,6 @@ gfc_init_decl_processing (void)
      want double_type_node to actually have double precision.  */
   build_common_tree_nodes (false);
 
-  size_type_node = gfc_build_uint_type (POINTER_SIZE);
-  set_sizetype (size_type_node);
-
   build_common_tree_nodes_2 (0);
   void_list_node = build_tree_list (NULL_TREE, void_type_node);
 
Index: gcc/java/decl.c
===================================================================
--- gcc/java/decl.c	(revision 174520)
+++ gcc/java/decl.c	(working copy)
@@ -606,7 +606,14 @@ java_init_decl_processing (void)
 
   /* This is not a java type, however tree-dfa requires a definition for
      size_type_node.  */
-  size_type_node = make_unsigned_type (POINTER_SIZE);
+  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
+    size_type_node = make_unsigned_type (INT_TYPE_SIZE);
+  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
+    size_type_node = make_unsigned_type (LONG_TYPE_SIZE);
+  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
+    size_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
+  else
+    gcc_unreachable ();
   set_sizetype (size_type_node);
 
   /* Define these next since types below may used them.  */
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 174520)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -1087,17 +1087,6 @@ lto_init (void)
   /* Create the basic integer types.  */
   build_common_tree_nodes (flag_signed_char);
 
-  /* Tell the middle end what type to use for the size of objects.  */
-  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
-    size_type_node = unsigned_type_node;
-  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
-    size_type_node = long_unsigned_type_node;
-  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
-    size_type_node = long_long_unsigned_type_node;
-  else
-    gcc_unreachable ();
-  set_sizetype (size_type_node);
-
   /* The global tree for the main identifier is filled in by
      language-specific front-end initialization that is not run in the
      LTO back-end.  It appears that all languages that perform such
Index: gcc/ada/gcc-interface/misc.c
===================================================================
--- gcc/ada/gcc-interface/misc.c	(revision 174520)
+++ gcc/ada/gcc-interface/misc.c	(working copy)
@@ -309,17 +309,6 @@ gnat_init (void)
      matter since we'll use the explicit `unsigned char' for Character.  */
   build_common_tree_nodes (flag_signed_char);
 
-  /* In Ada, we use the unsigned type corresponding to the width of Pmode as
-     SIZETYPE.  In most cases when ptr_mode and Pmode differ, C will use the
-     width of ptr_mode for SIZETYPE, but we get better code using the width
-     of Pmode.  Note that, although we manipulate negative offsets for some
-     internal constructs and rely on compile time overflow detection in size
-     computations, using unsigned types for SIZETYPEs is fine since they are
-     treated specially by the middle-end, in particular sign-extended.  */
-  size_type_node = gnat_type_for_mode (Pmode, 1);
-  set_sizetype (size_type_node);
-  TYPE_NAME (sizetype) = get_identifier ("size_type");
-
   /* In Ada, we use an unsigned 8-bit type for the default boolean type.  */
   boolean_type_node = make_unsigned_type (8);
   TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
  2011-06-01 11:34 [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end Richard Guenther
@ 2011-06-01 16:00 ` Eric Botcazou
  2011-06-01 16:02 ` Andrew Haley
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Botcazou @ 2011-06-01 16:00 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches, fortran, java

> 	ada/
> 	* gcc-interface/misc.c (gnat_init): Do not set
> 	size_type_node or call set_sizetype.

OK, thanks.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
  2011-06-01 11:34 [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end Richard Guenther
  2011-06-01 16:00 ` Eric Botcazou
@ 2011-06-01 16:02 ` Andrew Haley
       [not found]   ` <BANLkTimM2uF3X8Y82YBfPG7VaUi+iKKk=g@mail.gmail.com>
  2011-06-01 17:27 ` Andrew Haley
  2011-06-02 13:37 ` Janne Blomqvist
  3 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2011-06-01 16:02 UTC (permalink / raw)
  To: java

On 06/01/2011 12:34 PM, Richard Guenther wrote:
> 
> 	java/
> 	* decl.c (java_init_decl_processing): Properly initialize
> 	size_type_node.
> 
> Index: gcc/java/decl.c
> ===================================================================
> --- gcc/java/decl.c	(revision 174520)
> +++ gcc/java/decl.c	(working copy)
> @@ -606,7 +606,14 @@ java_init_decl_processing (void)
>  
>    /* This is not a java type, however tree-dfa requires a definition for
>       size_type_node.  */
> -  size_type_node = make_unsigned_type (POINTER_SIZE);
> +  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
> +    size_type_node = make_unsigned_type (INT_TYPE_SIZE);
> +  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
> +    size_type_node = make_unsigned_type (LONG_TYPE_SIZE);
> +  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
> +    size_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
> +  else
> +    gcc_unreachable ();
>    set_sizetype (size_type_node);
>  

OK.

Andrew.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
  2011-06-01 11:34 [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end Richard Guenther
  2011-06-01 16:00 ` Eric Botcazou
  2011-06-01 16:02 ` Andrew Haley
@ 2011-06-01 17:27 ` Andrew Haley
  2011-06-02 13:37 ` Janne Blomqvist
  3 siblings, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2011-06-01 17:27 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches, fortran, java

On 06/01/2011 12:34 PM, Richard Guenther wrote:
> >
> > 	java/
> > 	* decl.c (java_init_decl_processing): Properly initialize
> > 	size_type_node.
> >
> > Index: gcc/java/decl.c
> > ===================================================================
> > --- gcc/java/decl.c	(revision 174520)
> > +++ gcc/java/decl.c	(working copy)
> > @@ -606,7 +606,14 @@ java_init_decl_processing (void)
> >
> >    /* This is not a java type, however tree-dfa requires a definition for
> >       size_type_node.  */
> > -  size_type_node = make_unsigned_type (POINTER_SIZE);
> > +  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
> > +    size_type_node = make_unsigned_type (INT_TYPE_SIZE);
> > +  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
> > +    size_type_node = make_unsigned_type (LONG_TYPE_SIZE);
> > +  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
> > +    size_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
> > +  else
> > +    gcc_unreachable ();
> >    set_sizetype (size_type_node);
> >

OK.

Andrew.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
       [not found]   ` <BANLkTimM2uF3X8Y82YBfPG7VaUi+iKKk=g@mail.gmail.com>
@ 2011-06-01 17:27     ` Andrew Haley
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2011-06-01 17:27 UTC (permalink / raw)
  To: Bryce McKinlay; +Cc: java, GCC Patches

On 06/01/2011 05:45 PM, Bryce McKinlay wrote:
> 
> Can I suggest that you cc such approvals to gcc-patches. Richard (and
> others) may not be subscribed to the java@gcc.gnu.org list.

Sorry, I meant to do so.  This idiot mailer has its "reply list" button
replying to just the one list, not all the CC:s.

(I know, I know, a bad workman blames his tools.  But I wish I could
fix this in the mailer...  :-)

Andrew.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
  2011-06-01 11:34 [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end Richard Guenther
                   ` (2 preceding siblings ...)
  2011-06-01 17:27 ` Andrew Haley
@ 2011-06-02 13:37 ` Janne Blomqvist
  3 siblings, 0 replies; 6+ messages in thread
From: Janne Blomqvist @ 2011-06-02 13:37 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches, fortran, java

On Wed, Jun 1, 2011 at 14:34, Richard Guenther <rguenther@suse.de> wrote:
>
> This patch defers the control over size_t and sizetype to the
> middle-end which in turn consults the target.  This removes
> various inconsistencies for frontends that do not seem to care
> about size_t and will allow simplifying the global tree initialization.
>
> Bootstrapped on x86_64-unknown-linux-gnu for all languages, testing
> in progress.
>
> Ok for trunk?  (the change is worthwhile from an LTO and middle-end
> perspective and I'll apply leeway to frontends that appear to be
> unmaintained - hello Java)

Fortran parts are ok.

-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-02 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01 11:34 [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end Richard Guenther
2011-06-01 16:00 ` Eric Botcazou
2011-06-01 16:02 ` Andrew Haley
     [not found]   ` <BANLkTimM2uF3X8Y82YBfPG7VaUi+iKKk=g@mail.gmail.com>
2011-06-01 17:27     ` Andrew Haley
2011-06-01 17:27 ` Andrew Haley
2011-06-02 13:37 ` Janne Blomqvist

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).