]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
This patch adds a new hook that gives the preferred alignment for a static rtx...
authorRichard Sandiford <richard.sandiford@linaro.org>
Thu, 26 Oct 2017 11:28:25 +0000 (11:28 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 26 Oct 2017 11:28:25 +0000 (11:28 +0000)
TARGET_STATIC_RTX_ALIGNMENT

This patch adds a new hook that gives the preferred alignment for
a static rtx, so that we don't need to query the front end in
force_const_mem.

2017-10-26  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
* target.def (static_rtx_alignment): New hook.
* targhooks.h (default_static_rtx_alignment): Declare.
* targhooks.c (default_static_rtx_alignment): New function.
* doc/tm.texi.in (TARGET_STATIC_RTX_ALIGNMENT): New hook.
* doc/tm.texi: Regenerate.
* varasm.c (force_const_mem): Use targetm.static_rtx_alignment
instead of targetm.constant_alignment.  Remove call to
set_mem_attributes.
* config/cris/cris.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
(cris_preferred_mininum_alignment): New function, split out from...
(cris_constant_alignment): ...here.
(cris_static_rtx_alignment): New function.
* config/i386/i386.c (ix86_static_rtx_alignment): New function,
split out from...
(ix86_constant_alignment): ...here.
(TARGET_STATIC_RTX_ALIGNMENT): Redefine.
* config/mmix/mmix.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
(mmix_static_rtx_alignment): New function.
* config/spu/spu.c (spu_static_rtx_alignment): New function.
(TARGET_STATIC_RTX_ALIGNMENT): Redefine.

From-SVN: r254102

gcc/ChangeLog
gcc/config/cris/cris.c
gcc/config/i386/i386.c
gcc/config/mmix/mmix.c
gcc/config/spu/spu.c
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/target.def
gcc/targhooks.c
gcc/targhooks.h
gcc/varasm.c

index ad54a57e1c04416fbc119c6d08b92a01f0f8e7c0..3033a7f789d5e8d3c5ec7e1aa5046b12d0cb131e 100644 (file)
@@ -1,3 +1,26 @@
+2017-10-26  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       * target.def (static_rtx_alignment): New hook.
+       * targhooks.h (default_static_rtx_alignment): Declare.
+       * targhooks.c (default_static_rtx_alignment): New function.
+       * doc/tm.texi.in (TARGET_STATIC_RTX_ALIGNMENT): New hook.
+       * doc/tm.texi: Regenerate.
+       * varasm.c (force_const_mem): Use targetm.static_rtx_alignment
+       instead of targetm.constant_alignment.  Remove call to
+       set_mem_attributes.
+       * config/cris/cris.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
+       (cris_preferred_mininum_alignment): New function, split out from...
+       (cris_constant_alignment): ...here.
+       (cris_static_rtx_alignment): New function.
+       * config/i386/i386.c (ix86_static_rtx_alignment): New function,
+       split out from...
+       (ix86_constant_alignment): ...here.
+       (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
+       * config/mmix/mmix.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
+       (mmix_static_rtx_alignment): New function.
+       * config/spu/spu.c (spu_static_rtx_alignment): New function.
+       (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
+
 2017-10-26  Tamar Christina  <tamar.christina@arm.com>
 
        PR target/81800
index fe80a27b2d6d5d94a4fd4514aabc8e0a2ee61339..8fa234f7ff0577061c9a8bbe7db0983ea7bf88e5 100644 (file)
@@ -165,6 +165,7 @@ static bool cris_function_value_regno_p (const unsigned int);
 static void cris_file_end (void);
 static unsigned int cris_hard_regno_nregs (unsigned int, machine_mode);
 static bool cris_hard_regno_mode_ok (unsigned int, machine_mode);
+static HOST_WIDE_INT cris_static_rtx_alignment (machine_mode);
 static HOST_WIDE_INT cris_constant_alignment (const_tree, HOST_WIDE_INT);
 
 /* This is the parsed result of the "-max-stack-stackframe=" option.  If
@@ -288,6 +289,8 @@ int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
 #undef TARGET_HARD_REGNO_MODE_OK
 #define TARGET_HARD_REGNO_MODE_OK cris_hard_regno_mode_ok
 
+#undef TARGET_STATIC_RTX_ALIGNMENT
+#define TARGET_STATIC_RTX_ALIGNMENT cris_static_rtx_alignment
 #undef TARGET_CONSTANT_ALIGNMENT
 #define TARGET_CONSTANT_ALIGNMENT cris_constant_alignment
 
@@ -4329,6 +4332,26 @@ cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
              || (regno != CRIS_MOF_REGNUM && regno != CRIS_ACR_REGNUM)));
 }
 
+/* Return the preferred minimum alignment for a static object.  */
+
+static HOST_WIDE_INT
+cris_preferred_mininum_alignment (void)
+{
+  if (!TARGET_CONST_ALIGN)
+    return 8;
+  if (TARGET_ALIGN_BY_32)
+    return 32;
+  return 16;
+}
+
+/* Implement TARGET_STATIC_RTX_ALIGNMENT.  */
+
+static HOST_WIDE_INT
+cris_static_rtx_alignment (machine_mode mode)
+{
+  return MAX (cris_preferred_mininum_alignment (), GET_MODE_ALIGNMENT (mode));
+}
+
 /* Implement TARGET_CONSTANT_ALIGNMENT.  Note that this hook has the
    effect of making gcc believe that ALL references to constant stuff
    (in code segment, like strings) have this alignment.  That is a rather
@@ -4339,11 +4362,7 @@ cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
 static HOST_WIDE_INT
 cris_constant_alignment (const_tree, HOST_WIDE_INT basic_align)
 {
-  if (!TARGET_CONST_ALIGN)
-    return basic_align;
-  if (TARGET_ALIGN_BY_32)
-    return MAX (basic_align, 32);
-  return MAX (basic_align, 16);
+  return MAX (cris_preferred_mininum_alignment (), basic_align);
 }
 
 #if 0
index 56486e049c7146c910bd9472c03ef5066b428973..1facf121987c9d8b21cdf4a513ecfe66be4c9060 100644 (file)
@@ -28741,6 +28741,18 @@ ix86_sched_init_global (FILE *, int, int)
 }
 
 \f
+/* Implement TARGET_STATIC_RTX_ALIGNMENT.  */
+
+static HOST_WIDE_INT
+ix86_static_rtx_alignment (machine_mode mode)
+{
+  if (mode == DFmode)
+    return 64;
+  if (ALIGN_MODE_128 (mode))
+    return MAX (128, GET_MODE_ALIGNMENT (mode));
+  return GET_MODE_ALIGNMENT (mode);
+}
+
 /* Implement TARGET_CONSTANT_ALIGNMENT.  */
 
 static HOST_WIDE_INT
@@ -28749,10 +28761,9 @@ ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align)
   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
       || TREE_CODE (exp) == INTEGER_CST)
     {
-      if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
-       return 64;
-      else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
-       return 128;
+      machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
+      HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode);
+      return MAX (mode_align, align);
     }
   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
           && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
@@ -50295,6 +50306,8 @@ ix86_run_selftests (void)
 #undef TARGET_CAN_CHANGE_MODE_CLASS
 #define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class
 
+#undef TARGET_STATIC_RTX_ALIGNMENT
+#define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment
 #undef TARGET_CONSTANT_ALIGNMENT
 #define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment
 
index e9115941e1e94f7d89645a7c77d0e53f57552622..4a73162c18c09d20329b109b679ea49fe2a34554 100644 (file)
@@ -168,6 +168,7 @@ static void mmix_print_operand (FILE *, rtx, int);
 static void mmix_print_operand_address (FILE *, machine_mode, rtx);
 static bool mmix_print_operand_punct_valid_p (unsigned char);
 static void mmix_conditional_register_usage (void);
+static HOST_WIDE_INT mmix_static_rtx_alignment (machine_mode);
 static HOST_WIDE_INT mmix_constant_alignment (const_tree, HOST_WIDE_INT);
 static HOST_WIDE_INT mmix_starting_frame_offset (void);
 
@@ -284,6 +285,8 @@ static HOST_WIDE_INT mmix_starting_frame_offset (void);
 #undef TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE mmix_option_override
 
+#undef TARGET_STATIC_RTX_ALIGNMENT
+#define TARGET_STATIC_RTX_ALIGNMENT mmix_static_rtx_alignment
 #undef TARGET_CONSTANT_ALIGNMENT
 #define TARGET_CONSTANT_ALIGNMENT mmix_constant_alignment
 
@@ -342,6 +345,14 @@ mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
   return basic_align;
 }
 
+/* Implement TARGET_STATIC_RTX_ALIGNMENT.  */
+
+static HOST_WIDE_INT
+mmix_static_rtx_alignment (machine_mode mode)
+{
+  return MAX (GET_MODE_ALIGNMENT (mode), 32);
+}
+
 /* Implement tARGET_CONSTANT_ALIGNMENT.  */
 
 static HOST_WIDE_INT
index eda7fcaaeb9ec21eea51a95403a982a4c5fcdee9..bf21cca5157325cde8003ef2dfd9caa5085bec59 100644 (file)
@@ -7196,6 +7196,18 @@ spu_truly_noop_truncation (unsigned int outprec, unsigned int inprec)
   return inprec <= 32 && outprec <= inprec;
 }
 
+/* Implement TARGET_STATIC_RTX_ALIGNMENT.
+
+   Make all static objects 16-byte aligned.  This allows us to assume
+   they are also padded to 16 bytes, which means we can use a single
+   load or store instruction to access them.  */
+
+static HOST_WIDE_INT
+spu_static_rtx_alignment (machine_mode mode)
+{
+  return MAX (GET_MODE_ALIGNMENT (mode), 128);
+}
+
 /* Implement TARGET_CONSTANT_ALIGNMENT.
 
    Make all static objects 16-byte aligned.  This allows us to assume
@@ -7447,6 +7459,8 @@ static const struct attribute_spec spu_attribute_table[] =
 #undef TARGET_TRULY_NOOP_TRUNCATION
 #define TARGET_TRULY_NOOP_TRUNCATION spu_truly_noop_truncation
 
+#undef TARGET_STATIC_RTX_ALIGNMENT
+#define TARGET_STATIC_RTX_ALIGNMENT spu_static_rtx_alignment
 #undef TARGET_CONSTANT_ALIGNMENT
 #define TARGET_CONSTANT_ALIGNMENT spu_constant_alignment
 
index 8484c1d3602f4eb6a4d219c4028145807f92845b..c02f4d35116057b243e15a581e3f7618fed15e29 100644 (file)
@@ -1078,6 +1078,13 @@ On 32-bit ELF the largest supported section alignment in bits is
 @samp{(0x80000000 * 8)}, but this is not representable on 32-bit hosts.
 @end defmac
 
+@deftypefn {Target Hook} HOST_WIDE_INT TARGET_STATIC_RTX_ALIGNMENT (machine_mode @var{mode})
+This hook returns the preferred alignment in bits for a
+statically-allocated rtx, such as a constant pool entry.  @var{mode}
+is the mode of the rtx.  The default implementation returns
+@samp{GET_MODE_ALIGNMENT (@var{mode})}.
+@end deftypefn
+
 @defmac DATA_ALIGNMENT (@var{type}, @var{basic-align})
 If defined, a C expression to compute the alignment for a variable in
 the static store.  @var{type} is the data type, and @var{basic-align} is
index 015f59eac2e2fba93cbbe7aedc27b1059e37fbc6..37308e1e551e7a7d163430fdf436fd14a6610c9a 100644 (file)
@@ -1026,6 +1026,8 @@ On 32-bit ELF the largest supported section alignment in bits is
 @samp{(0x80000000 * 8)}, but this is not representable on 32-bit hosts.
 @end defmac
 
+@hook TARGET_STATIC_RTX_ALIGNMENT
+
 @defmac DATA_ALIGNMENT (@var{type}, @var{basic-align})
 If defined, a C expression to compute the alignment for a variable in
 the static store.  @var{type} is the data type, and @var{basic-align} is
index 435849c3d35f506e1285fc6834f543994c574414..6a1cd31f2acc50ae34aace5699f72d880100e15b 100644 (file)
@@ -3335,6 +3335,15 @@ HOOK_VECTOR_END (addr_space)
 #undef HOOK_PREFIX
 #define HOOK_PREFIX "TARGET_"
 
+DEFHOOK
+(static_rtx_alignment,
+ "This hook returns the preferred alignment in bits for a\n\
+statically-allocated rtx, such as a constant pool entry.  @var{mode}\n\
+is the mode of the rtx.  The default implementation returns\n\
+@samp{GET_MODE_ALIGNMENT (@var{mode})}.",
+ HOST_WIDE_INT, (machine_mode mode),
+ default_static_rtx_alignment)
+
 DEFHOOK
 (constant_alignment,
  "This hook returns the alignment in bits of a constant that is being\n\
index 41cab3825df20ddf8baa2a98bb57de6e41fda4ba..92ecc90d4d4deff8644be7e850b99809b727680e 100644 (file)
@@ -1173,6 +1173,14 @@ tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED,
    return id;
 }
 
+/* The default implementation of TARGET_STATIC_RTX_ALIGNMENT.  */
+
+HOST_WIDE_INT
+default_static_rtx_alignment (machine_mode mode)
+{
+  return GET_MODE_ALIGNMENT (mode);
+}
+
 /* The default implementation of TARGET_CONSTANT_ALIGNMENT.  */
 
 HOST_WIDE_INT
index 1510bb97a9ca46aed2a43d0eb130629376e085da..f60bca257f7aad4d7f583b8d0c6fb74415b8b2e0 100644 (file)
@@ -94,6 +94,7 @@ extern int default_builtin_vectorization_cost (enum vect_cost_for_stmt, tree, in
 
 extern tree default_builtin_reciprocal (tree);
 
+extern HOST_WIDE_INT default_static_rtx_alignment (machine_mode);
 extern HOST_WIDE_INT default_constant_alignment (const_tree, HOST_WIDE_INT);
 extern HOST_WIDE_INT constant_alignment_word_strings (const_tree,
                                                      HOST_WIDE_INT);
index d324ca034fbf844af717a4b1b4f302e7dadbba72..a139151b2e167b5ffc108be77f3f5266a28b0059 100644 (file)
@@ -3783,11 +3783,8 @@ force_const_mem (machine_mode mode, rtx x)
   *slot = desc;
 
   /* Align the location counter as required by EXP's data type.  */
-  align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
-
-  tree type = lang_hooks.types.type_for_mode (mode, 0);
-  if (type != NULL_TREE)
-    align = targetm.constant_alignment (make_tree (type, x), align);
+  machine_mode align_mode = (mode == VOIDmode ? word_mode : mode);
+  align = targetm.static_rtx_alignment (align_mode);
 
   pool->offset += (align / BITS_PER_UNIT) - 1;
   pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
@@ -3829,7 +3826,6 @@ force_const_mem (machine_mode mode, rtx x)
 
   /* Construct the MEM.  */
   desc->mem = def = gen_const_mem (mode, symbol);
-  set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
   set_mem_align (def, align);
 
   /* If we're dropping a label to the constant pool, make sure we