From: Richard Guenther <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: fortran@gcc.gnu.org, java@gcc.gnu.org
Subject: [PATCH][all-langs] Defer size_t and sizetype setting to the middle-end
Date: Wed, 01 Jun 2011 11:34:00 -0000 [thread overview]
Message-ID: <alpine.LNX.2.00.1106011301130.810@zhemvz.fhfr.qr> (raw)
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);
next reply other threads:[~2011-06-01 11:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-01 11:34 Richard Guenther [this message]
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
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=alpine.LNX.2.00.1106011301130.810@zhemvz.fhfr.qr \
--to=rguenther@suse.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=java@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).