On Sun, 2024-06-02 at 22:01 -0500, Kewen Lin wrote:
> Joseph pointed out "floating types should have their mode,
> not a poorly defined precision value" in the discussion[1],
> as he and Richi suggested, the existing macros
> {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE will be replaced with a
> hook mode_for_floating_type.  Unlike the other FEs, for the
> uses in recording::memento_of_get_type::get_size, since
> {float,{,long_}double}_type_node haven't been initialized
> yet, this is to replace {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE
> with calling hook targetm.c.mode_for_floating_type.
> 
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
> 
> gcc/jit/ChangeLog:
> 
>         * jit-recording.cc
> (recording::memento_of_get_type::get_size): Update
>         macros {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE by calling
>         targetm.c.mode_for_floating_type with
>         TI_{FLOAT,DOUBLE,LONG_DOUBLE}_TYPE.
> ---
>  gcc/jit/jit-recording.cc | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
> index 68a2e860c1f..7719b898e57 100644
> --- a/gcc/jit/jit-recording.cc
> +++ b/gcc/jit/jit-recording.cc
> @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "tm.h"
> +#include "target.h"
>  #include "pretty-print.h"
>  #include "toplev.h"
>  
> @@ -2353,6 +2353,7 @@ size_t
>  recording::memento_of_get_type::get_size ()
>  {
>    int size;
> +  machine_mode m;
>    switch (m_kind)
>      {
>      case GCC_JIT_TYPE_VOID:
> @@ -2399,13 +2400,16 @@ recording::memento_of_get_type::get_size ()
>        size = 128;
>        break;
>      case GCC_JIT_TYPE_FLOAT:
> -      size = FLOAT_TYPE_SIZE;
> +      m = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
> +      size = GET_MODE_PRECISION (m).to_constant ();
>        break;
>      case GCC_JIT_TYPE_DOUBLE:
> -      size = DOUBLE_TYPE_SIZE;
> +      m = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
> +      size = GET_MODE_PRECISION (m).to_constant ();
>        break;
>      case GCC_JIT_TYPE_LONG_DOUBLE:
> -      size = LONG_DOUBLE_TYPE_SIZE;
> +      m = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
> +      size = GET_MODE_PRECISION (m).to_constant ();
>        break;
>      case GCC_JIT_TYPE_SIZE_T:
>        size = MAX_BITS_PER_WORD;

[CCing jit mailing list]

Thanks for the patch; sorry for the delay in responding.

Did your testing include jit?  Note that --enable-languages=all does
*not* include it (due to it needing --enable-host-shared).

The jit::recording code runs *very* early - before toplev::main.  For
example, a call to gcc_jit_type_get_size can trigger the above code
path before toplev::main has run.

target.h says each target should have a:

  struct gcc_target targetm = TARGET_INITIALIZER;

Has targetm.c.mode_for_floating_type been initialized enough by that
static initialization?  Could the mode_for_floating_type hook be
relying on some target-specific dynamic initialization that hasn't run
yet?  (e.g. taking account of command-line options?)

Dave

Reply via email to