From: Antoni Boucher <[email protected]>
gcc/jit/ChangeLog:
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_35): New ABI tag.
* docs/topics/types.rst: Document gcc_jit_type_is_floating_point.
* libgccjit.cc (gcc_jit_type_is_floating_point): New function.
* libgccjit.h (gcc_jit_type_is_floating_point): New function.
* libgccjit.map: New function.
gcc/testsuite/ChangeLog:
* jit.dg/test-reflection.c: Add test for
gcc_jit_type_is_floating_point.
Co-authored-by: Robert Zakrzewski <[email protected]>
---
gcc/jit/docs/topics/compatibility.rst | 8 ++++
gcc/jit/docs/topics/types.rst | 12 +++++
gcc/jit/libgccjit.cc | 17 +++++++
gcc/jit/libgccjit.h | 6 +++
gcc/jit/libgccjit.map | 5 ++
gcc/testsuite/jit.dg/test-reflection.c | 63 ++++++++++++++++++++++++--
6 files changed, 108 insertions(+), 3 deletions(-)
diff --git a/gcc/jit/docs/topics/compatibility.rst
b/gcc/jit/docs/topics/compatibility.rst
index 1f8c4d9365ef..5ec452dc771e 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -481,3 +481,11 @@ information:
--------------------
``LIBGCCJIT_ABI_37`` covers the addition of
:func:`gcc_jit_context_new_array_type_u64`
+
+.. _LIBGCCJIT_ABI_38:
+
+``LIBGCCJIT_ABI_38``
+--------------------
+``LIBGCCJIT_ABI_38`` covers the addition of
+
+ * :func:`gcc_jit_type_is_floating_point`
diff --git a/gcc/jit/docs/topics/types.rst b/gcc/jit/docs/topics/types.rst
index ae4d7d4e2853..ab5477099f90 100644
--- a/gcc/jit/docs/topics/types.rst
+++ b/gcc/jit/docs/topics/types.rst
@@ -456,6 +456,18 @@ Reflection API
Return non-zero if the type is an integral.
+.. function:: int\
+ gcc_jit_type_is_floating_point (gcc_jit_type *type)
+
+ Return non-zero if the type is floating point.
+
+ This entrypoint was added in :ref:`LIBGCCJIT_ABI_35`; you can test for
+ its presence using
+
+ .. code-block:: c
+
+ #ifdef LIBGCCJIT_HAVE_gcc_jit_type_is_floating_point
+
.. function:: gcc_jit_type *\
gcc_jit_type_is_pointer (gcc_jit_type *type)
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 3fc96fb989a2..fa843bddd2ff 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -637,6 +637,23 @@ gcc_jit_type_is_integral (gcc_jit_type *type)
return type->is_int ();
}
+/* Public entrypoint. See description in libgccjit.h.
+
+ After error-checking, the real work is done by the
+ gcc::jit::recording::type::is_float method, in
+ jit-recording.cc. */
+
+int
+gcc_jit_type_is_floating_point (gcc_jit_type *type)
+{
+ RETURN_VAL_IF_FAIL (type, FALSE, NULL, NULL, "NULL type");
+
+ if (type->is_vector ())
+ return false;
+
+ return type->is_float ();
+}
+
/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 1cc5e6a9946c..99c2e8d5c890 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -2094,6 +2094,12 @@ gcc_jit_function_type_get_param_type
(gcc_jit_function_type *function_type,
extern int
gcc_jit_type_is_integral (gcc_jit_type *type);
+/* Return non-zero if the type is floating point. */
+extern int
+gcc_jit_type_is_floating_point (gcc_jit_type * type);
+
+#define LIBGCCJIT_HAVE_gcc_jit_type_is_floating_point
+
/* Return the type pointed by the pointer type or NULL if it's not a
* pointer. */
extern gcc_jit_type *
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index 4d767f4f75bc..2e0c76299402 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -344,3 +344,8 @@ LIBGCCJIT_ABI_37 {
global:
gcc_jit_context_new_array_type_u64;
} LIBGCCJIT_ABI_36;
+
+LIBGCCJIT_ABI_38 {
+ global:
+ gcc_jit_type_is_floating_point;
+} LIBGCCJIT_ABI_37;
diff --git a/gcc/testsuite/jit.dg/test-reflection.c
b/gcc/testsuite/jit.dg/test-reflection.c
index afa76ff81f6c..a8c5dea81a9d 100644
--- a/gcc/testsuite/jit.dg/test-reflection.c
+++ b/gcc/testsuite/jit.dg/test-reflection.c
@@ -24,15 +24,68 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE);
CHECK_VALUE (gcc_jit_function_get_return_type(builtin_sin), double_type);
CHECK (!gcc_jit_type_is_integral(double_type));
+ CHECK (gcc_jit_type_is_floating_point (double_type));
+
+ gcc_jit_type *float_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT);
+ CHECK (!gcc_jit_type_is_bool (float_type));
+ CHECK (!gcc_jit_type_is_integral (float_type));
+ CHECK (gcc_jit_type_is_floating_point (float_type));
+
+ gcc_jit_target_info *target_info = gcc_jit_context_get_target_info (ctxt);
+ if (target_info != NULL &&
+ gcc_jit_target_info_supports_target_dependent_type (target_info,
+ GCC_JIT_TYPE_FLOAT16))
+ {
+ gcc_jit_type *float16_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT16);
+ CHECK (!gcc_jit_type_is_bool (float16_type));
+ CHECK (!gcc_jit_type_is_integral (float16_type));
+ CHECK (gcc_jit_type_is_floating_point (float16_type));
+ }
+
+ if (target_info != NULL &&
+ gcc_jit_target_info_supports_target_dependent_type (target_info,
+ GCC_JIT_TYPE_FLOAT32))
+ {
+ gcc_jit_type *float32_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT32);
+ CHECK (!gcc_jit_type_is_bool (float32_type));
+ CHECK (!gcc_jit_type_is_integral (float32_type));
+ CHECK (gcc_jit_type_is_floating_point (float32_type));
+ }
+
+ if (target_info != NULL &&
+ gcc_jit_target_info_supports_target_dependent_type (target_info,
+ GCC_JIT_TYPE_FLOAT64))
+ {
+ gcc_jit_type *float64_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT64);
+ CHECK (!gcc_jit_type_is_bool (float64_type));
+ CHECK (!gcc_jit_type_is_integral (float64_type));
+ CHECK (gcc_jit_type_is_floating_point (float64_type));
+ }
+
+ if (target_info != NULL &&
+ gcc_jit_target_info_supports_target_dependent_type (target_info,
+ GCC_JIT_TYPE_FLOAT128))
+ {
+ gcc_jit_type *float128_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT128);
+ CHECK (!gcc_jit_type_is_bool (float128_type));
+ CHECK (!gcc_jit_type_is_integral (float128_type));
+ CHECK (gcc_jit_type_is_floating_point (float128_type));
+ }
gcc_jit_type *bool_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL);
- CHECK (gcc_jit_type_is_bool(bool_type));
- CHECK (!gcc_jit_type_is_integral(bool_type));
+ CHECK (gcc_jit_type_is_bool (bool_type));
+ CHECK (!gcc_jit_type_is_integral (bool_type));
+ CHECK (!gcc_jit_type_is_floating_point (bool_type));
gcc_jit_type *aligned_bool_type =
gcc_jit_type_get_aligned(gcc_jit_context_get_type (ctxt,
GCC_JIT_TYPE_BOOL), 8);
- CHECK (gcc_jit_type_is_bool(aligned_bool_type));
+ CHECK (gcc_jit_type_is_bool (aligned_bool_type));
CHECK (bool_type != aligned_bool_type);
CHECK_VALUE (gcc_jit_type_unqualified(aligned_bool_type), bool_type);
@@ -42,15 +95,19 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
gcc_jit_type *int64 =
gcc_jit_context_get_int_type(ctxt, 8, 1);
CHECK (gcc_jit_type_is_integral(int64));
+ CHECK (!gcc_jit_type_is_floating_point(int64));
gcc_jit_type *uint64 =
gcc_jit_context_get_int_type(ctxt, 8, 0);
CHECK (gcc_jit_type_is_integral(uint64));
+ CHECK (!gcc_jit_type_is_floating_point(uint64));
gcc_jit_type *int8 =
gcc_jit_context_get_int_type(ctxt, 1, 1);
CHECK (gcc_jit_type_is_integral(int8));
+ CHECK (!gcc_jit_type_is_floating_point(int8));
gcc_jit_type *uint8 =
gcc_jit_context_get_int_type(ctxt, 1, 0);
CHECK (gcc_jit_type_is_integral(uint8));
+ CHECK (!gcc_jit_type_is_floating_point(uint8));
CHECK (!gcc_jit_type_dyncast_vector(double_type));
gcc_jit_type *vec_type = gcc_jit_type_get_vector (double_type, 4);
--
2.54.0