Re: [PATCH] libgccjit: Add support for the type bfloat16

2024-02-21 Thread Antoni Boucher
Thanks for the review.
Here's the updated patch.

On Fri, 2023-12-01 at 12:45 -0500, David Malcolm wrote:
> On Thu, 2023-11-16 at 17:20 -0500, Antoni Boucher wrote:
> > I forgot to attach the patch.
> > 
> > On Thu, 2023-11-16 at 17:19 -0500, Antoni Boucher wrote:
> > > Hi.
> > > This patch adds the support for the type bfloat16 (bug 112574).
> > > 
> > > This was asked to be splitted from a another patch sent here:
> > > https://gcc.gnu.org/pipermail/jit/2023q1/001607.html
> > > 
> > > Thanks for the review.
> > 
> 
> Thanks for the patch.
> 
> > diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
> > index 18cc4da25b8..7e1c97a4638 100644
> > --- a/gcc/jit/jit-playback.cc
> > +++ b/gcc/jit/jit-playback.cc
> > @@ -280,6 +280,8 @@ get_tree_node_for_type (enum gcc_jit_types
> > type_)
> >  
> >  case GCC_JIT_TYPE_FLOAT:
> >    return float_type_node;
> > +    case GCC_JIT_TYPE_BFLOAT16:
> > +  return bfloat16_type_node;
> 
> The code to create bfloat16_type_node (in build_common_tree_nodes) is
> guarded by #ifdef HAVE_BFmode, so we should probably have a test for
> this in case GCC_JIT_TYPE_BFLOAT16 to at least add an error message
> when it's NULL_TREE, rather than silently returning NULL_TREE and
> crashing.
> 
> [...]
> 
> > diff --git a/gcc/testsuite/jit.dg/test-bfloat16.c
> > b/gcc/testsuite/jit.dg/test-bfloat16.c
> > new file mode 100644
> > index 000..6aed3920351
> > --- /dev/null
> > +++ b/gcc/testsuite/jit.dg/test-bfloat16.c
> > @@ -0,0 +1,37 @@
> > +/* { dg-do compile { target x86_64-*-* } } */
> > +
> > +#include 
> > +#include 
> > +
> > +#include "libgccjit.h"
> > +
> > +/* We don't want set_options() in harness.h to set -O3 so our
> > little local
> > +   is optimized away. */
> > +#define TEST_ESCHEWS_SET_OPTIONS
> > +static void set_options (gcc_jit_context *ctxt, const char *argv0)
> > +{
> > +}
> 
> 
> Please add a comment to all-non-failing-tests.h noting the exclusion
> of
> this test case from the array.
> 
> [...]
> 
> > diff --git a/gcc/testsuite/jit.dg/test-types.c
> > b/gcc/testsuite/jit.dg/test-types.c
> > index a01944e35fa..9e7c4f3e046 100644
> > --- a/gcc/testsuite/jit.dg/test-types.c
> > +++ b/gcc/testsuite/jit.dg/test-types.c
> > @@ -1,3 +1,4 @@
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -492,4 +493,5 @@ verify_code (gcc_jit_context *ctxt,
> > gcc_jit_result *result)
> >  
> >    CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
> >    CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
> > +  CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > (ctxt, GCC_JIT_TYPE_BFLOAT16)), sizeof (__bfloat16));
> 
> 
> This is only going to work on targets which #ifdef HAVE_BFmode, so
> this
> CHECK_VALUE needs to be conditionalized somehow, to avoid having
> this,
> test-combination, and test-threads from bailing out early on targets
> without BFmode.
> 
> Dave
> 

From 3b31bca3a1144a5fa4dc34e402ad3287ccca84dd Mon Sep 17 00:00:00 2001
From: Antoni Boucher 
Date: Thu, 16 Nov 2023 10:59:22 -0500
Subject: [PATCH] libgccjit: Add support for the type bfloat16

gcc/jit/ChangeLog:

	PR jit/112574
	* docs/topics/types.rst: Document GCC_JIT_TYPE_BFLOAT16.
	* jit-common.h: Update NUM_GCC_JIT_TYPES.
	* jit-playback.cc (get_tree_node_for_type): Support bfloat16.
	* jit-recording.cc (recording::memento_of_get_type::get_size,
	recording::memento_of_get_type::dereference,
	recording::memento_of_get_type::is_int,
	recording::memento_of_get_type::is_signed,
	recording::memento_of_get_type::is_float,
	recording::memento_of_get_type::is_bool): Support bfloat16.
	* libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BFLOAT16.

gcc/testsuite/ChangeLog:

	PR jit/112574
	* jit.dg/all-non-failing-tests.h: New test test-bfloat16.c.
	* jit.dg/test-types.c: Test GCC_JIT_TYPE_BFLOAT16.
	* jit.dg/test-bfloat16.c: New test.
---
 gcc/jit/docs/topics/types.rst|  2 ++
 gcc/jit/jit-common.h |  2 +-
 gcc/jit/jit-playback.cc  |  6 
 gcc/jit/jit-recording.cc | 11 ++
 gcc/jit/libgccjit.h  |  4 ++-
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  3 ++
 gcc/testsuite/jit.dg/test-bfloat16.c | 37 
 gcc/testsuite/jit.dg/test-types.c|  4 +++
 8 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/jit.dg/test-bfloat16.c

diff --git a/gcc/jit/docs/topics/types.rst b/gcc/jit/docs/topics/types.rst
index bb51f037b7e..6a7a35280ed 100644
--- a/gcc/jit/docs/topics/types.rst
+++ b/gcc/jit/docs/topics/types.rst
@@ -113,6 +113,8 @@ Standard types
- C99's ``__int128_t``
  * - :c:data:`GCC_JIT_TYPE_FLOAT`
-
+ * - :c:data:`GCC_JIT_TYPE_BFLOAT16`
+   - C's ``__bfloat16``
  * - :c:data:`GCC_JIT_TYPE_DOUBLE`
-
  * - 

Re: [PATCH] libgccjit: Add support for the type bfloat16

2023-12-01 Thread David Malcolm
On Thu, 2023-11-16 at 17:20 -0500, Antoni Boucher wrote:
> I forgot to attach the patch.
> 
> On Thu, 2023-11-16 at 17:19 -0500, Antoni Boucher wrote:
> > Hi.
> > This patch adds the support for the type bfloat16 (bug 112574).
> > 
> > This was asked to be splitted from a another patch sent here:
> > https://gcc.gnu.org/pipermail/jit/2023q1/001607.html
> > 
> > Thanks for the review.
> 

Thanks for the patch.

> diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
> index 18cc4da25b8..7e1c97a4638 100644
> --- a/gcc/jit/jit-playback.cc
> +++ b/gcc/jit/jit-playback.cc
> @@ -280,6 +280,8 @@ get_tree_node_for_type (enum gcc_jit_types type_)
>  
>  case GCC_JIT_TYPE_FLOAT:
>return float_type_node;
> +case GCC_JIT_TYPE_BFLOAT16:
> +  return bfloat16_type_node;

The code to create bfloat16_type_node (in build_common_tree_nodes) is
guarded by #ifdef HAVE_BFmode, so we should probably have a test for
this in case GCC_JIT_TYPE_BFLOAT16 to at least add an error message
when it's NULL_TREE, rather than silently returning NULL_TREE and
crashing.

[...]

> diff --git a/gcc/testsuite/jit.dg/test-bfloat16.c 
> b/gcc/testsuite/jit.dg/test-bfloat16.c
> new file mode 100644
> index 000..6aed3920351
> --- /dev/null
> +++ b/gcc/testsuite/jit.dg/test-bfloat16.c
> @@ -0,0 +1,37 @@
> +/* { dg-do compile { target x86_64-*-* } } */
> +
> +#include 
> +#include 
> +
> +#include "libgccjit.h"
> +
> +/* We don't want set_options() in harness.h to set -O3 so our little local
> +   is optimized away. */
> +#define TEST_ESCHEWS_SET_OPTIONS
> +static void set_options (gcc_jit_context *ctxt, const char *argv0)
> +{
> +}


Please add a comment to all-non-failing-tests.h noting the exclusion of
this test case from the array.

[...]

> diff --git a/gcc/testsuite/jit.dg/test-types.c 
> b/gcc/testsuite/jit.dg/test-types.c
> index a01944e35fa..9e7c4f3e046 100644
> --- a/gcc/testsuite/jit.dg/test-types.c
> +++ b/gcc/testsuite/jit.dg/test-types.c
> @@ -1,3 +1,4 @@
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -492,4 +493,5 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result 
> *result)
>  
>CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
> GCC_JIT_TYPE_FLOAT)), sizeof (float));
>CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
> GCC_JIT_TYPE_DOUBLE)), sizeof (double));
> +  CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
> GCC_JIT_TYPE_BFLOAT16)), sizeof (__bfloat16));


This is only going to work on targets which #ifdef HAVE_BFmode, so this
CHECK_VALUE needs to be conditionalized somehow, to avoid having this,
test-combination, and test-threads from bailing out early on targets
without BFmode.

Dave



Re: [PATCH] libgccjit: Add support for the type bfloat16

2023-12-01 Thread Antoni Boucher
David: ping.

On Thu, 2023-11-16 at 17:20 -0500, Antoni Boucher wrote:
> I forgot to attach the patch.
> 
> On Thu, 2023-11-16 at 17:19 -0500, Antoni Boucher wrote:
> > Hi.
> > This patch adds the support for the type bfloat16 (bug 112574).
> > 
> > This was asked to be splitted from a another patch sent here:
> > https://gcc.gnu.org/pipermail/jit/2023q1/001607.html
> > 
> > Thanks for the review.
> 



Re: [PATCH] libgccjit: Add support for the type bfloat16

2023-11-16 Thread Antoni Boucher
I forgot to attach the patch.

On Thu, 2023-11-16 at 17:19 -0500, Antoni Boucher wrote:
> Hi.
> This patch adds the support for the type bfloat16 (bug 112574).
> 
> This was asked to be splitted from a another patch sent here:
> https://gcc.gnu.org/pipermail/jit/2023q1/001607.html
> 
> Thanks for the review.

From 0e57583bba7e9fe5f5ff89559d4f29bf1bd7a240 Mon Sep 17 00:00:00 2001
From: Antoni Boucher 
Date: Thu, 16 Nov 2023 10:59:22 -0500
Subject: [PATCH] libgccjit: Add support for the type bfloat16

gcc/jit/ChangeLog:

	PR jit/112574
	* docs/topics/types.rst: Document GCC_JIT_TYPE_BFLOAT16.
	* jit-common.h: Update NUM_GCC_JIT_TYPES.
	* jit-playback.cc (get_tree_node_for_type): Support bfloat16.
	* jit-recording.cc (recording::memento_of_get_type::get_size,
	recording::memento_of_get_type::dereference,
	recording::memento_of_get_type::is_int,
	recording::memento_of_get_type::is_signed,
	recording::memento_of_get_type::is_float,
	recording::memento_of_get_type::is_bool): Support bfloat16.
	* libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BFLOAT16.

gcc/testsuite/ChangeLog:

	PR jit/112574
	* jit.dg/test-types.c: Test GCC_JIT_TYPE_BFLOAT16.
	* jit.dg/test-bfloat16.c: New test.
---
 gcc/jit/docs/topics/types.rst|  2 ++
 gcc/jit/jit-common.h |  2 +-
 gcc/jit/jit-playback.cc  |  2 ++
 gcc/jit/jit-recording.cc | 11 +
 gcc/jit/libgccjit.h  |  4 ++-
 gcc/testsuite/jit.dg/test-bfloat16.c | 37 
 gcc/testsuite/jit.dg/test-types.c|  2 ++
 7 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/jit.dg/test-bfloat16.c

diff --git a/gcc/jit/docs/topics/types.rst b/gcc/jit/docs/topics/types.rst
index d8c1d15d69d..1ae814a349d 100644
--- a/gcc/jit/docs/topics/types.rst
+++ b/gcc/jit/docs/topics/types.rst
@@ -113,6 +113,8 @@ Standard types
- C99's ``__int128_t``
  * - :c:data:`GCC_JIT_TYPE_FLOAT`
-
+ * - :c:data:`GCC_JIT_TYPE_BFLOAT16`
+   - C's ``__bfloat16``
  * - :c:data:`GCC_JIT_TYPE_DOUBLE`
-
  * - :c:data:`GCC_JIT_TYPE_LONG_DOUBLE`
diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index 80c1618da96..983c9190d44 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -36,7 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 #endif
 
-const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_INT128_T + 1;
+const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_BFLOAT16 + 1;
 
 /* This comment is included by the docs.
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 18cc4da25b8..7e1c97a4638 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -280,6 +280,8 @@ get_tree_node_for_type (enum gcc_jit_types type_)
 
 case GCC_JIT_TYPE_FLOAT:
   return float_type_node;
+case GCC_JIT_TYPE_BFLOAT16:
+  return bfloat16_type_node;
 case GCC_JIT_TYPE_DOUBLE:
   return double_type_node;
 case GCC_JIT_TYPE_LONG_DOUBLE:
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 9b5b8005ebe..af8b7a421ec 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -2385,6 +2385,10 @@ recording::memento_of_get_type::get_size ()
 case GCC_JIT_TYPE_FLOAT:
   size = FLOAT_TYPE_SIZE;
   break;
+#ifdef HAVE_BFmode
+case GCC_JIT_TYPE_BFLOAT16:
+  return GET_MODE_UNIT_SIZE (BFmode);
+#endif
 case GCC_JIT_TYPE_DOUBLE:
   size = DOUBLE_TYPE_SIZE;
   break;
@@ -2444,6 +2448,7 @@ recording::memento_of_get_type::dereference ()
 case GCC_JIT_TYPE_INT64_T:
 case GCC_JIT_TYPE_INT128_T:
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
 case GCC_JIT_TYPE_COMPLEX_FLOAT:
@@ -2508,6 +2513,7 @@ recording::memento_of_get_type::is_int () const
   return true;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
   return false;
@@ -2566,6 +2572,7 @@ recording::memento_of_get_type::is_signed () const
 case GCC_JIT_TYPE_UINT128_T:
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
 
@@ -2625,6 +2632,7 @@ recording::memento_of_get_type::is_float () const
   return false;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
   return true;
@@ -2688,6 +2696,7 @@ recording::memento_of_get_type::is_bool () const
   return false;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
   return false;
@@ -2768,6 +2777,7 @@ static const char * const get_type_strings[] = {
   "__int64_t",/* GCC_JIT_TYPE_INT64_T */
   "__int128_t",   /* GCC_JIT_TYPE_INT128_T */
 
+  "bfloat16", /* GCC_JIT_TYPE_BFLOAT16 */
 };
 
 /* Implementation of