https://gcc.gnu.org/g:123b6a239700dcc0106774bc6274990f96dad7dd
commit r17-1625-g123b6a239700dcc0106774bc6274990f96dad7dd Author: Antoni Boucher <[email protected]> Date: Fri Sep 5 10:32:40 2025 -0400 libgccjit: Add gcc_jit_type_is_floating_point gcc/jit/ChangeLog: * docs/topics/compatibility.rst (LIBGCCJIT_ABI_38): 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. * libgccjit.exports: 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]> Diff: --- gcc/jit/docs/topics/compatibility.rst | 8 +++++ gcc/jit/docs/topics/types.rst | 12 +++++++ gcc/jit/libgccjit.cc | 17 +++++++++ gcc/jit/libgccjit.exports | 3 ++ gcc/jit/libgccjit.h | 6 ++++ gcc/jit/libgccjit.map | 5 +++ gcc/testsuite/jit.dg/test-reflection.c | 63 ++++++++++++++++++++++++++++++++-- 7 files changed, 111 insertions(+), 3 deletions(-) diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index 6f85f51639bc..e4a231e7997f 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 f3b5b2945e53..f3e937c68987 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_38`; 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 ad4754713555..5a874fc4808a 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.exports b/gcc/jit/libgccjit.exports index 17864c7010b0..fae095192243 100644 --- a/gcc/jit/libgccjit.exports +++ b/gcc/jit/libgccjit.exports @@ -264,3 +264,6 @@ _gcc_jit_context_set_abort_on_unsupported_target_builtin # LIBGCCJIT_ABI_37 _gcc_jit_context_new_array_type_u64 + +# LIBGCCJIT_ABI_38 +_gcc_jit_type_is_floating_point diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index c749d2b8c028..2247c99deb4a 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 d4cb50d94861..78b6be9ff36a 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);
