Hi Richi,

on 2024/6/3 14:49, Richard Biener wrote:
> On Mon, Jun 3, 2024 at 5:02 AM Kewen Lin <li...@linux.ibm.com> wrote:
>>
>> Currently how we determine which mode will be used for a
>> floating point type is that for a given type precision
>> (size) call mode_for_size to get the first mode which has
>> this size in the specified class.  On Powerpc, we have
>> three modes (TF/KF/IF) having the same mode precision 128
>> (see[1]), so the processing forces us to have to place TF
>> at the first place, it would require us to make more
>> adjustment in some generic code to avoid some unexpected
>> mode conversions and it would be even worse if we get rid
>> of TF eventually one day.  And as Joseph pointed out in [2],
>> "floating types should have their mode, not a poorly
>> defined precision value", as Joseph and Richi suggested,
>> this patch is to introduce one hook mode_for_floating_type
>> which returns the corresponding mode for type float, double
>> or long double.  The default implementation returns SFmode
>> for float and DFmode for double or long double.  For ports
>> which need special treatment, there are some other patches
>> for their own port specific implementation (referring to
>> how {,LONG_}DOUBLE_TYPE_SIZE get used there).  For all
>> generic uses of {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE, depending
>> on the context, some of them are replaced with TYPE_PRECISION
>> of the according type node, some other are replaced with
>> GET_MODE_PRECISION on the mode from mode_for_floating_type.
>> This patch also poisons {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE,
>> so most defines of {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE in port
>> specific are removed, but there are still some which are
>> good to be kept for readability then they get renamed with
>> port specific prefix.
>>
>> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651017.html
>> [2] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
>>
>> gcc/ChangeLog:
>>
>>         * coretypes.h (enum tree_index): Forward declaration.
>>         * defaults.h (FLOAT_TYPE_SIZE): Remove.
>>         (DOUBLE_TYPE_SIZE): Likewise.
>>         (LONG_DOUBLE_TYPE_SIZE): Likewise.
>>         * doc/rtl.texi: Update document by replacing {FLOAT,DOUBLE}_TYPE_SIZE
>>         with C type {float,double}.
>>         * doc/tm.texi.in: Document new hook mode_for_floating_type, remove
>>         document entries for {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE and
>>         update document for WIDEST_HARDWARE_FP_SIZE.
>>         * doc/tm.texi: Regenerate.
>>         * emit-rtl.cc (init_emit_once): Replace DOUBLE_TYPE_SIZE by
>>         calling targetm.c.mode_for_floating_type with TI_DOUBLE_TYPE.
>>         * real.h (REAL_VALUE_TO_TARGET_LONG_DOUBLE): Use TYPE_PRECISION of
>>         long_double_type_node to replace LONG_DOUBLE_TYPE_SIZE.
>>         * system.h (FLOAT_TYPE_SIZE): Poison.
>>         (DOUBLE_TYPE_SIZE): Likewise.
>>         (LONG_DOUBLE_TYPE_SIZE): Likewise.
>>         * target.def (mode_for_floating_type): New hook.
>>         * targhooks.cc (default_mode_for_floating_type): New function.
>>         (default_scalar_mode_supported_p): Update macros
>>         {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE by calling
>>         targetm.c.mode_for_floating_type with
>>         TI_{FLOAT,DOUBLE,LONG_DOUBLE}_TYPE.
>>         * targhooks.h (default_mode_for_floating_type): New declaration.
>>         * tree-core.h (enum tree_index): Specify underlying type unsigned
>>         to sync with forward declaration in coretypes.h.
>>         (NUM_FLOATN_TYPES): Explicitly convert to int.
>>         (NUM_FLOATNX_TYPES): Likewise.
>>         (NUM_FLOATN_NX_TYPES): Likewise.
>>         * tree.cc (build_common_tree_nodes): Update macros
>>         {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE by calling
>>         targetm.c.mode_for_floating_type with
>>         TI_{FLOAT,DOUBLE,LONG_DOUBLE}_TYPE and set type mode accordingly.
>> ---
>>  gcc/coretypes.h    |  1 +
>>  gcc/defaults.h     | 12 ------------
>>  gcc/doc/rtl.texi   |  2 +-
>>  gcc/doc/tm.texi    | 33 +++++++++++++--------------------
>>  gcc/doc/tm.texi.in | 27 +++++++--------------------
>>  gcc/emit-rtl.cc    |  3 ++-
>>  gcc/real.h         |  7 ++++---
>>  gcc/system.h       |  3 ++-
>>  gcc/target.def     |  9 +++++++++
>>  gcc/targhooks.cc   | 18 +++++++++++++++---
>>  gcc/targhooks.h    |  1 +
>>  gcc/tree-core.h    | 13 +++++++------
>>  gcc/tree.cc        | 18 +++++++++++++++---
>>  13 files changed, 77 insertions(+), 70 deletions(-)
>>
>> diff --git a/gcc/coretypes.h b/gcc/coretypes.h
>> index 1ac6f0abea3..00c1c58bd8c 100644
>> --- a/gcc/coretypes.h
>> +++ b/gcc/coretypes.h
>> @@ -100,6 +100,7 @@ struct gimple;
>>  typedef gimple *gimple_seq;
>>  struct gimple_stmt_iterator;
>>  class code_helper;
>> +enum tree_index : unsigned;
>>
>>  /* Forward declare rtx_code, so that we can use it in target hooks without
>>     needing to pull in rtl.h.  */
>> diff --git a/gcc/defaults.h b/gcc/defaults.h
>> index 92f3e07f742..ac2d25852ab 100644
>> --- a/gcc/defaults.h
>> +++ b/gcc/defaults.h
>> @@ -513,18 +513,6 @@ see the files COPYING3 and COPYING.RUNTIME 
>> respectively.  If not, see
>>  #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
>>  #endif
>>
>> -#ifndef FLOAT_TYPE_SIZE
>> -#define FLOAT_TYPE_SIZE BITS_PER_WORD
>> -#endif
>> -
>> -#ifndef DOUBLE_TYPE_SIZE
>> -#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
>> -#endif
>> -
>> -#ifndef LONG_DOUBLE_TYPE_SIZE
>> -#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
>> -#endif
>> -
>>  #ifndef DECIMAL32_TYPE_SIZE
>>  #define DECIMAL32_TYPE_SIZE 32
>>  #endif
>> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
>> index aa10b5235b5..d85b6dcbf1a 100644
>> --- a/gcc/doc/rtl.texi
>> +++ b/gcc/doc/rtl.texi
>> @@ -1326,7 +1326,7 @@ whose size is @code{BITS_PER_WORD}, @code{SImode} on 
>> 32-bit machines.
>>
>>  The only modes which a machine description @i{must} support are
>>  @code{QImode}, and the modes corresponding to @code{BITS_PER_WORD},
>> -@code{FLOAT_TYPE_SIZE} and @code{DOUBLE_TYPE_SIZE}.
>> +C type @code{float} and C type type @code{double}.
> 
> type type

Oops, thanks for catching, will fix it.

> 
> OK with that fixed and no comments from others.

Thanks!

BR,
Kewen

Reply via email to