diff mbox series

[49/52] mips: New hook implementation mips_c_mode_for_floating_type

Message ID 77176b03e00ebd29d71e339ade21bb50811d8d5f.1717134752.git.linkw@linux.ibm.com
State New
Headers show
Series Replace {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE with new hook | expand

Commit Message

Kewen.Lin June 3, 2024, 3:01 a.m. UTC
This is to add new port specific hook implementation
mips_c_mode_for_floating_type, remove macros FLOAT_TYPE_SIZE
and DOUBLE_TYPE_SIZE, rename LONG_DOUBLE_TYPE_SIZE to
MIPS_LONG_DOUBLE_TYPE_SIZE since we poison LONG_DOUBLE_TYPE_SIZE
but some subtarget wants to redefine it and some macro defines
need it.

gcc/ChangeLog:

	* config/mips/mips.cc (mips_c_mode_for_floating_type): New function.
	(TARGET_C_MODE_FOR_FLOATING_TYPE): New macro.
	* config/mips/mips.h (UNITS_PER_FPVALUE): Replace LONG_DOUBLE_TYPE_SIZE
	with MIPS_LONG_DOUBLE_TYPE_SIZE.
	(MAX_FIXED_MODE_SIZE): Likewise.
	(STRUCTURE_SIZE_BOUNDARY): Likewise.
	(BIGGEST_ALIGNMENT): Likewise.
	(FLOAT_TYPE_SIZE): Remove.
	(DOUBLE_TYPE_SIZE): Remove.
	(LONG_DOUBLE_TYPE_SIZE): Rename to ...
	(MIPS_LONG_DOUBLE_TYPE_SIZE): ... this.
	* config/mips/n32-elf.h (LONG_DOUBLE_TYPE_SIZE): Rename to ...
	(MIPS_LONG_DOUBLE_TYPE_SIZE): ... this.
---
 gcc/config/mips/mips.cc   | 14 ++++++++++++++
 gcc/config/mips/mips.h    | 13 ++++++-------
 gcc/config/mips/n32-elf.h |  4 ++--
 3 files changed, 22 insertions(+), 9 deletions(-)

Comments

YunQiang Su June 4, 2024, 1:16 a.m. UTC | #1
Kewen Lin <linkw@linux.ibm.com> 于2024年6月3日周一 11:03写道:
>
> This is to add new port specific hook implementation
> mips_c_mode_for_floating_type, remove macros FLOAT_TYPE_SIZE
> and DOUBLE_TYPE_SIZE, rename LONG_DOUBLE_TYPE_SIZE to
> MIPS_LONG_DOUBLE_TYPE_SIZE since we poison LONG_DOUBLE_TYPE_SIZE
> but some subtarget wants to redefine it and some macro defines
> need it.
>

Good for me if the framework is approved.

> gcc/ChangeLog:
>
>         * config/mips/mips.cc (mips_c_mode_for_floating_type): New function.
>         (TARGET_C_MODE_FOR_FLOATING_TYPE): New macro.
>         * config/mips/mips.h (UNITS_PER_FPVALUE): Replace LONG_DOUBLE_TYPE_SIZE
>         with MIPS_LONG_DOUBLE_TYPE_SIZE.
>         (MAX_FIXED_MODE_SIZE): Likewise.
>         (STRUCTURE_SIZE_BOUNDARY): Likewise.
>         (BIGGEST_ALIGNMENT): Likewise.
>         (FLOAT_TYPE_SIZE): Remove.
>         (DOUBLE_TYPE_SIZE): Remove.
>         (LONG_DOUBLE_TYPE_SIZE): Rename to ...
>         (MIPS_LONG_DOUBLE_TYPE_SIZE): ... this.
>         * config/mips/n32-elf.h (LONG_DOUBLE_TYPE_SIZE): Rename to ...
>         (MIPS_LONG_DOUBLE_TYPE_SIZE): ... this.
> ---
>  gcc/config/mips/mips.cc   | 14 ++++++++++++++
>  gcc/config/mips/mips.h    | 13 ++++++-------
>  gcc/config/mips/n32-elf.h |  4 ++--
>  3 files changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
> index b63d40a357b..3e5035a385c 100644
> --- a/gcc/config/mips/mips.cc
> +++ b/gcc/config/mips/mips.cc
> @@ -22972,6 +22972,18 @@ mips_asm_file_end (void)
>      file_end_indicate_exec_stack ();
>  }
>
> +/* Implement TARGET_C_MODE_FOR_FLOATING_TYPE.  Return TFmode or DFmode
> +   for TI_LONG_DOUBLE_TYPE which is for long double type, go with the
> +   default one for the others.  */
> +
> +static machine_mode
> +mips_c_mode_for_floating_type (enum tree_index ti)
> +{
> +  if (ti == TI_LONG_DOUBLE_TYPE)
> +    return MIPS_LONG_DOUBLE_TYPE_SIZE == 64 ? DFmode : TFmode;
> +  return default_mode_for_floating_type (ti);
> +}
> +
>  void
>  mips_bit_clear_info (enum machine_mode mode, unsigned HOST_WIDE_INT m,
>                       int *start_pos, int *size)
> @@ -23340,6 +23352,8 @@ mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m)
>  #undef TARGET_ASM_FILE_END
>  #define TARGET_ASM_FILE_END mips_asm_file_end
>
> +#undef TARGET_C_MODE_FOR_FLOATING_TYPE
> +#define TARGET_C_MODE_FOR_FLOATING_TYPE mips_c_mode_for_floating_type
>
>  struct gcc_target targetm = TARGET_INITIALIZER;
>
> diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
> index 9d965966f2f..7a9b18c8096 100644
> --- a/gcc/config/mips/mips.h
> +++ b/gcc/config/mips/mips.h
> @@ -1654,7 +1654,7 @@ FP_ASM_SPEC "\
>  #define UNITS_PER_FPVALUE                      \
>    (TARGET_SOFT_FLOAT_ABI ? 0                   \
>     : TARGET_SINGLE_FLOAT ? UNITS_PER_FPREG     \
> -   : LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
> +   : MIPS_LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
>
>  /* The number of bytes in a double.  */
>  #define UNITS_PER_DOUBLE (TYPE_PRECISION (double_type_node) / BITS_PER_UNIT)
> @@ -1665,9 +1665,8 @@ FP_ASM_SPEC "\
>  #define LONG_TYPE_SIZE (TARGET_LONG64 ? 64 : 32)
>  #define LONG_LONG_TYPE_SIZE 64
>
> -#define FLOAT_TYPE_SIZE 32
> -#define DOUBLE_TYPE_SIZE 64
> -#define LONG_DOUBLE_TYPE_SIZE (TARGET_NEWABI ? 128 : 64)
> +/* LONG_DOUBLE_TYPE_SIZE gets poisoned, so add MIPS_ prefix.  */
> +#define MIPS_LONG_DOUBLE_TYPE_SIZE (TARGET_NEWABI ? 128 : 64)
>
>  /* Define the sizes of fixed-point types.  */
>  #define SHORT_FRACT_TYPE_SIZE 8
> @@ -1684,7 +1683,7 @@ FP_ASM_SPEC "\
>
>  /* long double is not a fixed mode, but the idea is that, if we
>     support long double, we also want a 128-bit integer type.  */
> -#define MAX_FIXED_MODE_SIZE LONG_DOUBLE_TYPE_SIZE
> +#define MAX_FIXED_MODE_SIZE MIPS_LONG_DOUBLE_TYPE_SIZE
>
>  /* Width in bits of a pointer.  */
>  #ifndef POINTER_SIZE
> @@ -1705,10 +1704,10 @@ FP_ASM_SPEC "\
>  #define STRUCTURE_SIZE_BOUNDARY 8
>
>  /* There is no point aligning anything to a rounder boundary than
> -   LONG_DOUBLE_TYPE_SIZE, unless under MSA the bigggest alignment is
> +   MIPS_LONG_DOUBLE_TYPE_SIZE, unless under MSA the bigggest alignment is
>     BITS_PER_MSA_REG.  */
>  #define BIGGEST_ALIGNMENT \
> -  (ISA_HAS_MSA ? BITS_PER_MSA_REG : LONG_DOUBLE_TYPE_SIZE)
> +  (ISA_HAS_MSA ? BITS_PER_MSA_REG : MIPS_LONG_DOUBLE_TYPE_SIZE)
>
>  /* All accesses must be aligned.  */
>  #define STRICT_ALIGNMENT (!ISA_HAS_UNALIGNED_ACCESS)
> diff --git a/gcc/config/mips/n32-elf.h b/gcc/config/mips/n32-elf.h
> index 94a90d847f0..01c8a852539 100644
> --- a/gcc/config/mips/n32-elf.h
> +++ b/gcc/config/mips/n32-elf.h
> @@ -26,5 +26,5 @@ along with GCC; see the file COPYING3.  If not see
>  #define NO_DOLLAR_IN_LABEL
>
>  /* Force n32 to use 64-bit long doubles.  */
> -#undef LONG_DOUBLE_TYPE_SIZE
> -#define LONG_DOUBLE_TYPE_SIZE 64
> +#undef MIPS_LONG_DOUBLE_TYPE_SIZE
> +#define MIPS_LONG_DOUBLE_TYPE_SIZE 64
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index b63d40a357b..3e5035a385c 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -22972,6 +22972,18 @@  mips_asm_file_end (void)
     file_end_indicate_exec_stack ();
 }
 
+/* Implement TARGET_C_MODE_FOR_FLOATING_TYPE.  Return TFmode or DFmode
+   for TI_LONG_DOUBLE_TYPE which is for long double type, go with the
+   default one for the others.  */
+
+static machine_mode
+mips_c_mode_for_floating_type (enum tree_index ti)
+{
+  if (ti == TI_LONG_DOUBLE_TYPE)
+    return MIPS_LONG_DOUBLE_TYPE_SIZE == 64 ? DFmode : TFmode;
+  return default_mode_for_floating_type (ti);
+}
+
 void
 mips_bit_clear_info (enum machine_mode mode, unsigned HOST_WIDE_INT m,
 		      int *start_pos, int *size)
@@ -23340,6 +23352,8 @@  mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m)
 #undef TARGET_ASM_FILE_END
 #define TARGET_ASM_FILE_END mips_asm_file_end
 
+#undef TARGET_C_MODE_FOR_FLOATING_TYPE
+#define TARGET_C_MODE_FOR_FLOATING_TYPE mips_c_mode_for_floating_type
 
 struct gcc_target targetm = TARGET_INITIALIZER;
 
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index 9d965966f2f..7a9b18c8096 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -1654,7 +1654,7 @@  FP_ASM_SPEC "\
 #define UNITS_PER_FPVALUE			\
   (TARGET_SOFT_FLOAT_ABI ? 0			\
    : TARGET_SINGLE_FLOAT ? UNITS_PER_FPREG	\
-   : LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
+   : MIPS_LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
 
 /* The number of bytes in a double.  */
 #define UNITS_PER_DOUBLE (TYPE_PRECISION (double_type_node) / BITS_PER_UNIT)
@@ -1665,9 +1665,8 @@  FP_ASM_SPEC "\
 #define LONG_TYPE_SIZE (TARGET_LONG64 ? 64 : 32)
 #define LONG_LONG_TYPE_SIZE 64
 
-#define FLOAT_TYPE_SIZE 32
-#define DOUBLE_TYPE_SIZE 64
-#define LONG_DOUBLE_TYPE_SIZE (TARGET_NEWABI ? 128 : 64)
+/* LONG_DOUBLE_TYPE_SIZE gets poisoned, so add MIPS_ prefix.  */
+#define MIPS_LONG_DOUBLE_TYPE_SIZE (TARGET_NEWABI ? 128 : 64)
 
 /* Define the sizes of fixed-point types.  */
 #define SHORT_FRACT_TYPE_SIZE 8
@@ -1684,7 +1683,7 @@  FP_ASM_SPEC "\
 
 /* long double is not a fixed mode, but the idea is that, if we
    support long double, we also want a 128-bit integer type.  */
-#define MAX_FIXED_MODE_SIZE LONG_DOUBLE_TYPE_SIZE
+#define MAX_FIXED_MODE_SIZE MIPS_LONG_DOUBLE_TYPE_SIZE
 
 /* Width in bits of a pointer.  */
 #ifndef POINTER_SIZE
@@ -1705,10 +1704,10 @@  FP_ASM_SPEC "\
 #define STRUCTURE_SIZE_BOUNDARY 8
 
 /* There is no point aligning anything to a rounder boundary than
-   LONG_DOUBLE_TYPE_SIZE, unless under MSA the bigggest alignment is
+   MIPS_LONG_DOUBLE_TYPE_SIZE, unless under MSA the bigggest alignment is
    BITS_PER_MSA_REG.  */
 #define BIGGEST_ALIGNMENT \
-  (ISA_HAS_MSA ? BITS_PER_MSA_REG : LONG_DOUBLE_TYPE_SIZE)
+  (ISA_HAS_MSA ? BITS_PER_MSA_REG : MIPS_LONG_DOUBLE_TYPE_SIZE)
 
 /* All accesses must be aligned.  */
 #define STRICT_ALIGNMENT (!ISA_HAS_UNALIGNED_ACCESS)
diff --git a/gcc/config/mips/n32-elf.h b/gcc/config/mips/n32-elf.h
index 94a90d847f0..01c8a852539 100644
--- a/gcc/config/mips/n32-elf.h
+++ b/gcc/config/mips/n32-elf.h
@@ -26,5 +26,5 @@  along with GCC; see the file COPYING3.  If not see
 #define NO_DOLLAR_IN_LABEL
 
 /* Force n32 to use 64-bit long doubles.  */
-#undef LONG_DOUBLE_TYPE_SIZE
-#define LONG_DOUBLE_TYPE_SIZE 64
+#undef MIPS_LONG_DOUBLE_TYPE_SIZE
+#define MIPS_LONG_DOUBLE_TYPE_SIZE 64