* [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
@ 2007-12-13 19:07 Nathan Froyd
2007-12-14 11:51 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Nathan Froyd @ 2007-12-13 19:07 UTC (permalink / raw)
To: gcc-patches; +Cc: zadeck
Reason #4829 why langhooks should die. The comment is at Kenny's
request and is somewhat milder than Kenny's suggestion.
Fixes a number of bitfield-related tests in the testsuite.
Committed to the LTO branch.
-Nathan
gcc/
* langhooks.h (struct lang_hooks) Add comment for
reduce_bit_field_operations.
gcc/lto/
* lto-lang.c (LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS): Define.
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h (revision 130903)
+++ gcc/langhooks.h (working copy)
@@ -319,7 +319,11 @@ struct lang_hooks
void (*set_decl_assembler_name) (tree);
/* Nonzero if operations on types narrower than their mode should
- have their results reduced to the precision of the type. */
+ have their results reduced to the precision of the type.
+
+ FIXME: This langhook is here purely for the convenience of C++;
+ somebody needs to figure out why C++ is so desperate to set this
+ differently than every other front-end and fix C++. */
bool reduce_bit_field_operations;
/* Nonzero if this front end does not generate a dummy BLOCK between
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c (revision 130903)
+++ gcc/lto/lto-lang.c (working copy)
@@ -573,6 +573,8 @@ lto_init (void)
#define LANG_HOOKS_PARSE_FILE lto_main
#undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
#define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
+#undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
+#define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
2007-12-13 19:07 [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS Nathan Froyd
@ 2007-12-14 11:51 ` Paolo Bonzini
2007-12-14 14:13 ` Richard Guenther
2007-12-14 17:02 ` Paolo Bonzini
0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2007-12-14 11:51 UTC (permalink / raw)
To: gcc-patches
Nathan Froyd wrote:
> Reason #4829 why langhooks should die. The comment is at Kenny's
> request and is somewhat milder than Kenny's suggestion.
>
> Fixes a number of bitfield-related tests in the testsuite.
I have a 4.4-pending patch which "the right way to do this": removing
the langhook. I'll update it and submit it so that you can include it
in LTO.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
2007-12-14 11:51 ` Paolo Bonzini
@ 2007-12-14 14:13 ` Richard Guenther
2007-12-14 17:02 ` Paolo Bonzini
1 sibling, 0 replies; 5+ messages in thread
From: Richard Guenther @ 2007-12-14 14:13 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: gcc-patches
On Dec 14, 2007 11:57 AM, Paolo Bonzini <bonzini@gnu.org> wrote:
> Nathan Froyd wrote:
> > Reason #4829 why langhooks should die. The comment is at Kenny's
> > request and is somewhat milder than Kenny's suggestion.
> >
> > Fixes a number of bitfield-related tests in the testsuite.
>
> I have a 4.4-pending patch which "the right way to do this": removing
> the langhook. I'll update it and submit it so that you can include it
> in LTO.
There is also PR33887, a wrong-code regression for C++ and bitfields
which happens to be fixed if C++ enables this langhook. But it breaks
something in libjava.
So - I would appreciate some more efforts from you to "fix" C++ and
remove this langhook ;)
Thanks,
Richard.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
2007-12-14 11:51 ` Paolo Bonzini
2007-12-14 14:13 ` Richard Guenther
@ 2007-12-14 17:02 ` Paolo Bonzini
2007-12-14 22:21 ` Richard Guenther
1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2007-12-14 17:02 UTC (permalink / raw)
To: Mark Mitchell; +Cc: gcc-patches, Richard Guenther, Nathan Froyd
[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]
Paolo Bonzini wrote:
> Nathan Froyd wrote:
>> Reason #4829 why langhooks should die. The comment is at Kenny's
>> request and is somewhat milder than Kenny's suggestion.
>>
>> Fixes a number of bitfield-related tests in the testsuite.
>
> I have a 4.4-pending patch which "the right way to do this": removing
> the langhook. I'll update it and submit it so that you can include it
> in LTO.
Here is the patch (which was actually 4.3-pending too, but I had no time
to submit it earlier than stage3 :-P). The way it work is simply by
turning the langhook into a type flag, so that C creates types with the
flag set to true and C++ creates types with the flag set to false.
I modified every place which sets TYPE_PRECISION to set or copy over the
new flag.
The middle-end has one type with small TYPE_PRECISION, namely
boolean_type_node. In this patch I was more conservative than necessary
(hopefully), so in C++ I mark it as !TYPE_REDUCE_BIT_FIELD_OPERATIONS.
Since I don't know if it is a problem for LTO, I left it in; but if it
*is* a problem, you might try removing it altogether since I think this
special treatment is not necessary.
Then there is also the problem of the PR that Richard pointed out. I
don't know if this patch can ease solving that PR, but it cannot make it
worse. :-)
This patch (for now at least) is not for mainline, so if you want it in
LTO I guess you'll have to foster-parent it into there; thanks for that.
Bootstrapped/regtested C/C++/ObjC/Fortran on i686-pc-linux-gnu.
Paolo
[-- Attachment #2: remove-bitfield-langhook.patch --]
[-- Type: text/plain, Size: 11057 bytes --]
2007-12-14 Paolo Bonzini <bonzini@gnu.org>
* tree.c (type_hash_eq) <case INTEGER_TYPE, BOOLEAN_TYPE,
ENUMERAL_TYPE>: Test TYPE_REDUCE_BIT_FIELD_OPERATIONS equality.
(build_nonstandard_integer_type): Accept an additional parameter
and use it to set TYPE_REDUCE_BIT_FIELD_OPERATIONS.
(build_range_type): Copy over TYPE_REDUCE_BIT_FIELD_OPERATIONS.
(build_common_tree_nodes): Set TYPE_REDUCE_BIT_FIELD_OPERATIONS
for boolean_type_node. Adjust calls to build_nonstandard_integer_type.
* tree.h (INTEGRAL_TYPE_CHECK, TYPE_REDUCE_BIT_FIELD_OPERATIONS): New.
(build_nonstandard_integer_type): Adjust prototype.
* expr.c (store_expr, expand_expr_real_1): Test per-type
TYPE_REDUCE_BIT_FIELD_OPERATIONS instead of langhook.
* c-common.c (c_common_signed_or_unsigned_type,
c_build_bitfield_integer_type): Adjust calls to
build_nonstandard_integer_type, passing true for C and false for C++.
* c-decl.c (finish_enum): Copy over TYPE_REDUCE_BIT_FIELD_OPERATIONS.
* c-objc-common.h (LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS): Nuke.
* langhooks-def.h (LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS): Nuke.
cp:
2007-12-14 Paolo Bonzini <bonzini@gnu.org>
* decl.c (cxx_init_decl_processing): Reset boolean_type_node's
TYPE_REDUCE_BIT_FIELD_OPERATIONS bit.
Index: tree.c
===================================================================
--- tree.c (revision 130928)
+++ tree.c (working copy)
@@ -4582,7 +4582,9 @@ type_hash_eq (const void *va, const void
TYPE_MAX_VALUE (b->type)))
&& (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
|| tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
- TYPE_MIN_VALUE (b->type))));
+ TYPE_MIN_VALUE (b->type)))
+ && TYPE_REDUCE_BIT_FIELD_OPERATIONS (a->type)
+ == TYPE_REDUCE_BIT_FIELD_OPERATIONS (b->type));
case FIXED_POINT_TYPE:
return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
@@ -5571,7 +5573,7 @@ build_index_type (tree maxval)
built-in target types. */
tree
build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
- int unsignedp)
+ int unsignedp, bool reduce_bit_field_operations)
{
tree itype = make_node (INTEGER_TYPE);
@@ -5582,6 +5584,7 @@ build_nonstandard_integer_type (unsigned
else
fixup_signed_type (itype);
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (itype) = reduce_bit_field_operations;
if (host_integerp (TYPE_MAX_VALUE (itype), 1))
return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
@@ -5610,6 +5613,8 @@ build_range_type (tree type, tree lowval
TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
TYPE_ALIGN (itype) = TYPE_ALIGN (type);
TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (itype) =
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (type);
if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
return type_hash_canon (tree_low_cst (highval, 0)
@@ -7236,6 +7241,7 @@ build_common_tree_nodes (bool signed_cha
TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
TYPE_PRECISION (boolean_type_node) = 1;
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (boolean_type_node) = true;
/* Fill in the rest of the sized types. Reuse existing type nodes
when possible. */
@@ -7313,8 +7319,8 @@ build_common_tree_nodes_2 (int short_dou
integer_ptr_type_node = build_pointer_type (integer_type_node);
/* Fixed size integer types. */
- uint32_type_node = build_nonstandard_integer_type (32, true);
- uint64_type_node = build_nonstandard_integer_type (64, true);
+ uint32_type_node = build_nonstandard_integer_type (32, true, true);
+ uint64_type_node = build_nonstandard_integer_type (64, true, true);
/* Decimal float types. */
dfloat32_type_node = make_node (REAL_TYPE);
Index: tree.h
===================================================================
--- tree.h (revision 130928)
+++ tree.h (working copy)
@@ -449,6 +449,8 @@ struct gimple_stmt GTY(())
ASM_INPUT_P in
ASM_EXPR
EH_FILTER_MUST_NOT_THROW in EH_FILTER_EXPR
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS in
+ INTEGER_TYPE, BOOLEAN_TYPE, ENUM_TYPE
TYPE_REF_CAN_ALIAS_ALL in
POINTER_TYPE, REFERENCE_TYPE
MOVE_NONTEMPORAL in
@@ -961,6 +963,8 @@ extern void omp_clause_range_check_faile
#define NOT_RECORD_OR_UNION_CHECK(T) \
TREE_NOT_CHECK3 (T, RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE)
+#define INTEGRAL_TYPE_CHECK(T) \
+ TREE_CHECK3 (T, INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE)
#define NUMERICAL_TYPE_CHECK(T) \
TREE_CHECK5 (T, INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, REAL_TYPE, \
FIXED_POINT_TYPE)
@@ -1190,6 +1194,11 @@ extern void omp_clause_range_check_faile
#define TREE_SYMBOL_REFERENCED(NODE) \
(IDENTIFIER_NODE_CHECK (NODE)->base.static_flag)
+/* Nonzero if operations on types narrower than their mode should
+ have their results reduced to the precision of the type. */
+#define TYPE_REDUCE_BIT_FIELD_OPERATIONS(NODE) \
+ (INTEGRAL_TYPE_CHECK (NODE)->base.static_flag)
+
/* Nonzero in a pointer or reference type means the data pointed to
by this type can alias anything. */
#define TYPE_REF_CAN_ALIAS_ALL(NODE) \
@@ -4904,7 +4913,7 @@ extern void init_ttree (void);
extern void build_common_tree_nodes (bool, bool);
extern void build_common_tree_nodes_2 (int);
extern void build_common_builtin_nodes (void);
-extern tree build_nonstandard_integer_type (unsigned HOST_WIDE_INT, int);
+extern tree build_nonstandard_integer_type (unsigned HOST_WIDE_INT, int, bool);
extern tree build_range_type (tree, tree, tree);
extern HOST_WIDE_INT int_cst_value (const_tree);
extern tree build_addr (tree, tree);
Index: expr.c
===================================================================
--- expr.c (revision 130928)
+++ expr.c (working copy)
@@ -4471,7 +4471,7 @@ store_expr (tree exp, rtx target, int ca
converting modes. */
if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
&& TREE_TYPE (TREE_TYPE (exp)) == 0
- && (!lang_hooks.reduce_bit_field_operations
+ && (!TYPE_REDUCE_BIT_FIELD_OPERATIONS (TREE_TYPE (exp))
|| (GET_MODE_PRECISION (GET_MODE (target))
== TYPE_PRECISION (TREE_TYPE (exp)))))
{
@@ -7144,8 +7144,9 @@ expand_expr_real_1 (tree exp, rtx target
mode = TYPE_MODE (type);
unsignedp = TYPE_UNSIGNED (type);
}
- if (lang_hooks.reduce_bit_field_operations
- && TREE_CODE (type) == INTEGER_TYPE
+
+ if (TREE_CODE (type) == INTEGER_TYPE
+ && TYPE_REDUCE_BIT_FIELD_OPERATIONS (type)
&& GET_MODE_PRECISION (mode) > TYPE_PRECISION (type))
{
/* An operation in what may be a bit-field type needs the
Index: c-decl.c
===================================================================
--- c-decl.c (revision 130928)
+++ c-decl.c (working copy)
@@ -5895,6 +5895,8 @@ finish_enum (tree enumtype, tree values,
else
TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (enumtype)
+ = TYPE_REDUCE_BIT_FIELD_OPERATIONS (tem);
layout_type (enumtype);
if (values != error_mark_node)
@@ -5957,6 +5959,8 @@ finish_enum (tree enumtype, tree values,
TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (enumtype)
+ = TYPE_REDUCE_BIT_FIELD_OPERATIONS (tem);
}
/* Finish debugging output for this type. */
Index: langhooks.h
===================================================================
--- langhooks.h (revision 130928)
+++ langhooks.h (working copy)
@@ -324,10 +324,6 @@ struct lang_hooks
assembler does not talk about it. */
void (*set_decl_assembler_name) (tree);
- /* Nonzero if operations on types narrower than their mode should
- have their results reduced to the precision of the type. */
- bool reduce_bit_field_operations;
-
/* Nonzero if this front end does not generate a dummy BLOCK between
the outermost scope of the function and the FUNCTION_DECL. See
is_body_block in stmt.c, and its callers. */
Index: langhooks-def.h
===================================================================
--- langhooks-def.h (revision 130928)
+++ langhooks-def.h (working copy)
@@ -98,7 +98,6 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_STATICP lhd_staticp
#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL lhd_do_nothing_t
#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lhd_set_decl_assembler_name
-#define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS false
#define LANG_HOOKS_NO_BODY_BLOCKS false
#define LANG_HOOKS_PRINT_STATISTICS lhd_do_nothing
#define LANG_HOOKS_PRINT_XNODE lhd_print_tree_nothing
@@ -257,7 +256,6 @@ extern tree lhd_make_node (enum tree_cod
LANG_HOOKS_STATICP, \
LANG_HOOKS_DUP_LANG_SPECIFIC_DECL, \
LANG_HOOKS_SET_DECL_ASSEMBLER_NAME, \
- LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS, \
LANG_HOOKS_NO_BODY_BLOCKS, \
LANG_HOOKS_PRINT_STATISTICS, \
LANG_HOOKS_PRINT_XNODE, \
Index: c-common.c
===================================================================
--- c-common.c (revision 130928)
+++ c-common.c (working copy)
@@ -2323,7 +2323,8 @@ c_common_signed_or_unsigned_type (int un
if (c_dialect_cxx ())
return type;
else
- return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
+ return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp,
+ true);
}
/* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
@@ -2348,7 +2349,7 @@ c_build_bitfield_integer_type (unsigned
if (width == TYPE_PRECISION (long_long_integer_type_node))
return (unsignedp ? long_long_unsigned_type_node
: long_long_integer_type_node);
- return build_nonstandard_integer_type (width, unsignedp);
+ return build_nonstandard_integer_type (width, unsignedp, !c_dialect_cxx ());
}
/* The C version of the register_builtin_type langhook. */
Index: c-objc-common.h
===================================================================
--- c-objc-common.h (revision 130928)
+++ c-objc-common.h (working copy)
@@ -53,8 +53,6 @@ extern void c_initialize_diagnostics (di
#define LANG_HOOKS_PARSE_FILE c_common_parse_file
#undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
#define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
-#undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
-#define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
#undef LANG_HOOKS_STATICP
#define LANG_HOOKS_STATICP c_staticp
#undef LANG_HOOKS_NO_BODY_BLOCKS
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 130928)
+++ cp/decl.c (working copy)
@@ -3261,6 +3261,7 @@ cxx_init_decl_processing (void)
tree void_ftype_ptr;
build_common_tree_nodes (flag_signed_char, false);
+ TYPE_REDUCE_BIT_FIELD_OPERATIONS (boolean_type_node) = 0;
/* Create all the identifiers we need. */
initialize_predefined_identifiers ();
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
2007-12-14 17:02 ` Paolo Bonzini
@ 2007-12-14 22:21 ` Richard Guenther
0 siblings, 0 replies; 5+ messages in thread
From: Richard Guenther @ 2007-12-14 22:21 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Mark Mitchell, gcc-patches, Richard Guenther, Nathan Froyd
On Dec 14, 2007 5:46 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
>
> Paolo Bonzini wrote:
> > Nathan Froyd wrote:
> >> Reason #4829 why langhooks should die. The comment is at Kenny's
> >> request and is somewhat milder than Kenny's suggestion.
> >>
> >> Fixes a number of bitfield-related tests in the testsuite.
> >
> > I have a 4.4-pending patch which "the right way to do this": removing
> > the langhook. I'll update it and submit it so that you can include it
> > in LTO.
>
> Here is the patch (which was actually 4.3-pending too, but I had no time
> to submit it earlier than stage3 :-P). The way it work is simply by
> turning the langhook into a type flag, so that C creates types with the
> flag set to true and C++ creates types with the flag set to false.
>
> I modified every place which sets TYPE_PRECISION to set or copy over the
> new flag.
>
> The middle-end has one type with small TYPE_PRECISION, namely
> boolean_type_node. In this patch I was more conservative than necessary
Ha! This at least hints at ...
> (hopefully), so in C++ I mark it as !TYPE_REDUCE_BIT_FIELD_OPERATIONS.
> Since I don't know if it is a problem for LTO, I left it in; but if it
> *is* a problem, you might try removing it altogether since I think this
> special treatment is not necessary.
>
> Then there is also the problem of the PR that Richard pointed out. I
> don't know if this patch can ease solving that PR, but it cannot make it
> worse. :-)
... what maybe breaks libjava. The C++ boolean type indeed has a
precision of 1.
I guess for 4.4 we need to figure out if we need the distinction at all.
Richard.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-14 22:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-13 19:07 [lto] set LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS Nathan Froyd
2007-12-14 11:51 ` Paolo Bonzini
2007-12-14 14:13 ` Richard Guenther
2007-12-14 17:02 ` Paolo Bonzini
2007-12-14 22:21 ` Richard Guenther
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).