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]

Patch: new langhook for PRs 6005 and 7611


A couple months ago I wrote this patch for PR 6005.  Today I
resurrected it and tested it.

Right now fold-const will turn certain field comparisons into
bit-field operations.  The gcj bytecode generator doesn't understand
bit-fields, and changing it to undo the changes made by fold-const
would be difficult.  It is much simpler to change fold-const so that
it doesn't do these transformations in the first place.

This patch adds a new langhook that tells fold-const whether it can
perform bit-field transformations.

I tested this using the test case in the PR (rebuilding xerces from
rhug on the alpha).

This patch also ought to fix PR 7611, but I haven't tested that.  If
this looks like an acceptable approach I'll ask the PR submitter to
test it.

I did a clean rebuild on both x86 and alpha using this patch.  I
haven't yet run gcc regression tests to make sure I didn't break
anything non-java.

At this point I'm mostly interested in whether this is an acceptable
approach.  Any comments?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	For PR java/6005 and PR java/7611:
	* fold-const.c (fold_truthop): Use can_use_bit_fields_p.
	(fold): Likewise.
	* langhooks.c (lhd_can_use_bit_fields_p): New function.
	* langhooks-def.h (lhd_can_use_bit_fields_p): Declare.
	(LANG_HOOKS_CAN_USE_BIT_FIELDS_P): New define.
	(LANG_HOOKS_INITIALIZER): Use it.
	* langhooks.h (struct lang_hooks) [can_use_bit_fields_p]: New
	field.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.218
diff -u -r1.218 fold-const.c
--- fold-const.c 5 Aug 2002 19:26:25 -0000 1.218
+++ fold-const.c 18 Aug 2002 01:58:00 -0000
@@ -1,5 +1,5 @@
 /* Fold a constant sub-tree into a single node for C-compiler
-   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2002,
    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -3711,6 +3711,11 @@
 	return 0;
     }
 
+  /* After this point all optimizations will generate bit-field
+     references, which we might not want.  */
+  if (! (*lang_hooks.can_use_bit_fields_p) ())
+    return 0;
+
   /* See if we can find a mode that contains both fields being compared on
      the left.  If we can't, fail.  Otherwise, update all constants and masks
      to be relative to a field of that size.  */
@@ -6590,7 +6595,8 @@
 	}
 
       /* If this is a comparison of a field, we may be able to simplify it.  */
-      if ((TREE_CODE (arg0) == COMPONENT_REF
+      if (((TREE_CODE (arg0) == COMPONENT_REF
+	    && (*lang_hooks.can_use_bit_fields_p) ())
 	   || TREE_CODE (arg0) == BIT_FIELD_REF)
 	  && (code == EQ_EXPR || code == NE_EXPR)
 	  /* Handle the constant case even without -O
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.36
diff -u -r1.36 langhooks-def.h
--- langhooks-def.h 2 Aug 2002 11:57:17 -0000 1.36
+++ langhooks-def.h 18 Aug 2002 01:58:00 -0000
@@ -59,6 +59,7 @@
 extern void lhd_print_error_function PARAMS ((struct diagnostic_context *,
 					      const char *));
 extern void lhd_set_decl_assembler_name PARAMS ((tree));
+extern bool lhd_can_use_bit_fields_p PARAMS ((void));
 extern bool lhd_warn_unused_global_decl PARAMS ((tree));
 extern void lhd_incomplete_type_error PARAMS ((tree, tree));
 extern tree lhd_type_promotes_to PARAMS ((tree));
@@ -102,6 +103,7 @@
 #define LANG_HOOKS_UNSAVE_EXPR_NOW	lhd_unsave_expr_now
 #define LANG_HOOKS_MAYBE_BUILD_CLEANUP	lhd_return_null_tree
 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lhd_set_decl_assembler_name
+#define LANG_HOOKS_CAN_USE_BIT_FIELDS_P lhd_can_use_bit_fields_p
 #define LANG_HOOKS_HONOR_READONLY	false
 #define LANG_HOOKS_PRINT_STATISTICS	lhd_do_nothing
 #define LANG_HOOKS_PRINT_XNODE		lhd_print_tree_nothing
@@ -241,6 +243,7 @@
   LANG_HOOKS_UNSAVE_EXPR_NOW, \
   LANG_HOOKS_MAYBE_BUILD_CLEANUP, \
   LANG_HOOKS_SET_DECL_ASSEMBLER_NAME, \
+  LANG_HOOKS_CAN_USE_BIT_FIELDS_P, \
   LANG_HOOKS_HONOR_READONLY, \
   LANG_HOOKS_PRINT_STATISTICS, \
   LANG_HOOKS_PRINT_XNODE, \
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.32
diff -u -r1.32 langhooks.c
--- langhooks.c 2 Aug 2002 11:57:17 -0000 1.32
+++ langhooks.c 18 Aug 2002 01:58:00 -0000
@@ -175,6 +175,13 @@
     abort ();
 }
 
+/* By default we always allow bit-field based optimizations.  */
+bool
+lhd_can_use_bit_fields_p ()
+{
+  return true;
+}
+
 /* Provide a default routine to clear the binding stack.  This is used
    by languages that don't need to do anything special.  */
 void
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.44
diff -u -r1.44 langhooks.h
--- langhooks.h 2 Aug 2002 11:57:17 -0000 1.44
+++ langhooks.h 18 Aug 2002 01:58:01 -0000
@@ -299,6 +299,10 @@
      assembler does not talk about it.  */
   void (*set_decl_assembler_name) PARAMS ((tree));
 
+  /* Return nonzero if fold-const is free to use bit-field
+     optimizations, for instance in fold_truthop().  */
+  bool (*can_use_bit_fields_p) PARAMS ((void));
+
   /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored.  */
   bool honor_readonly;
 
Index: java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	For PR java/6005 and PR java/7611:
	* lang.c (LANG_HOOKS_CAN_USE_BITFIELDS_P): New define.
	(java_can_use_bit_fields_p): New function.

Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.106
diff -u -r1.106 lang.c
--- java/lang.c 16 Aug 2002 10:32:30 -0000 1.106
+++ java/lang.c 18 Aug 2002 01:58:18 -0000
@@ -1,5 +1,5 @@
 /* Java(TM) language-specific utility routines.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of GNU CC.
@@ -68,6 +68,8 @@
 						       void *,
 						       void *));
 static int java_unsafe_for_reeval PARAMS ((tree));
+static bool java_can_use_bit_fields_p PARAMS ((void));
+
 
 #ifndef TARGET_OBJECT_SUFFIX
 # define TARGET_OBJECT_SUFFIX ".o"
@@ -259,6 +261,8 @@
 #define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
 #define LANG_HOOKS_PRINT_ERROR_FUNCTION	java_print_error_function
+#undef LANG_HOOKS_CAN_USE_BIT_FIELDS_P
+#define LANG_HOOKS_CAN_USE_BIT_FIELDS_P java_can_use_bit_fields_p
 
 #undef LANG_HOOKS_TYPE_FOR_MODE
 #define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
@@ -792,6 +796,14 @@
 
   /* In Java floating point operations never trap.  */
   flag_trapping_math = 0;
+}
+
+static bool
+java_can_use_bit_fields_p ()
+{
+  /* The bit-field optimizations cause problems when generating class
+     files.  */
+  return flag_emit_class_files ? false : true;
 }
 
 /* Post-switch processing.  */


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