2006-03-29 Paul Brook <paul@codesourcery.com>
authorpbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Mar 2006 15:21:13 +0000 (15:21 +0000)
committerpbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Mar 2006 15:21:13 +0000 (15:21 +0000)
PR middle-end/23623
* targhooks.c (default_narrow_bitfield): New fuction.
* targhooks.h (default_narrow_bitfield): add prototype.
* target.h (gcc_target): Add narrow_volatile_bitfield.
* target-def.h (TARGET_NARROW_VOLATILE_BITFIELD): Define.
* stor-layout.c (get_best_mode): Use targetm.narrow_volatile_bitfield.
* doc/tm.texi: Document TARGET_NARROW_VOLATILE_BITFIELDS.
* config/arm/arm.c (TARGET_NARROW_VOLATILE_BITFIELD): Define.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@112493 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/arm/arm.c
gcc/doc/tm.texi
gcc/stor-layout.c
gcc/target-def.h
gcc/target.h
gcc/targhooks.c
gcc/targhooks.h

index 1dbe439..7ab85ea 100644 (file)
@@ -1,3 +1,14 @@
+2006-03-29  Paul Brook  <paul@codesourcery.com>
+
+       PR middle-end/23623
+       * targhooks.c (default_narrow_bitfield): New fuction.
+       * targhooks.h (default_narrow_bitfield): add prototype.
+       * target.h (gcc_target): Add narrow_volatile_bitfield.
+       * target-def.h (TARGET_NARROW_VOLATILE_BITFIELD): Define.
+       * stor-layout.c (get_best_mode): Use targetm.narrow_volatile_bitfield.
+       * doc/tm.texi: Document TARGET_NARROW_VOLATILE_BITFIELDS.
+       * config/arm/arm.c (TARGET_NARROW_VOLATILE_BITFIELD): Define.
+
 2006-03-29  Andreas Krebbel  <krebbel1@de.ibm.com>
 
        * config.gcc (s390-*-linux-*, s390x-*-linux*): Add t-dfprules to 
index 2e5c9c4..e6b97df 100644 (file)
@@ -312,6 +312,9 @@ static bool arm_tls_symbol_p (rtx x);
 #undef TARGET_ALIGN_ANON_BITFIELD
 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
 
+#undef TARGET_NARROW_VOLATILE_BITFIELD
+#define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
+
 #undef TARGET_CXX_GUARD_TYPE
 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
 
index 708a5af..b1dae11 100644 (file)
@@ -1221,6 +1221,14 @@ structure.  The hook should return true if the structure should inherit
 the alignment requirements of an unnamed bitfield's type.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_NARROW_VOLATILE_BITFIELDS (void)
+This target hook should return @code{true} if accesses to volatile bitfields
+should use the narrowest mode possible.  It should return @code{false} if
+these accesses should use the bitfield container type.
+
+The default is @code{!TARGET_STRICT_ALIGN}.
+@end deftypefn
+
 @defmac MEMBER_TYPE_FORCES_BLK (@var{field}, @var{mode})
 Return 1 if a structure or array containing @var{field} should be accessed using
 @code{BLKMODE}.
index caf176f..5617d27 100644 (file)
@@ -2148,13 +2148,17 @@ fixup_unsigned_type (tree type)
    If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
    larger than LARGEST_MODE (usually SImode).
 
-   If no mode meets all these conditions, we return VOIDmode.  Otherwise, if
-   VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
-   mode meeting these conditions.
-
-   Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
-   the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
-   all the conditions.  */
+   If no mode meets all these conditions, we return VOIDmode.
+   
+   If VOLATILEP is false and SLOW_BYTE_ACCESS is false, we return the
+   smallest mode meeting these conditions.
+
+   If VOLATILEP is false and SLOW_BYTE_ACCESS is true, we return the
+   largest mode (but a mode no wider than UNITS_PER_WORD) that meets
+   all the conditions.
+   
+   If VOLATILEP is true the narrow_volatile_bitfields target hook is used to
+   decide which of the above modes should be used.  */
 
 enum machine_mode
 get_best_mode (int bitsize, int bitpos, unsigned int align,
@@ -2184,7 +2188,8 @@ get_best_mode (int bitsize, int bitpos, unsigned int align,
       || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
     return VOIDmode;
 
-  if (SLOW_BYTE_ACCESS && ! volatilep)
+  if ((SLOW_BYTE_ACCESS && ! volatilep)
+      || (volatilep && !targetm.narrow_volatile_bitfield()))
     {
       enum machine_mode wide_mode = VOIDmode, tmode;
 
index 690d0a5..7500151 100644 (file)
@@ -412,6 +412,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_tree_false
 #define TARGET_MS_BITFIELD_LAYOUT_P hook_bool_tree_false
 #define TARGET_ALIGN_ANON_BITFIELD hook_bool_void_false
+#define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
 #define TARGET_RTX_COSTS hook_bool_rtx_int_int_intp_false
 #define TARGET_MANGLE_FUNDAMENTAL_TYPE hook_constcharptr_tree_null
 #define TARGET_ALLOCATE_INITIAL_VALUE NULL
@@ -609,6 +610,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   TARGET_MS_BITFIELD_LAYOUT_P,                 \
   TARGET_DECIMAL_FLOAT_SUPPORTED_P,            \
   TARGET_ALIGN_ANON_BITFIELD,                  \
+  TARGET_NARROW_VOLATILE_BITFIELD,             \
   TARGET_INIT_BUILTINS,                                \
   TARGET_EXPAND_BUILTIN,                       \
   TARGET_EXPAND_LIBRARY_BUILTIN,               \
index 1b768e4..e9a5eca 100644 (file)
@@ -418,6 +418,10 @@ struct gcc_target
   /* Return true if anonymous bitfields affect structure alignment.  */
   bool (* align_anon_bitfield) (void);
 
+  /* Return true if volatile bitfields should use the narrowest type possible.
+     Return false if they should use the container type.  */
+  bool (* narrow_volatile_bitfield) (void);
+
   /* Set up target-specific built-in functions.  */
   void (* init_builtins) (void);
 
index 45942a2..f33704b 100644 (file)
@@ -572,4 +572,18 @@ default_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
   return class;
 }
 
+
+/* If STRICT_ALIGNMENT is true we use the container type for accessing
+   volatile bitfields.  This is generally the preferred behavior for memory
+   mapped peripherals on RISC architectures.
+   If STRICT_ALIGNMENT is false we use the narrowest type possible.  This
+   is typically used to avoid spurious page faults and extra memory accesses
+   due to unaligned accesses on CISC architectures.  */
+
+bool
+default_narrow_bitfield (void)
+{
+  return !STRICT_ALIGNMENT;
+}
+
 #include "gt-targhooks.h"
index 05d1add..7c99b08 100644 (file)
@@ -54,6 +54,8 @@ extern bool default_decimal_float_supported_p (void);
 
 extern const char * default_invalid_within_doloop (rtx);
 
+extern bool default_narrow_bitfield (void);
+
 /* These are here, and not in hooks.[ch], because not all users of
    hooks.h include tm.h, and thus we don't have CUMULATIVE_ARGS.  */