From 58e17cf84636d72e3620b5af50b0336d9364ddd0 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Mon, 25 Sep 2017 16:04:27 +0000 Subject: [PATCH] Turn CONSTANT_ALIGNMENT into a hook The definition: #define CONSTANT_ALIGNMENT(EXP, ALIGN) \ (TREE_CODE (EXP) == STRING_CST \ && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) was very common, so the patch adds a canned definition for that, called constant_alignment_word_strings. Some ports had a variation that used a port-local FASTEST_ALIGNMENT instead of BITS_PER_WORD; the patch uses constant_alignment_word_strings if FASTEST_ALIGNMENT was always BITS_PER_WORD and a port-local hook function otherwise. 2017-09-25 Richard Sandiford gcc/ * target.def (constant_alignment): New hook. * defaults.h (CONSTANT_ALIGNMENT): Delete. * doc/tm.texi.in (CONSTANT_ALIGNMENT): Replace with... (TARGET_CONSTANT_ALIGNMENT): ...this new hook. * doc/tm.texi: Regenerate. * targhooks.h (default_constant_alignment): Declare. (constant_alignment_word_strings): Likewise. * targhooks.c (default_constant_alignment): New function. (constant_alignment_word_strings): Likewise. * builtins.c (get_object_alignment_2): Use targetm.constant_alignment instead of CONSTANT_ALIGNMENT. * varasm.c (align_variable, get_variable_align, build_constant_desc) (force_const_mem): Likewise. * config/aarch64/aarch64.h (CONSTANT_ALIGNMENT): Delete. * config/aarch64/aarch64.c (aarch64_constant_alignment): New function. (aarch64_classify_address): Call it instead of CONSTANT_ALIGNMENT. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/alpha/alpha.h (CONSTANT_ALIGNMENT): Delete commented-out definition. * config/arc/arc.h (CONSTANT_ALIGNMENT): Delete. * config/arc/arc.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/arm/arm.h (CONSTANT_ALIGNMENT_FACTOR): Delete. (CONSTANT_ALIGNMENT): Likewise. * config/arm/arm.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (arm_constant_alignment): New function. * config/bfin/bfin.h (CONSTANT_ALIGNMENT): Delete. * config/bfin/bfin.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/cr16/cr16.h (CONSTANT_ALIGNMENT): Delete. * config/cr16/cr16.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/cris/cris.h (CONSTANT_ALIGNMENT): Delete. * config/cris/cris.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (cris_constant_alignment): New function. * config/epiphany/epiphany.h (CONSTANT_ALIGNMENT): Delete. * config/epiphany/epiphany.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (epiphany_constant_alignment): New function. * config/fr30/fr30.h (CONSTANT_ALIGNMENT): Delete. * config/fr30/fr30.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/frv/frv.h (CONSTANT_ALIGNMENT): Delete. * config/frv/frv.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/ft32/ft32.h (CONSTANT_ALIGNMENT): Delete. * config/ft32/ft32.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/i386/i386.h (CONSTANT_ALIGNMENT): Delete. * config/i386/i386-protos.h (ix86_constant_alignment): Delete. * config/i386/i386.c (ix86_constant_alignment): Make static. Use the same interface as the target hook. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/ia64/ia64.h (CONSTANT_ALIGNMENT): Delete. * config/ia64/ia64.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/iq2000/iq2000.h (CONSTANT_ALIGNMENT): Delete. * config/iq2000/iq2000.c (iq2000_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/lm32/lm32.h (CONSTANT_ALIGNMENT): Delete. * config/lm32/lm32.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/m32r/m32r.h (CONSTANT_ALIGNMENT): Delete. * config/m32r/m32r.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/mcore/mcore.h (CONSTANT_ALIGNMENT): Delete. * config/mcore/mcore.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/microblaze/microblaze.h (CONSTANT_ALIGNMENT): Delete. * config/microblaze/microblaze.c (microblaze_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/mips/mips.h (CONSTANT_ALIGNMENT): Delete. * config/mips/mips.c (mips_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/mmix/mmix.h (CONSTANT_ALIGNMENT): Delete. * config/mmix/mmix-protos.h (mmix_constant_alignment): Delete. * config/mmix/mmix.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (mmix_constant_alignment): Make static. Use the same interface as the target hook. * config/moxie/moxie.h (CONSTANT_ALIGNMENT): Delete. * config/moxie/moxie.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/nios2/nios2.h (CONSTANT_ALIGNMENT): Delete. * config/nios2/nios2.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/pa/pa.h (CONSTANT_ALIGNMENT): Delete. * config/pa/pa.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/powerpcspe/powerpcspe.h (CONSTANT_ALIGNMENT): Delete. * config/powerpcspe/powerpcspe.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (rs6000_constant_alignment): New function. * config/riscv/riscv.h (CONSTANT_ALIGNMENT): Delete. * config/riscv/riscv.c (riscv_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/rs6000/rs6000.h (CONSTANT_ALIGNMENT): Delete. * config/rs6000/rs6000.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (rs6000_constant_alignment): New function. * config/s390/s390.h (CONSTANT_ALIGNMENT): Delete. * config/s390/s390.c (s390_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/sh/sh.h (CONSTANT_ALIGNMENT): Delete. * config/sh/sh.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/sparc/sparc.h (CONSTANT_ALIGNMENT): Delete. * config/sparc/sparc.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (sparc_constant_alignment): New function. * config/spu/spu.h (CONSTANT_ALIGNMENT): Delete. * config/spu/spu.c (spu_constant_alignment): New function. (TARGET_CONSTANT_ALIGNMENT): Redefine. * config/stormy16/stormy16.h (CONSTANT_ALIGNMENT): Delete. * config/stormy16/stormy16.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/tilegx/tilegx.h (CONSTANT_ALIGNMENT): Delete. * config/tilegx/tilegx.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/tilepro/tilepro.h (CONSTANT_ALIGNMENT): Delete. * config/tilepro/tilepro.c (TARGET_CONSTANT_ALIGNMENT): Redefine to constant_alignment_word_strings. * config/visium/visium.h (CONSTANT_ALIGNMENT): Delete. * config/visium/visium.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (visium_constant_alignment): New function. * config/xtensa/xtensa.h (CONSTANT_ALIGNMENT): Delete. * config/xtensa/xtensa.c (TARGET_CONSTANT_ALIGNMENT): Redefine. (xtensa_constant_alignment): New function. * system.h (CONSTANT_ALIGNMENT): Poison. From-SVN: r253154 --- gcc/ChangeLog | 128 +++++++++++++++++++++++++++++ gcc/builtins.c | 4 +- gcc/config/aarch64/aarch64.c | 16 +++- gcc/config/aarch64/aarch64.h | 8 -- gcc/config/alpha/alpha.h | 1 - gcc/config/arc/arc.c | 3 + gcc/config/arc/arc.h | 7 -- gcc/config/arm/arm.c | 16 ++++ gcc/config/arm/arm.h | 9 -- gcc/config/bfin/bfin.c | 3 + gcc/config/bfin/bfin.h | 5 -- gcc/config/cr16/cr16.c | 3 + gcc/config/cr16/cr16.h | 5 -- gcc/config/cris/cris.c | 21 +++++ gcc/config/cris/cris.h | 11 --- gcc/config/epiphany/epiphany.c | 14 ++++ gcc/config/epiphany/epiphany.h | 6 -- gcc/config/fr30/fr30.c | 3 + gcc/config/fr30/fr30.h | 4 - gcc/config/frv/frv.c | 2 + gcc/config/frv/frv.h | 14 ---- gcc/config/ft32/ft32.c | 3 + gcc/config/ft32/ft32.h | 6 -- gcc/config/i386/i386-protos.h | 1 - gcc/config/i386/i386.c | 13 ++- gcc/config/i386/i386.h | 14 ---- gcc/config/ia64/ia64.c | 3 + gcc/config/ia64/ia64.h | 9 -- gcc/config/iq2000/iq2000.c | 14 ++++ gcc/config/iq2000/iq2000.h | 4 - gcc/config/lm32/lm32.c | 3 + gcc/config/lm32/lm32.h | 5 -- gcc/config/m32r/m32r.c | 3 + gcc/config/m32r/m32r.h | 6 -- gcc/config/mcore/mcore.c | 3 + gcc/config/mcore/mcore.h | 6 -- gcc/config/microblaze/microblaze.c | 13 +++ gcc/config/microblaze/microblaze.h | 6 -- gcc/config/mips/mips.c | 13 +++ gcc/config/mips/mips.h | 16 ---- gcc/config/mmix/mmix-protos.h | 1 - gcc/config/mmix/mmix.c | 10 ++- gcc/config/mmix/mmix.h | 3 - gcc/config/moxie/moxie.c | 3 + gcc/config/moxie/moxie.h | 6 -- gcc/config/nios2/nios2.c | 3 + gcc/config/nios2/nios2.h | 4 - gcc/config/pa/pa.c | 3 + gcc/config/pa/pa.h | 5 -- gcc/config/powerpcspe/powerpcspe.c | 14 ++++ gcc/config/powerpcspe/powerpcspe.h | 8 -- gcc/config/riscv/riscv.c | 14 ++++ gcc/config/riscv/riscv.h | 16 ---- gcc/config/rs6000/rs6000.c | 14 ++++ gcc/config/rs6000/rs6000.h | 8 -- gcc/config/s390/s390.c | 12 +++ gcc/config/s390/s390.h | 1 - gcc/config/sh/sh.c | 3 + gcc/config/sh/sh.h | 6 -- gcc/config/sparc/sparc.c | 14 ++++ gcc/config/sparc/sparc.h | 6 -- gcc/config/spu/spu.c | 17 +++- gcc/config/spu/spu.h | 1 - gcc/config/stormy16/stormy16.c | 3 + gcc/config/stormy16/stormy16.h | 4 - gcc/config/tilegx/tilegx.c | 3 + gcc/config/tilegx/tilegx.h | 7 -- gcc/config/tilepro/tilepro.c | 3 + gcc/config/tilepro/tilepro.h | 7 -- gcc/config/visium/visium.c | 13 +++ gcc/config/visium/visium.h | 10 --- gcc/config/xtensa/xtensa.c | 19 +++++ gcc/config/xtensa/xtensa.h | 11 --- gcc/defaults.h | 4 - gcc/doc/tm.texi | 19 ++--- gcc/doc/tm.texi.in | 14 +--- gcc/system.h | 2 +- gcc/target.def | 15 ++++ gcc/targhooks.c | 19 +++++ gcc/targhooks.h | 3 + gcc/varasm.c | 16 ++-- 81 files changed, 470 insertions(+), 298 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ae61ed3f566..e27d0ba48d6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,131 @@ +2017-09-25 Richard Sandiford + + * target.def (constant_alignment): New hook. + * defaults.h (CONSTANT_ALIGNMENT): Delete. + * doc/tm.texi.in (CONSTANT_ALIGNMENT): Replace with... + (TARGET_CONSTANT_ALIGNMENT): ...this new hook. + * doc/tm.texi: Regenerate. + * targhooks.h (default_constant_alignment): Declare. + (constant_alignment_word_strings): Likewise. + * targhooks.c (default_constant_alignment): New function. + (constant_alignment_word_strings): Likewise. + * builtins.c (get_object_alignment_2): Use targetm.constant_alignment + instead of CONSTANT_ALIGNMENT. + * varasm.c (align_variable, get_variable_align, build_constant_desc) + (force_const_mem): Likewise. + * config/aarch64/aarch64.h (CONSTANT_ALIGNMENT): Delete. + * config/aarch64/aarch64.c (aarch64_constant_alignment): New function. + (aarch64_classify_address): Call it instead of CONSTANT_ALIGNMENT. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/alpha/alpha.h (CONSTANT_ALIGNMENT): Delete commented-out + definition. + * config/arc/arc.h (CONSTANT_ALIGNMENT): Delete. + * config/arc/arc.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/arm/arm.h (CONSTANT_ALIGNMENT_FACTOR): Delete. + (CONSTANT_ALIGNMENT): Likewise. + * config/arm/arm.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (arm_constant_alignment): New function. + * config/bfin/bfin.h (CONSTANT_ALIGNMENT): Delete. + * config/bfin/bfin.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/cr16/cr16.h (CONSTANT_ALIGNMENT): Delete. + * config/cr16/cr16.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/cris/cris.h (CONSTANT_ALIGNMENT): Delete. + * config/cris/cris.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (cris_constant_alignment): New function. + * config/epiphany/epiphany.h (CONSTANT_ALIGNMENT): Delete. + * config/epiphany/epiphany.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (epiphany_constant_alignment): New function. + * config/fr30/fr30.h (CONSTANT_ALIGNMENT): Delete. + * config/fr30/fr30.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/frv/frv.h (CONSTANT_ALIGNMENT): Delete. + * config/frv/frv.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/ft32/ft32.h (CONSTANT_ALIGNMENT): Delete. + * config/ft32/ft32.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/i386/i386.h (CONSTANT_ALIGNMENT): Delete. + * config/i386/i386-protos.h (ix86_constant_alignment): Delete. + * config/i386/i386.c (ix86_constant_alignment): Make static. + Use the same interface as the target hook. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/ia64/ia64.h (CONSTANT_ALIGNMENT): Delete. + * config/ia64/ia64.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/iq2000/iq2000.h (CONSTANT_ALIGNMENT): Delete. + * config/iq2000/iq2000.c (iq2000_constant_alignment): New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/lm32/lm32.h (CONSTANT_ALIGNMENT): Delete. + * config/lm32/lm32.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/m32r/m32r.h (CONSTANT_ALIGNMENT): Delete. + * config/m32r/m32r.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/mcore/mcore.h (CONSTANT_ALIGNMENT): Delete. + * config/mcore/mcore.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/microblaze/microblaze.h (CONSTANT_ALIGNMENT): Delete. + * config/microblaze/microblaze.c (microblaze_constant_alignment): + New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/mips/mips.h (CONSTANT_ALIGNMENT): Delete. + * config/mips/mips.c (mips_constant_alignment): New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/mmix/mmix.h (CONSTANT_ALIGNMENT): Delete. + * config/mmix/mmix-protos.h (mmix_constant_alignment): Delete. + * config/mmix/mmix.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (mmix_constant_alignment): Make static. Use the same interface + as the target hook. + * config/moxie/moxie.h (CONSTANT_ALIGNMENT): Delete. + * config/moxie/moxie.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/nios2/nios2.h (CONSTANT_ALIGNMENT): Delete. + * config/nios2/nios2.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/pa/pa.h (CONSTANT_ALIGNMENT): Delete. + * config/pa/pa.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/powerpcspe/powerpcspe.h (CONSTANT_ALIGNMENT): Delete. + * config/powerpcspe/powerpcspe.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (rs6000_constant_alignment): New function. + * config/riscv/riscv.h (CONSTANT_ALIGNMENT): Delete. + * config/riscv/riscv.c (riscv_constant_alignment): New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/rs6000/rs6000.h (CONSTANT_ALIGNMENT): Delete. + * config/rs6000/rs6000.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (rs6000_constant_alignment): New function. + * config/s390/s390.h (CONSTANT_ALIGNMENT): Delete. + * config/s390/s390.c (s390_constant_alignment): New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/sh/sh.h (CONSTANT_ALIGNMENT): Delete. + * config/sh/sh.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/sparc/sparc.h (CONSTANT_ALIGNMENT): Delete. + * config/sparc/sparc.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (sparc_constant_alignment): New function. + * config/spu/spu.h (CONSTANT_ALIGNMENT): Delete. + * config/spu/spu.c (spu_constant_alignment): New function. + (TARGET_CONSTANT_ALIGNMENT): Redefine. + * config/stormy16/stormy16.h (CONSTANT_ALIGNMENT): Delete. + * config/stormy16/stormy16.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/tilegx/tilegx.h (CONSTANT_ALIGNMENT): Delete. + * config/tilegx/tilegx.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/tilepro/tilepro.h (CONSTANT_ALIGNMENT): Delete. + * config/tilepro/tilepro.c (TARGET_CONSTANT_ALIGNMENT): Redefine to + constant_alignment_word_strings. + * config/visium/visium.h (CONSTANT_ALIGNMENT): Delete. + * config/visium/visium.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (visium_constant_alignment): New function. + * config/xtensa/xtensa.h (CONSTANT_ALIGNMENT): Delete. + * config/xtensa/xtensa.c (TARGET_CONSTANT_ALIGNMENT): Redefine. + (xtensa_constant_alignment): New function. + * system.h (CONSTANT_ALIGNMENT): Poison. + 2017-09-25 Will Schmidt * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add handling diff --git a/gcc/builtins.c b/gcc/builtins.c index c8a5ea62611..ff049aa9d37 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -283,7 +283,7 @@ get_object_alignment_2 (tree exp, unsigned int *alignp, exp = DECL_INITIAL (exp); align = TYPE_ALIGN (TREE_TYPE (exp)); if (CONSTANT_CLASS_P (exp)) - align = (unsigned) CONSTANT_ALIGNMENT (exp, align); + align = targetm.constant_alignment (exp, align); known_alignment = true; } @@ -359,7 +359,7 @@ get_object_alignment_2 (tree exp, unsigned int *alignp, wrapped inside a CONST_DECL. */ align = TYPE_ALIGN (TREE_TYPE (exp)); if (CONSTANT_CLASS_P (exp)) - align = (unsigned) CONSTANT_ALIGNMENT (exp, align); + align = targetm.constant_alignment (exp, align); known_alignment = true; } diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 9b02c6e85e4..71d8dc4471e 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -1142,6 +1142,17 @@ aarch64_hard_regno_caller_save_mode (unsigned regno, unsigned nregs, return choose_hard_reg_mode (regno, nregs, false); } +/* Implement TARGET_CONSTANT_ALIGNMENT. Make strings word-aligned so + that strcpy from constants will be faster. */ + +static HOST_WIDE_INT +aarch64_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST && !optimize_size) + return MAX (align, BITS_PER_WORD); + return align; +} + /* Return true if calls to DECL should be treated as long-calls (ie called via a register). */ static bool @@ -4622,7 +4633,7 @@ aarch64_classify_address (struct aarch64_address_info *info, { tree exp = SYMBOL_REF_DECL (sym); align = TYPE_ALIGN (TREE_TYPE (exp)); - align = CONSTANT_ALIGNMENT (exp, align); + align = aarch64_constant_alignment (exp, align); } else if (SYMBOL_REF_DECL (sym)) align = DECL_ALIGN (SYMBOL_REF_DECL (sym)); @@ -15687,6 +15698,9 @@ aarch64_libgcc_floating_mode_supported_p #define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \ aarch64_hard_regno_call_part_clobbered +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT aarch64_constant_alignment + #if CHECKING_P #undef TARGET_RUN_TARGET_SELFTESTS #define TARGET_RUN_TARGET_SELFTESTS selftest::aarch64_run_selftests diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index fe3dd43c679..0786b283719 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -90,14 +90,6 @@ port. */ #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_delta -/* Make strings word-aligned so that strcpy from constants will be - faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && !optimize_size \ - && (ALIGN) < BITS_PER_WORD) \ - ? BITS_PER_WORD : ALIGN) - /* Align definitions of arrays, unions and structures so that initializations and copies can be made more efficient. This is not ABI-changing, so it only affects places where we can see the diff --git a/gcc/config/alpha/alpha.h b/gcc/config/alpha/alpha.h index 82d04d6135a..a2878c64e94 100644 --- a/gcc/config/alpha/alpha.h +++ b/gcc/config/alpha/alpha.h @@ -289,7 +289,6 @@ extern enum alpha_fp_trap_mode alpha_fptm; /* ??? Only if block-move stuff knows about different source/destination alignment. */ #if 0 -#define CONSTANT_ALIGNMENT(EXP, ALIGN) MAX ((ALIGN), BITS_PER_WORD) #define DATA_ALIGNMENT(EXP, ALIGN) MAX ((ALIGN), BITS_PER_WORD) #endif diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c index 61c83fc9389..a0b667586b3 100644 --- a/gcc/config/arc/arc.c +++ b/gcc/config/arc/arc.c @@ -10657,6 +10657,9 @@ arc_use_anchors_for_symbol_p (const_rtx symbol) #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P #define TARGET_USE_ANCHORS_FOR_SYMBOL_P arc_use_anchors_for_symbol_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-arc.h" diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h index 6c634301ee9..91a4c90ac93 100644 --- a/gcc/config/arc/arc.h +++ b/gcc/config/arc/arc.h @@ -271,13 +271,6 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \ /* The best alignment to use in cases where we have a choice. */ #define FASTEST_ALIGNMENT 32 -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - - /* Make arrays of chars word-aligned for the same reasons. */ #define LOCAL_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index f9c1ce35f37..363f5499a67 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -316,6 +316,7 @@ static opt_scalar_float_mode arm_floatn_mode (int, bool); static unsigned int arm_hard_regno_nregs (unsigned int, machine_mode); static bool arm_hard_regno_mode_ok (unsigned int, machine_mode); static bool arm_modes_tieable_p (machine_mode, machine_mode); +static HOST_WIDE_INT arm_constant_alignment (const_tree, HOST_WIDE_INT); /* Table of machine attributes. */ static const struct attribute_spec arm_attribute_table[] = @@ -795,6 +796,9 @@ static const struct attribute_spec arm_attribute_table[] = #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS arm_can_change_mode_class + +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT arm_constant_alignment /* Obstack for minipool constant handling. */ static struct obstack minipool_obstack; @@ -31276,6 +31280,18 @@ arm_can_change_mode_class (machine_mode from, machine_mode to, return true; } +/* Implement TARGET_CONSTANT_ALIGNMENT. Make strings word-aligned so + strcpy from constants will be faster. */ + +static HOST_WIDE_INT +arm_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + unsigned int factor = (TARGET_THUMB || ! arm_tune_xscale ? 1 : 2); + if (TREE_CODE (exp) == STRING_CST && !optimize_size) + return MAX (align, BITS_PER_WORD * factor); + return align; +} + #if CHECKING_P namespace selftest { diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index 9a171b07033..c71ad5cd710 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -592,15 +592,6 @@ extern int arm_arch_cmse; #define BIGGEST_FIELD_ALIGNMENT 64 #endif -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT_FACTOR (TARGET_THUMB || ! arm_tune_xscale ? 1 : 2) - -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && !optimize_size \ - && (ALIGN) < BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR) \ - ? BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR : (ALIGN)) - /* Align definitions of arrays, unions and structures so that initializations and copies can be made more efficient. This is not ABI-changing, so it only affects places where we can see the diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c index 7ef173aface..ed9ea03682f 100644 --- a/gcc/config/bfin/bfin.c +++ b/gcc/config/bfin/bfin.c @@ -5882,4 +5882,7 @@ bfin_conditional_register_usage (void) #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P bfin_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/bfin/bfin.h b/gcc/config/bfin/bfin.h index e0443da2205..787600f3308 100644 --- a/gcc/config/bfin/bfin.h +++ b/gcc/config/bfin/bfin.h @@ -321,11 +321,6 @@ extern const char *bfin_library_id_string; #define LOCAL_ALIGNMENT(TYPE, ALIGN) bfin_local_alignment ((TYPE), (ALIGN)) -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define TRAMPOLINE_SIZE (TARGET_FDPIC ? 30 : 18) /* Definitions for register eliminations. diff --git a/gcc/config/cr16/cr16.c b/gcc/config/cr16/cr16.c index c4100710a2f..55e0965ad2f 100644 --- a/gcc/config/cr16/cr16.c +++ b/gcc/config/cr16/cr16.c @@ -200,6 +200,9 @@ static void cr16_print_operand_address (FILE *, machine_mode, rtx); #undef TARGET_MEMORY_MOVE_COST #define TARGET_MEMORY_MOVE_COST cr16_memory_move_cost +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + /* Table of machine attributes. */ static const struct attribute_spec cr16_attribute_table[] = { /* ISRs have special prologue and epilogue requirements. */ diff --git a/gcc/config/cr16/cr16.h b/gcc/config/cr16/cr16.h index ce54dd74469..143a1dbfda3 100644 --- a/gcc/config/cr16/cr16.h +++ b/gcc/config/cr16/cr16.h @@ -114,11 +114,6 @@ while (0) && ((ALIGN) < BITS_PER_WORD)) \ ? (BITS_PER_WORD) : (ALIGN)) -/* In CR16 strings are word-aligned; strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(CONSTANT, ALIGN) \ - (((TREE_CODE (CONSTANT) == STRING_CST) && ((ALIGN) < BITS_PER_WORD)) \ - ? (BITS_PER_WORD) : (ALIGN)) - #define STRICT_ALIGNMENT 0 #define PCC_BITFIELD_TYPE_MATTERS 1 diff --git a/gcc/config/cris/cris.c b/gcc/config/cris/cris.c index 1b2add03298..fe80a27b2d6 100644 --- a/gcc/config/cris/cris.c +++ b/gcc/config/cris/cris.c @@ -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_constant_alignment (const_tree, HOST_WIDE_INT); /* This is the parsed result of the "-max-stack-stackframe=" option. If it (still) is zero, then there was no such option given. */ @@ -287,6 +288,9 @@ 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_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT cris_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; /* Helper for cris_load_multiple_op and cris_ret_movem_op. */ @@ -4325,6 +4329,23 @@ cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode) || (regno != CRIS_MOF_REGNUM && regno != CRIS_ACR_REGNUM))); } +/* 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 + rushed assumption. Luckily we do not care about the "alignment" + operand to builtin memcpy (only place where it counts), so it doesn't + affect any bad spots. */ + +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); +} + #if 0 /* Various small functions to replace macros. Only called from a debugger. They might collide with gcc functions or system functions, diff --git a/gcc/config/cris/cris.h b/gcc/config/cris/cris.h index b44164fd83a..570e2d9defe 100644 --- a/gcc/config/cris/cris.h +++ b/gcc/config/cris/cris.h @@ -368,17 +368,6 @@ extern int cris_cpu_version; ? (BASIC_ALIGN < 32 ? 32 : BASIC_ALIGN) \ : (BASIC_ALIGN < 16 ? 16 : BASIC_ALIGN)) : BASIC_ALIGN) -/* Note that CONSTANT_ALIGNMENT has the effect of making gcc believe that - ALL references to constant stuff (in code segment, like strings) has - this alignment. That is a rather rushed assumption. Luckily we do not - care about the "alignment" operand to builtin memcpy (only place where - it counts), so it doesn't affect any bad spots. */ -#define CONSTANT_ALIGNMENT(CONSTANT, BASIC_ALIGN) \ - (TARGET_CONST_ALIGN \ - ? (TARGET_ALIGN_BY_32 \ - ? (BASIC_ALIGN < 32 ? 32 : BASIC_ALIGN) \ - : (BASIC_ALIGN < 16 ? 16 : BASIC_ALIGN)) : BASIC_ALIGN) - /* FIXME: Define LOCAL_ALIGNMENT for word and dword or arrays and structures (if -mstack-align=), and check that it is good. */ diff --git a/gcc/config/epiphany/epiphany.c b/gcc/config/epiphany/epiphany.c index 67d52b8e891..d1d9ee9998d 100644 --- a/gcc/config/epiphany/epiphany.c +++ b/gcc/config/epiphany/epiphany.c @@ -173,6 +173,9 @@ static rtx_insn *frame_insn (rtx); #undef TARGET_HARD_REGNO_MODE_OK #define TARGET_HARD_REGNO_MODE_OK epiphany_hard_regno_mode_ok + +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT epiphany_constant_alignment bool epiphany_is_interrupt_p (tree decl) @@ -3014,4 +3017,15 @@ epiphany_start_function (FILE *file, const char *name, tree decl) ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +epiphany_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST) + return MAX (align, FASTEST_ALIGNMENT); + return align; +} + struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/epiphany/epiphany.h b/gcc/config/epiphany/epiphany.h index 303ac5e071d..290ea20a583 100644 --- a/gcc/config/epiphany/epiphany.h +++ b/gcc/config/epiphany/epiphany.h @@ -147,12 +147,6 @@ along with GCC; see the file COPYING3. If not see #define MALLOC_ABI_ALIGNMENT BIGGEST_ALIGNMENT -/* Make strings dword-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars dword-aligned for the same reasons. Also, align arrays of SImode items. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ diff --git a/gcc/config/fr30/fr30.c b/gcc/config/fr30/fr30.c index d83b2f31daa..91884811f17 100644 --- a/gcc/config/fr30/fr30.c +++ b/gcc/config/fr30/fr30.c @@ -190,6 +190,9 @@ static int fr30_num_arg_regs (machine_mode, const_tree); #undef TARGET_TRAMPOLINE_INIT #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/fr30/fr30.h b/gcc/config/fr30/fr30.h index 2e6b793b8bc..c4485096f0f 100644 --- a/gcc/config/fr30/fr30.h +++ b/gcc/config/fr30/fr30.h @@ -88,10 +88,6 @@ along with GCC; see the file COPYING3. If not see && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \ && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define STRICT_ALIGNMENT 1 #define PCC_BITFIELD_TYPE_MATTERS 1 diff --git a/gcc/config/frv/frv.c b/gcc/config/frv/frv.c index 85e22c7dcf4..c9877e74d7c 100644 --- a/gcc/config/frv/frv.c +++ b/gcc/config/frv/frv.c @@ -523,6 +523,8 @@ static bool frv_modes_tieable_p (machine_mode, machine_mode); #define TARGET_HARD_REGNO_MODE_OK frv_hard_regno_mode_ok #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P frv_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h index 350a59fbc1c..44a73e08f90 100644 --- a/gcc/config/frv/frv.h +++ b/gcc/config/frv/frv.h @@ -351,20 +351,6 @@ && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \ && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) -/* If defined, a C expression to compute the alignment given to a constant that - is being placed in memory. CONSTANT is the constant and ALIGN is the - alignment that the object would ordinarily have. The value of this macro is - used instead of that alignment to align the object. - - If this macro is not defined, then ALIGN is used. - - The typical use of this macro is to increase alignment for string constants - to be word aligned so that `strcpy' calls that copy constants can be done - inline. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - /* Define this macro to be the value 1 if instructions will fail to work if given data not on the nominal alignment. If instructions will merely go slower in that case, define this macro as 0. */ diff --git a/gcc/config/ft32/ft32.c b/gcc/config/ft32/ft32.c index fada9248329..0386e068f3b 100644 --- a/gcc/config/ft32/ft32.c +++ b/gcc/config/ft32/ft32.c @@ -940,6 +940,9 @@ ft32_elf_encode_section_info (tree decl, rtx rtl, int first) } } +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-ft32.h" diff --git a/gcc/config/ft32/ft32.h b/gcc/config/ft32/ft32.h index 643839323bf..32aa32095ea 100644 --- a/gcc/config/ft32/ft32.h +++ b/gcc/config/ft32/ft32.h @@ -354,12 +354,6 @@ enum reg_class is GET_MODE_SIZE(DImode). */ #define MAX_FIXED_MODE_SIZE 32 -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Set this nonzero if move instructions will actually fail to work when given unaligned data. */ #define STRICT_ALIGNMENT 1 diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 4df6274add2..fbe9f271434 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -209,7 +209,6 @@ extern unsigned int ix86_local_alignment (tree, machine_mode, unsigned int); extern unsigned int ix86_minimum_alignment (tree, machine_mode, unsigned int); -extern int ix86_constant_alignment (tree, int); extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *); extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *); extern int x86_field_alignment (tree, int); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 29b5a9c1bd8..d52d1df251c 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -31563,14 +31563,10 @@ ix86_sched_init_global (FILE *, int, int) } -/* Compute the alignment given to a constant that is being placed in memory. - EXP is the constant and ALIGN is the alignment that the object would - ordinarily have. - The value of this function is used instead of that alignment to align - the object. */ +/* Implement TARGET_CONSTANT_ALIGNMENT. */ -int -ix86_constant_alignment (tree exp, int align) +static HOST_WIDE_INT +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) @@ -53609,6 +53605,9 @@ ix86_run_selftests (void) #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment + #if CHECKING_P #undef TARGET_RUN_TARGET_SELFTESTS #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 012b85d07d7..899ba8b3706 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -848,20 +848,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); x86_field_alignment ((TYPE), (COMPUTED)) #endif -/* If defined, a C expression to compute the alignment given to a - constant that is being placed in memory. EXP is the constant - and ALIGN is the alignment that the object would ordinarily have. - The value of this macro is used instead of that alignment to align - the object. - - If this macro is not defined, then ALIGN is used. - - The typical use of this macro is to increase alignment for string - constants to be word aligned so that `strcpy' calls that copy - constants can be done inline. */ - -#define CONSTANT_ALIGNMENT(EXP, ALIGN) ix86_constant_alignment ((EXP), (ALIGN)) - /* If defined, a C expression to compute the alignment for a static variable. TYPE is the data type, and ALIGN is the alignment that the object would ordinarily have. The value of this macro is used diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c index 5573f27af37..fce3006d6d9 100644 --- a/gcc/config/ia64/ia64.c +++ b/gcc/config/ia64/ia64.c @@ -672,6 +672,9 @@ static const struct attribute_spec ia64_attribute_table[] = #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS ia64_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; /* Returns TRUE iff the target attribute indicated by ATTR_ID takes a plain diff --git a/gcc/config/ia64/ia64.h b/gcc/config/ia64/ia64.h index 9cfb0091910..4a9313e1d49 100644 --- a/gcc/config/ia64/ia64.h +++ b/gcc/config/ia64/ia64.h @@ -185,15 +185,6 @@ while (0) && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \ && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) -/* If defined, a C expression to compute the alignment given to a constant that - is being placed in memory. CONSTANT is the constant and ALIGN is the - alignment that the object would ordinarily have. The value of this macro is - used instead of that alignment to align the object. */ - -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define STRICT_ALIGNMENT 1 /* Define this if you wish to imitate the way many other C compilers handle diff --git a/gcc/config/iq2000/iq2000.c b/gcc/config/iq2000/iq2000.c index 460e38d2df1..297bd2bb0d4 100644 --- a/gcc/config/iq2000/iq2000.c +++ b/gcc/config/iq2000/iq2000.c @@ -180,6 +180,7 @@ static void iq2000_print_operand_address (FILE *, machine_mode, rtx); static bool iq2000_print_operand_punct_valid_p (unsigned char code); static bool iq2000_hard_regno_mode_ok (unsigned int, machine_mode); static bool iq2000_modes_tieable_p (machine_mode, machine_mode); +static HOST_WIDE_INT iq2000_constant_alignment (const_tree, HOST_WIDE_INT); #undef TARGET_INIT_BUILTINS #define TARGET_INIT_BUILTINS iq2000_init_builtins @@ -264,6 +265,9 @@ static bool iq2000_modes_tieable_p (machine_mode, machine_mode); #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P iq2000_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT iq2000_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; /* Return nonzero if we split the address into high and low parts. */ @@ -3532,4 +3536,14 @@ iq2000_modes_tieable_p (machine_mode mode1, machine_mode mode2) || GET_MODE_CLASS (mode2) == MODE_COMPLEX_FLOAT)); } +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +iq2000_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) + return MAX (align, BITS_PER_WORD); + return align; +} + #include "gt-iq2000.h" diff --git a/gcc/config/iq2000/iq2000.h b/gcc/config/iq2000/iq2000.h index ef4cd2705e1..58c3597fd78 100644 --- a/gcc/config/iq2000/iq2000.h +++ b/gcc/config/iq2000/iq2000.h @@ -96,10 +96,6 @@ || TREE_CODE (TYPE) == UNION_TYPE \ || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN)) -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define EMPTY_FIELD_BOUNDARY 32 #define STRUCTURE_SIZE_BOUNDARY 8 diff --git a/gcc/config/lm32/lm32.c b/gcc/config/lm32/lm32.c index f088069868e..a4aade494d6 100644 --- a/gcc/config/lm32/lm32.c +++ b/gcc/config/lm32/lm32.c @@ -113,6 +113,9 @@ static bool lm32_modes_tieable_p (machine_mode, machine_mode); #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P lm32_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; /* Current frame information calculated by lm32_compute_frame_size. */ diff --git a/gcc/config/lm32/lm32.h b/gcc/config/lm32/lm32.h index 916983408a4..605bd68ca7c 100644 --- a/gcc/config/lm32/lm32.h +++ b/gcc/config/lm32/lm32.h @@ -99,11 +99,6 @@ do { \ #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - /* Make arrays and structures word-aligned to allow faster copying etc. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ ((((ALIGN) < BITS_PER_WORD) \ diff --git a/gcc/config/m32r/m32r.c b/gcc/config/m32r/m32r.c index 9b7cb5f7d70..aefab935c34 100644 --- a/gcc/config/m32r/m32r.c +++ b/gcc/config/m32r/m32r.c @@ -217,6 +217,9 @@ static const struct attribute_spec m32r_attribute_table[] = #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P m32r_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; /* Called by m32r_option_override to initialize various things. */ diff --git a/gcc/config/m32r/m32r.h b/gcc/config/m32r/m32r.h index 09d73bc30c4..5b2a93bfca8 100644 --- a/gcc/config/m32r/m32r.h +++ b/gcc/config/m32r/m32r.h @@ -260,12 +260,6 @@ /* The best alignment to use in cases where we have a choice. */ #define FASTEST_ALIGNMENT 32 -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/mcore/mcore.c b/gcc/config/mcore/mcore.c index 81a5820d2e9..04dfb9d085a 100644 --- a/gcc/config/mcore/mcore.c +++ b/gcc/config/mcore/mcore.c @@ -248,6 +248,9 @@ static const struct attribute_spec mcore_attribute_table[] = #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P mcore_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; /* Adjust the stack and return the number of bytes taken to do it. */ diff --git a/gcc/config/mcore/mcore.h b/gcc/config/mcore/mcore.h index 4e9334369d1..f411186e567 100644 --- a/gcc/config/mcore/mcore.h +++ b/gcc/config/mcore/mcore.h @@ -148,12 +148,6 @@ extern char * mcore_current_function_name; is GET_MODE_SIZE(DImode). */ #define MAX_FIXED_MODE_SIZE 32 -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c index d935c3efa72..53ca016ce65 100644 --- a/gcc/config/microblaze/microblaze.c +++ b/gcc/config/microblaze/microblaze.c @@ -3800,6 +3800,16 @@ microblaze_machine_dependent_reorg (void) return; } } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +microblaze_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) + return MAX (align, BITS_PER_WORD); + return align; +} #undef TARGET_ENCODE_SECTION_INFO #define TARGET_ENCODE_SECTION_INFO microblaze_encode_section_info @@ -3904,6 +3914,9 @@ microblaze_machine_dependent_reorg (void) #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P microblaze_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT microblaze_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-microblaze.h" diff --git a/gcc/config/microblaze/microblaze.h b/gcc/config/microblaze/microblaze.h index 1726e265844..2fc7fc50a15 100644 --- a/gcc/config/microblaze/microblaze.h +++ b/gcc/config/microblaze/microblaze.h @@ -234,12 +234,6 @@ extern enum pipeline_type microblaze_pipe; #undef PTRDIFF_TYPE #define PTRDIFF_TYPE "int" -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \ - && (ALIGN) < BITS_PER_WORD \ - ? BITS_PER_WORD \ - : (ALIGN)) - #define DATA_ALIGNMENT(TYPE, ALIGN) \ ((((ALIGN) < BITS_PER_WORD) \ && (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index a71732e047b..41333755b84 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -22336,6 +22336,16 @@ mips_truly_noop_truncation (unsigned int outprec, unsigned int inprec) { return !TARGET_64BIT || inprec <= 32 || outprec > 32; } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +mips_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) + return MAX (align, BITS_PER_WORD); + return align; +} /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP @@ -22634,6 +22644,9 @@ mips_truly_noop_truncation (unsigned int outprec, unsigned int inprec) #undef TARGET_TRULY_NOOP_TRUNCATION #define TARGET_TRULY_NOOP_TRUNCATION mips_truly_noop_truncation +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT mips_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-mips.h" diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index 1f4cad8b121..a2d8c7c1350 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -1636,22 +1636,6 @@ FP_ASM_SPEC "\ #define PCC_BITFIELD_TYPE_MATTERS 1 -/* If defined, a C expression to compute the alignment given to a - constant that is being placed in memory. CONSTANT is the constant - and ALIGN is the alignment that the object would ordinarily have. - The value of this macro is used instead of that alignment to align - the object. - - If this macro is not defined, then ALIGN is used. - - The typical use of this macro is to increase alignment for string - constants to be word aligned so that `strcpy' calls that copy - constants can be done inline. */ - -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - /* If defined, a C expression to compute the alignment for a static variable. TYPE is the data type, and ALIGN is the alignment that the object would ordinarily have. The value of this macro is used diff --git a/gcc/config/mmix/mmix-protos.h b/gcc/config/mmix/mmix-protos.h index 7cb4670892d..6c38924f479 100644 --- a/gcc/config/mmix/mmix-protos.h +++ b/gcc/config/mmix/mmix-protos.h @@ -47,7 +47,6 @@ extern unsigned mmix_dbx_register_number (unsigned); extern int mmix_use_simple_return (void); extern void mmix_make_decl_one_only (tree); extern int mmix_data_alignment (tree, int); -extern int mmix_constant_alignment (tree, int); extern unsigned mmix_local_alignment (tree, unsigned); extern void mmix_asm_output_pool_prologue (FILE *, const char *, tree, int); extern void mmix_asm_output_aligned_common (FILE *, const char *, int, int); diff --git a/gcc/config/mmix/mmix.c b/gcc/config/mmix/mmix.c index 90a465160c1..09e752dca0d 100644 --- a/gcc/config/mmix/mmix.c +++ b/gcc/config/mmix/mmix.c @@ -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_constant_alignment (const_tree, HOST_WIDE_INT); /* Target structure macros. Listed by node. See `Using and Porting GCC' for a general description. */ @@ -282,6 +283,9 @@ static void mmix_conditional_register_usage (void); #undef TARGET_OPTION_OVERRIDE #define TARGET_OPTION_OVERRIDE mmix_option_override +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT mmix_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; /* Functions that are expansions for target macros. @@ -334,10 +338,10 @@ mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align) return basic_align; } -/* CONSTANT_ALIGNMENT. */ +/* Implement tARGET_CONSTANT_ALIGNMENT. */ -int -mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align) +static HOST_WIDE_INT +mmix_constant_alignment (const_tree, HOST_WIDE_INT basic_align) { if (basic_align < 32) return 32; diff --git a/gcc/config/mmix/mmix.h b/gcc/config/mmix/mmix.h index 71616561a7f..7d1e83c28e0 100644 --- a/gcc/config/mmix/mmix.h +++ b/gcc/config/mmix/mmix.h @@ -167,9 +167,6 @@ struct GTY(()) machine_function #define DATA_ABI_ALIGNMENT(TYPE, BASIC_ALIGN) \ mmix_data_alignment (TYPE, BASIC_ALIGN) -#define CONSTANT_ALIGNMENT(CONSTANT, BASIC_ALIGN) \ - mmix_constant_alignment (CONSTANT, BASIC_ALIGN) - #define LOCAL_ALIGNMENT(TYPE, BASIC_ALIGN) \ mmix_local_alignment (TYPE, BASIC_ALIGN) diff --git a/gcc/config/moxie/moxie.c b/gcc/config/moxie/moxie.c index 19cd83f5193..49012374858 100644 --- a/gcc/config/moxie/moxie.c +++ b/gcc/config/moxie/moxie.c @@ -667,6 +667,9 @@ moxie_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED, #undef TARGET_PRINT_OPERAND_ADDRESS #define TARGET_PRINT_OPERAND_ADDRESS moxie_print_operand_address +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-moxie.h" diff --git a/gcc/config/moxie/moxie.h b/gcc/config/moxie/moxie.h index 9ae5f823727..29442fb47e8 100644 --- a/gcc/config/moxie/moxie.h +++ b/gcc/config/moxie/moxie.h @@ -317,12 +317,6 @@ enum reg_class is GET_MODE_SIZE(DImode). */ #define MAX_FIXED_MODE_SIZE 32 -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index 893ddd19e59..2602605fb21 100644 --- a/gcc/config/nios2/nios2.c +++ b/gcc/config/nios2/nios2.c @@ -5116,6 +5116,9 @@ nios2_adjust_reg_alloc_order (void) #undef TARGET_MACHINE_DEPENDENT_REORG #define TARGET_MACHINE_DEPENDENT_REORG nios2_reorg +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-nios2.h" diff --git a/gcc/config/nios2/nios2.h b/gcc/config/nios2/nios2.h index d911b547baf..10bebfbcdd3 100644 --- a/gcc/config/nios2/nios2.h +++ b/gcc/config/nios2/nios2.h @@ -92,10 +92,6 @@ #define PREFERRED_STACK_BOUNDARY 32 #define MAX_FIXED_MODE_SIZE 64 -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST) \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define LABEL_ALIGN(LABEL) nios2_label_align (LABEL) /* Layout of source language data types. */ diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c index 651ae59378d..2586f92d837 100644 --- a/gcc/config/pa/pa.c +++ b/gcc/config/pa/pa.c @@ -425,6 +425,9 @@ static size_t n_deferred_plabels = 0; #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS pa_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; /* Parse the -mfixed-range= option string. */ diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h index 2edf0db76ef..fbfbe488363 100644 --- a/gcc/config/pa/pa.h +++ b/gcc/config/pa/pa.h @@ -309,11 +309,6 @@ typedef struct GTY(()) machine_function atomic operations. */ #define MALLOC_ABI_ALIGNMENT (TARGET_SOM ? 64 : 128) -/* Get around hp-ux assembler bug, and make strcpy of constants fast. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/powerpcspe/powerpcspe.c b/gcc/config/powerpcspe/powerpcspe.c index 26692aa8a69..12af88417ba 100644 --- a/gcc/config/powerpcspe/powerpcspe.c +++ b/gcc/config/powerpcspe/powerpcspe.c @@ -1984,6 +1984,9 @@ static const struct attribute_spec rs6000_attribute_table[] = #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS rs6000_can_change_mode_class + +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT rs6000_constant_alignment /* Processor table. */ @@ -43752,6 +43755,17 @@ rs6000_optab_supported_p (int op, machine_mode mode1, machine_mode, return true; } } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +rs6000_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST + && (STRICT_ALIGNMENT || !optimize_size)) + return MAX (align, BITS_PER_WORD); + return align; +} struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/powerpcspe/powerpcspe.h b/gcc/config/powerpcspe/powerpcspe.h index 52c0376edfa..8381785067c 100644 --- a/gcc/config/powerpcspe/powerpcspe.h +++ b/gcc/config/powerpcspe/powerpcspe.h @@ -978,14 +978,6 @@ enum data_align { align_abi, align_opt, align_both }; #define LOCAL_ALIGNMENT(TYPE, ALIGN) \ rs6000_data_alignment (TYPE, ALIGN, align_both) -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (STRICT_ALIGNMENT || !optimize_size) \ - && (ALIGN) < BITS_PER_WORD \ - ? BITS_PER_WORD \ - : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ rs6000_data_alignment (TYPE, ALIGN, align_opt) diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 42ddac997a6..c34468e018d 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -3995,6 +3995,17 @@ riscv_can_change_mode_class (machine_mode, machine_mode, reg_class_t rclass) return !reg_classes_intersect_p (FP_REGS, rclass); } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +riscv_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) + return MAX (align, BITS_PER_WORD); + return align; +} + /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" @@ -4142,6 +4153,9 @@ riscv_can_change_mode_class (machine_mode, machine_mode, reg_class_t rclass) #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS riscv_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT riscv_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h" diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index a04da2ce28b..c31d2cc9957 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -152,22 +152,6 @@ along with GCC; see the file COPYING3. If not see #define PCC_BITFIELD_TYPE_MATTERS 1 -/* If defined, a C expression to compute the alignment given to a - constant that is being placed in memory. CONSTANT is the constant - and ALIGN is the alignment that the object would ordinarily have. - The value of this macro is used instead of that alignment to align - the object. - - If this macro is not defined, then ALIGN is used. - - The typical use of this macro is to increase alignment for string - constants to be word aligned so that `strcpy' calls that copy - constants can be done inline. */ - -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - /* If defined, a C expression to compute the alignment for a static variable. TYPE is the data type, and ALIGN is the alignment that the object would ordinarily have. The value of this macro is used diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 3212634f783..3c01546658f 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -1974,6 +1974,9 @@ static const struct attribute_spec rs6000_attribute_table[] = #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS rs6000_can_change_mode_class + +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT rs6000_constant_alignment /* Processor table. */ @@ -39195,6 +39198,17 @@ rs6000_optab_supported_p (int op, machine_mode mode1, machine_mode, return true; } } + +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +rs6000_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST + && (STRICT_ALIGNMENT || !optimize_size)) + return MAX (align, BITS_PER_WORD); + return align; +} struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index da2f4f5c089..60219726f9d 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -950,14 +950,6 @@ enum data_align { align_abi, align_opt, align_both }; #define LOCAL_ALIGNMENT(TYPE, ALIGN) \ rs6000_data_alignment (TYPE, ALIGN, align_both) -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (STRICT_ALIGNMENT || !optimize_size) \ - && (ALIGN) < BITS_PER_WORD \ - ? BITS_PER_WORD \ - : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ rs6000_data_alignment (TYPE, ALIGN, align_opt) diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 037e22e737e..e3fafa2a642 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -15906,6 +15906,15 @@ s390_vector_alignment (const_tree type) return MIN (64, tree_to_shwi (TYPE_SIZE (type))); } +/* Implement TARGET_CONSTANT_ALIGNMENT. Alignment on even addresses for + LARL instruction. */ + +static HOST_WIDE_INT +s390_constant_alignment (const_tree, HOST_WIDE_INT align) +{ + return MAX (align, 16); +} + #ifdef HAVE_AS_MACHINE_MACHINEMODE /* Implement TARGET_ASM_FILE_START. */ static void @@ -16325,6 +16334,9 @@ s390_asan_shadow_offset (void) #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS s390_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT s390_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-s390.h" diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h index 00652da3792..52eee948bdf 100644 --- a/gcc/config/s390/s390.h +++ b/gcc/config/s390/s390.h @@ -315,7 +315,6 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv); #define EMPTY_FIELD_BOUNDARY 32 /* Alignment on even addresses for LARL instruction. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN) #define DATA_ABI_ALIGNMENT(TYPE, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN) /* Alignment is not required by the hardware. */ diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c index fa9f9ad17a6..3c6d525eb0c 100644 --- a/gcc/config/sh/sh.c +++ b/gcc/config/sh/sh.c @@ -657,6 +657,9 @@ static const struct attribute_spec sh_attribute_table[] = #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS sh_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h index a18044d1ac8..339bf284862 100644 --- a/gcc/config/sh/sh.h +++ b/gcc/config/sh/sh.h @@ -462,12 +462,6 @@ extern const sh_atomic_model& selected_atomic_model (void); /* The best alignment to use in cases where we have a choice. */ #define FASTEST_ALIGNMENT (32) -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* get_mode_alignment assumes complex values are always held in multiple registers, but that is not the case on the SH; CQImode and CHImode are held in a single integer register. */ diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c index 11e4f4565a5..d3f002d8198 100644 --- a/gcc/config/sparc/sparc.c +++ b/gcc/config/sparc/sparc.c @@ -684,6 +684,7 @@ static bool sparc_hard_regno_mode_ok (unsigned int, machine_mode); static bool sparc_modes_tieable_p (machine_mode, machine_mode); static bool sparc_can_change_mode_class (machine_mode, machine_mode, reg_class_t); +static HOST_WIDE_INT sparc_constant_alignment (const_tree, HOST_WIDE_INT); #ifdef SUBTARGET_ATTRIBUTE_TABLE /* Table of valid machine attributes. */ @@ -925,6 +926,9 @@ char sparc_hard_reg_printed[8]; #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS sparc_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT sparc_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; /* Return the memory reference contained in X if any, zero otherwise. */ @@ -13429,4 +13433,14 @@ sparc_can_change_mode_class (machine_mode from, machine_mode to, return true; } +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +sparc_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST) + return MAX (align, FASTEST_ALIGNMENT); + return align; +} + #include "gt-sparc.h" diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h index 946605d5936..9ac741f569b 100644 --- a/gcc/config/sparc/sparc.h +++ b/gcc/config/sparc/sparc.h @@ -579,12 +579,6 @@ extern enum cmodel sparc_cmodel; #define STACK_SAVEAREA_MODE(LEVEL) \ ((LEVEL) == SAVE_NONLOCAL ? (TARGET_ARCH64 ? TImode : DImode) : Pmode) -/* Make strings word-aligned so strcpy from constants will be faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/spu/spu.c b/gcc/config/spu/spu.c index ed8047dcd3d..b9af9a969f7 100644 --- a/gcc/config/spu/spu.c +++ b/gcc/config/spu/spu.c @@ -4159,7 +4159,7 @@ spu_encode_section_info (tree decl, rtx rtl, int first) which is both 16-byte aligned and padded to a 16-byte boundary. This would make it safe to store with a single instruction. We guarantee the alignment and padding for static objects by aligning - all of them to 16-bytes. (DATA_ALIGNMENT and CONSTANT_ALIGNMENT.) + all of them to 16-bytes. (DATA_ALIGNMENT and TARGET_CONSTANT_ALIGNMENT.) FIXME: We currently cannot guarantee this for objects on the stack because assign_parm_setup_stack calls assign_stack_local with the alignment of the parameter mode and in that case the alignment never @@ -7193,6 +7193,18 @@ spu_truly_noop_truncation (unsigned int outprec, unsigned int inprec) { return inprec <= 32 && outprec <= inprec; } + +/* Implement TARGET_CONSTANT_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_constant_alignment (const_tree, HOST_WIDE_INT align) +{ + return MAX (align, 128); +} /* Table of machine attributes. */ static const struct attribute_spec spu_attribute_table[] = @@ -7433,6 +7445,9 @@ static const struct attribute_spec spu_attribute_table[] = #undef TARGET_TRULY_NOOP_TRUNCATION #define TARGET_TRULY_NOOP_TRUNCATION spu_truly_noop_truncation +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT spu_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-spu.h" diff --git a/gcc/config/spu/spu.h b/gcc/config/spu/spu.h index 4cf426b7c5b..de4aa99f276 100644 --- a/gcc/config/spu/spu.h +++ b/gcc/config/spu/spu.h @@ -96,7 +96,6 @@ extern GTY(()) int spu_tune; on the stack. (Except a bug (?) allows some stack objects to be unaligned.) */ #define DATA_ALIGNMENT(TYPE,ALIGN) ((ALIGN) > 128 ? (ALIGN) : 128) -#define CONSTANT_ALIGNMENT(TYPE,ALIGN) ((ALIGN) > 128 ? (ALIGN) : 128) #define LOCAL_ALIGNMENT(TYPE,ALIGN) ((ALIGN) > 128 ? (ALIGN) : 128) #define EMPTY_FIELD_BOUNDARY 32 diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c index 89f474eba84..d0bd4335073 100644 --- a/gcc/config/stormy16/stormy16.c +++ b/gcc/config/stormy16/stormy16.c @@ -2715,6 +2715,9 @@ xstormy16_modes_tieable_p (machine_mode mode1, machine_mode mode2) #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P xstormy16_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-stormy16.h" diff --git a/gcc/config/stormy16/stormy16.h b/gcc/config/stormy16/stormy16.h index 0f19686c9d8..31d6156cc26 100644 --- a/gcc/config/stormy16/stormy16.h +++ b/gcc/config/stormy16/stormy16.h @@ -87,10 +87,6 @@ && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \ && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN)) - #define STRICT_ALIGNMENT 1 #define PCC_BITFIELD_TYPE_MATTERS 1 diff --git a/gcc/config/tilegx/tilegx.c b/gcc/config/tilegx/tilegx.c index 368821ed11a..63fe3406ae9 100644 --- a/gcc/config/tilegx/tilegx.c +++ b/gcc/config/tilegx/tilegx.c @@ -5734,6 +5734,9 @@ tilegx_truly_noop_truncation (unsigned int outprec, unsigned int inprec) #undef TARGET_TRULY_NOOP_TRUNCATION #define TARGET_TRULY_NOOP_TRUNCATION tilegx_truly_noop_truncation +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-tilegx.h" diff --git a/gcc/config/tilegx/tilegx.h b/gcc/config/tilegx/tilegx.h index 55fd89a4b86..066c34d2155 100644 --- a/gcc/config/tilegx/tilegx.h +++ b/gcc/config/tilegx/tilegx.h @@ -94,13 +94,6 @@ #define BIGGEST_FIELD_ALIGNMENT 128 #define WIDEST_HARDWARE_FP_SIZE 64 -/* Make strings word-aligned so strcpy from constants will be - faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/tilepro/tilepro.c b/gcc/config/tilepro/tilepro.c index ae3337ba0a4..ee9bc0a9343 100644 --- a/gcc/config/tilepro/tilepro.c +++ b/gcc/config/tilepro/tilepro.c @@ -5091,6 +5091,9 @@ tilepro_file_end (void) #undef TARGET_CAN_USE_DOLOOP_P #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-tilepro.h" diff --git a/gcc/config/tilepro/tilepro.h b/gcc/config/tilepro/tilepro.h index 325b2ed258f..5ab8be49be0 100644 --- a/gcc/config/tilepro/tilepro.h +++ b/gcc/config/tilepro/tilepro.h @@ -58,13 +58,6 @@ #define FASTEST_ALIGNMENT 32 #define BIGGEST_FIELD_ALIGNMENT 64 -/* Make strings word-aligned so strcpy from constants will be - faster. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - ((TREE_CODE (EXP) == STRING_CST \ - && (ALIGN) < FASTEST_ALIGNMENT) \ - ? FASTEST_ALIGNMENT : (ALIGN)) - /* Make arrays of chars word-aligned for the same reasons. */ #define DATA_ALIGNMENT(TYPE, ALIGN) \ (TREE_CODE (TYPE) == ARRAY_TYPE \ diff --git a/gcc/config/visium/visium.c b/gcc/config/visium/visium.c index 4dd66dcd40b..381d432778d 100644 --- a/gcc/config/visium/visium.c +++ b/gcc/config/visium/visium.c @@ -237,6 +237,8 @@ static bool visium_modes_tieable_p (machine_mode, machine_mode); static bool visium_can_change_mode_class (machine_mode, machine_mode, reg_class_t); +static HOST_WIDE_INT visium_constant_alignment (const_tree, HOST_WIDE_INT); + /* Setup the global target hooks structure. */ #undef TARGET_MAX_ANCHOR_OFFSET @@ -360,6 +362,9 @@ static bool visium_can_change_mode_class (machine_mode, machine_mode, #undef TARGET_CAN_CHANGE_MODE_CLASS #define TARGET_CAN_CHANGE_MODE_CLASS visium_can_change_mode_class +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT visium_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; namespace { @@ -834,6 +839,14 @@ visium_data_alignment (tree type, unsigned int align) return align; } +/* Implement TARGET_CONSTANT_ALIGNMENT. */ + +static HOST_WIDE_INT +visium_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + return visium_data_alignment (TREE_TYPE (exp), align); +} + /* Helper function for HARD_REGNO_RENAME_OK (FROM, TO). Return non-zero if it is OK to rename a hard register FROM to another hard register TO. */ diff --git a/gcc/config/visium/visium.h b/gcc/config/visium/visium.h index 4b086d32baa..3cc0bc41280 100644 --- a/gcc/config/visium/visium.h +++ b/gcc/config/visium/visium.h @@ -236,16 +236,6 @@ this macro is used instead of that alignment to align the object. */ #define DATA_ALIGNMENT(TYPE,ALIGN) visium_data_alignment (TYPE, ALIGN) -/* `CONSTANT_ALIGNMENT (CONSTANT, BASIC-ALIGN)` - - If defined, a C expression to compute the alignment given to a - constant that is being placed in memory. CONSTANT is the constant - and BASIC-ALIGN is the alignment that the object would ordinarily - have. The value of this macro is used instead of that alignment to - align the object. */ -#define CONSTANT_ALIGNMENT(EXP,ALIGN) \ - visium_data_alignment (TREE_TYPE (EXP), ALIGN) - /* `LOCAL_ALIGNMENT (TYPE, BASIC-ALIGN)` If defined, a C expression to compute the alignment for a variable diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c index 9c11ae043b5..3d60e317e6c 100644 --- a/gcc/config/xtensa/xtensa.c +++ b/gcc/config/xtensa/xtensa.c @@ -181,6 +181,7 @@ static void xtensa_conditional_register_usage (void); static unsigned int xtensa_hard_regno_nregs (unsigned int, machine_mode); static bool xtensa_hard_regno_mode_ok (unsigned int, machine_mode); static bool xtensa_modes_tieable_p (machine_mode, machine_mode); +static HOST_WIDE_INT xtensa_constant_alignment (const_tree, HOST_WIDE_INT); @@ -317,6 +318,9 @@ static bool xtensa_modes_tieable_p (machine_mode, machine_mode); #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P xtensa_modes_tieable_p +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT xtensa_constant_alignment + struct gcc_target targetm = TARGET_INITIALIZER; @@ -4380,4 +4384,19 @@ enum reg_class xtensa_regno_to_class (int regno) return regno_to_class[regno]; } +/* Implement TARGET_CONSTANT_ALIGNMENT. Align string constants and + constructors to at least a word boundary. The typical use of this + macro is to increase alignment for string constants to be word + aligned so that 'strcpy' calls that copy constants can be done + inline. */ + +static HOST_WIDE_INT +xtensa_constant_alignment (const_tree exp, HOST_WIDE_INT align) +{ + if ((TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) + && !optimize_size) + return MAX (align, BITS_PER_WORD); + return align; +} + #include "gt-xtensa.h" diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h index 74c5e52b95e..f9216391e25 100644 --- a/gcc/config/xtensa/xtensa.h +++ b/gcc/config/xtensa/xtensa.h @@ -169,17 +169,6 @@ along with GCC; see the file COPYING3. If not see bitfields and the structures that contain them. */ #define PCC_BITFIELD_TYPE_MATTERS 1 -/* Align string constants and constructors to at least a word boundary. - The typical use of this macro is to increase alignment for string - constants to be word aligned so that 'strcpy' calls that copy - constants can be done inline. */ -#define CONSTANT_ALIGNMENT(EXP, ALIGN) \ - (!optimize_size && \ - (TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \ - && (ALIGN) < BITS_PER_WORD \ - ? BITS_PER_WORD \ - : (ALIGN)) - /* Align arrays, unions and records to at least a word boundary. One use of this macro is to increase alignment of medium-size data to make it all fit in fewer cache lines. Another is to diff --git a/gcc/defaults.h b/gcc/defaults.h index d3265fcefcb..99cd9db5191 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -1265,10 +1265,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define LOAD_EXTEND_OP(M) UNKNOWN #endif -#ifndef CONSTANT_ALIGNMENT -#define CONSTANT_ALIGNMENT(EXP, ALIGN) ALIGN -#endif - #ifndef INITIAL_FRAME_ADDRESS_RTX #define INITIAL_FRAME_ADDRESS_RTX NULL #endif diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index c2493cf6251..8f503e1904e 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1102,19 +1102,18 @@ must be aligned to 16 byte boundaries. If this macro is not defined, then @var{basic-align} is used. @end defmac -@defmac CONSTANT_ALIGNMENT (@var{constant}, @var{basic-align}) -If defined, a C expression to compute the alignment given to a constant -that is being placed in memory. @var{constant} is the constant and -@var{basic-align} is the alignment that the object would ordinarily -have. The value of this macro is used instead of that alignment to -align the object. +@deftypefn {Target Hook} HOST_WIDE_INT TARGET_CONSTANT_ALIGNMENT (const_tree @var{constant}, HOST_WIDE_INT @var{basic_align}) +This hook returns the alignment in bits of a constant that is being +placed in memory. @var{constant} is the constant and @var{basic_align} +is the alignment that the object would ordinarily have. -The default definition just returns @var{basic-align}. +The default definition just returns @var{basic_align}. -The typical use of this macro is to increase alignment for string +The typical use of this hook is to increase alignment for string constants to be word aligned so that @code{strcpy} calls that copy -constants can be done inline. -@end defmac +constants can be done inline. The function +@code{constant_alignment_word_strings} provides such a definition. +@end deftypefn @defmac LOCAL_ALIGNMENT (@var{type}, @var{basic-align}) If defined, a C expression to compute the alignment for a variable in diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index fa3ff0164bd..15b3f1f6771 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -1050,19 +1050,7 @@ must be aligned to 16 byte boundaries. If this macro is not defined, then @var{basic-align} is used. @end defmac -@defmac CONSTANT_ALIGNMENT (@var{constant}, @var{basic-align}) -If defined, a C expression to compute the alignment given to a constant -that is being placed in memory. @var{constant} is the constant and -@var{basic-align} is the alignment that the object would ordinarily -have. The value of this macro is used instead of that alignment to -align the object. - -The default definition just returns @var{basic-align}. - -The typical use of this macro is to increase alignment for string -constants to be word aligned so that @code{strcpy} calls that copy -constants can be done inline. -@end defmac +@hook TARGET_CONSTANT_ALIGNMENT @defmac LOCAL_ALIGNMENT (@var{type}, @var{basic-align}) If defined, a C expression to compute the alignment for a variable in diff --git a/gcc/system.h b/gcc/system.h index c514cd8b382..59449f1942b 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -915,7 +915,7 @@ extern void fancy_abort (const char *, int, const char *) MODES_TIEABLE_P FUNCTION_ARG_PADDING SLOW_UNALIGNED_ACCESS \ HARD_REGNO_NREGS SECONDARY_MEMORY_NEEDED_MODE \ SECONDARY_MEMORY_NEEDED CANNOT_CHANGE_MODE_CLASS \ - TRULY_NOOP_TRUNCATION FUNCTION_ARG_OFFSET + TRULY_NOOP_TRUNCATION FUNCTION_ARG_OFFSET CONSTANT_ALIGNMENT /* Target macros only used for code built for the target, that have moved to libgcc-tm.h or have never been present elsewhere. */ diff --git a/gcc/target.def b/gcc/target.def index 42fd0b1854a..80ef7469a50 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -3335,6 +3335,21 @@ HOOK_VECTOR_END (addr_space) #undef HOOK_PREFIX #define HOOK_PREFIX "TARGET_" +DEFHOOK +(constant_alignment, + "This hook returns the alignment in bits of a constant that is being\n\ +placed in memory. @var{constant} is the constant and @var{basic_align}\n\ +is the alignment that the object would ordinarily have.\n\ +\n\ +The default definition just returns @var{basic_align}.\n\ +\n\ +The typical use of this hook is to increase alignment for string\n\ +constants to be word aligned so that @code{strcpy} calls that copy\n\ +constants can be done inline. The function\n\ +@code{constant_alignment_word_strings} provides such a definition.", + HOST_WIDE_INT, (const_tree constant, HOST_WIDE_INT basic_align), + default_constant_alignment) + /* True if MODE is valid for the target. By "valid", we mean able to be manipulated in non-trivial ways. In particular, this means all the arithmetic is supported. */ diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 171583d419e..d56f53d35d8 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1165,6 +1165,25 @@ tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED, return id; } +/* The default implementation of TARGET_CONSTANT_ALIGNMENT. */ + +HOST_WIDE_INT +default_constant_alignment (const_tree, HOST_WIDE_INT align) +{ + return align; +} + +/* An implementation of TARGET_CONSTANT_ALIGNMENT that aligns strings + to at least BITS_PER_WORD but otherwise makes no changes. */ + +HOST_WIDE_INT +constant_alignment_word_strings (const_tree exp, HOST_WIDE_INT align) +{ + if (TREE_CODE (exp) == STRING_CST) + return MAX (align, BITS_PER_WORD); + return align; +} + /* Default to natural alignment for vector types. */ HOST_WIDE_INT default_vector_alignment (const_tree type) diff --git a/gcc/targhooks.h b/gcc/targhooks.h index e577888654d..db1a087942a 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -93,6 +93,9 @@ extern int default_builtin_vectorization_cost (enum vect_cost_for_stmt, tree, in extern tree default_builtin_reciprocal (tree); +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); extern HOST_WIDE_INT default_vector_alignment (const_tree); extern HOST_WIDE_INT default_preferred_vector_alignment (const_tree); diff --git a/gcc/varasm.c b/gcc/varasm.c index 1c66c26ce5c..55fca76fab9 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1055,7 +1055,7 @@ align_variable (tree decl, bool dont_output_data) && (in_lto_p || DECL_INITIAL (decl) != error_mark_node)) { unsigned int const_align - = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align); + = targetm.constant_alignment (DECL_INITIAL (decl), align); /* Don't increase alignment too much for TLS variables - TLS space is too precious. */ if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD) @@ -1106,8 +1106,8 @@ get_variable_align (tree decl) to mark offlined constructors. */ && (in_lto_p || DECL_INITIAL (decl) != error_mark_node)) { - unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), - align); + unsigned int const_align + = targetm.constant_alignment (DECL_INITIAL (decl), align); /* Don't increase alignment too much for TLS variables - TLS space is too precious. */ if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD) @@ -3326,12 +3326,10 @@ build_constant_desc (tree exp) Instead we set the flag that will be recognized in make_decl_rtl. */ DECL_IN_CONSTANT_POOL (decl) = 1; DECL_INITIAL (decl) = desc->value; - /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most - architectures so use DATA_ALIGNMENT as well, except for strings. */ + /* ??? targetm.constant_alignment hasn't been updated for vector types on + most architectures so use DATA_ALIGNMENT as well, except for strings. */ if (TREE_CODE (exp) == STRING_CST) - { - SET_DECL_ALIGN (decl, CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl))); - } + SET_DECL_ALIGN (decl, targetm.constant_alignment (exp, DECL_ALIGN (decl))); else align_variable (decl, 0); @@ -3790,7 +3788,7 @@ force_const_mem (machine_mode mode, rtx x) tree type = lang_hooks.types.type_for_mode (mode, 0); if (type != NULL_TREE) - align = CONSTANT_ALIGNMENT (make_tree (type, x), align); + align = targetm.constant_alignment (make_tree (type, x), align); pool->offset += (align / BITS_PER_UNIT) - 1; pool->offset &= ~ ((align / BITS_PER_UNIT) - 1); -- 2.30.2