From: Antoni Boucher Date: Tue, 18 Mar 2025 16:51:23 +0000 (-0400) Subject: libgccjit: Support more target builtin types X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=760e281917fd808a1dfb387b3413b667cd0c65ae;p=thirdparty%2Fgcc.git libgccjit: Support more target builtin types This also adds option to abort on unsupported type in order to be able to detect new unsupported types more easily. gcc/jit/ChangeLog: PR jit/117886 * dummy-frontend.cc: Support some missing types. * jit-playback.h (get_abort_on_unsupported_target_builtin): New function. * jit-recording.cc (get_abort_on_unsupported_target_builtin, set_abort_on_unsupported_target_builtin): New functions. * jit-recording.h (get_abort_on_unsupported_target_builtin, set_abort_on_unsupported_target_builtin): New functions. (m_abort_on_unsupported_target_builtin): New field. * libgccjit.cc (gcc_jit_context_set_abort_on_unsupported_target_builtin): New function. * libgccjit.h (gcc_jit_context_set_abort_on_unsupported_target_builtin): New function. * libgccjit.exports (LIBGCCJIT_ABI_36): New ABI tag. * libgccjit.map (LIBGCCJIT_ABI_36): New ABI tag. * docs/topics/compatibility.rst (LIBGCCJIT_ABI_36): New ABI tag. * docs/topics/contexts.rst: Document new function. --- diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index 19be33eb4b5..9379b05049e 100644 --- a/gcc/jit/docs/topics/compatibility.rst +++ b/gcc/jit/docs/topics/compatibility.rst @@ -466,3 +466,11 @@ information: * :func:`gcc_jit_target_info_cpu_supports` * :func:`gcc_jit_target_info_arch` * :func:`gcc_jit_target_info_supports_target_dependent_type` + +.. _LIBGCCJIT_ABI_36: + +``LIBGCCJIT_ABI_36`` +-------------------- +``LIBGCCJIT_ABI_36`` covers the addition of + + * :func:`gcc_jit_context_set_abort_on_unsupported_target_builtin` diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst index f821e9c01ac..2229dc772f0 100644 --- a/gcc/jit/docs/topics/contexts.rst +++ b/gcc/jit/docs/topics/contexts.rst @@ -509,6 +509,22 @@ Boolean options #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr +.. function:: void \ + gcc_jit_context_set_abort_on_unsupported_target_builtin (gcc_jit_context *ctxt) + + By default, libgccjit will silently ignore when a target builtin has an + unsupported type. + + This entrypoint can be used to make it abort when the specified context + encounters such a target builtin. + + This entrypoint was added in :ref:`LIBGCCJIT_ABI_36`; you can test for + its presence using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_abort_on_unsupported_target_builtin + Integer options *************** diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc index 3ffca92903f..4db9bdbe413 100644 --- a/gcc/jit/dummy-frontend.cc +++ b/gcc/jit/dummy-frontend.cc @@ -1170,6 +1170,9 @@ jit_langhook_type_for_mode (machine_mode mode, int unsignedp) recording::type* tree_type_to_jit_type (tree type) { + gcc_assert (gcc::jit::active_playback_ctxt); + gcc::jit::playback::context* ctxt = gcc::jit::active_playback_ctxt; + if (TREE_CODE (type) == VECTOR_TYPE) { tree inner_type = TREE_TYPE (type); @@ -1282,6 +1285,39 @@ recording::type* tree_type_to_jit_type (tree type) return nullptr; return element_type->get_pointer (); } + else if (type == unsigned_intTI_type_node) + return new recording::memento_of_get_type (&target_builtins_ctxt, + GCC_JIT_TYPE_UINT128_T); + else if (INTEGRAL_TYPE_P (type)) + { + unsigned int size = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + return target_builtins_ctxt.get_int_type (size, TYPE_UNSIGNED (type)); + } + else if (SCALAR_FLOAT_TYPE_P (type)) + { + unsigned int size = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + enum gcc_jit_types type; + switch (size) + { + case 2: + type = GCC_JIT_TYPE_BFLOAT16; + break; + case 4: + type = GCC_JIT_TYPE_FLOAT; + break; + case 8: + type = GCC_JIT_TYPE_DOUBLE; + break; + default: + if (ctxt->get_abort_on_unsupported_target_builtin ()) + { + fprintf (stderr, "Unexpected float size: %d\n", size); + abort (); + } + return NULL; + } + return new recording::memento_of_get_type (&target_builtins_ctxt, type); + } else { // Attempt to find an unqualified type when the current type has qualifiers. @@ -1301,6 +1337,13 @@ recording::type* tree_type_to_jit_type (tree type) } } } + + if (ctxt->get_abort_on_unsupported_target_builtin ()) + { + fprintf (stderr, "Unknown type:\n"); + debug_tree (type); + abort (); + } } return NULL; diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 07dab6fa389..11bc27900e4 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -340,6 +340,11 @@ public: return info; } + bool get_abort_on_unsupported_target_builtin () const + { + return m_recording_ctxt->get_abort_on_unsupported_target_builtin (); + } + private: void dump_generated_code (); diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 2f4ecc31825..6384565384b 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -1498,6 +1498,18 @@ recording::context::set_output_ident (const char *ident) record (memento); } +bool +recording::context::get_abort_on_unsupported_target_builtin () +{ + return m_abort_on_unsupported_target_builtin; +} + +void +recording::context::set_abort_on_unsupported_target_builtin () +{ + m_abort_on_unsupported_target_builtin = true; +} + /* Set the given integer option for this context, or add an error if it's not recognized. diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 4d41faa0446..73a0b066348 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -270,6 +270,12 @@ public: void set_output_ident (const char *output_ident); + bool + get_abort_on_unsupported_target_builtin (); + + void + set_abort_on_unsupported_target_builtin (); + void set_int_option (enum gcc_jit_int_option opt, int value); @@ -424,6 +430,7 @@ private: type *m_FILE_type; bool m_populated_target_info = false; + bool m_abort_on_unsupported_target_builtin = false; builtins_manager *m_builtins_manager; // lazily created diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 33369447074..886ca4d44b4 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -3951,6 +3951,14 @@ gcc_jit_target_info_supports_target_dependent_type (gcc_jit_target_info *info, != info->m_supported_target_dependent_types.end (); } +void +gcc_jit_context_set_abort_on_unsupported_target_builtin (gcc_jit_context *ctxt) +{ + RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); + + ctxt->set_abort_on_unsupported_target_builtin (); +} + /* 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 26dc634a0e8..96ce697e609 100644 --- a/gcc/jit/libgccjit.exports +++ b/gcc/jit/libgccjit.exports @@ -239,16 +239,25 @@ _gcc_jit_global_set_readonly # LIBGCCJIT_ABI_30 _gcc_jit_context_convert_vector -# LIBGCCJIT_ABI_31 +# LIBGCCJIT_ABI_31 _gcc_jit_context_new_vector_access _gcc_jit_context_new_rvalue_vector_perm -# LIBGCCJIT_ABI_32 +# LIBGCCJIT_ABI_32 _gcc_jit_context_get_target_builtin_function -# LIBGCCJIT_ABI_33 +# LIBGCCJIT_ABI_33 _gcc_jit_function_new_temp -# LIBGCCJIT_ABI_34 +# LIBGCCJIT_ABI_34 _gcc_jit_context_set_output_ident +# LIBGCCJIT_ABI_35 +_gcc_jit_context_get_target_info +_gcc_jit_target_info_release +_gcc_jit_target_info_cpu_supports +_gcc_jit_target_info_arch +_gcc_jit_target_info_supports_target_dependent_type + +# LIBGCCJIT_ABI_36 +_gcc_jit_context_set_abort_on_unsupported_target_builtin diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index a5855100793..cf2b9513461 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -2216,6 +2216,11 @@ gcc_jit_context_set_output_ident (gcc_jit_context *ctxt, #define LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident +extern void +gcc_jit_context_set_abort_on_unsupported_target_builtin (gcc_jit_context *ctxt); + +#define LIBGCCJIT_HAVE_gcc_jit_context_set_abort_on_unsupported_target_builtin + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index 4662ca4b3c0..500eba9f6fb 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -334,3 +334,8 @@ LIBGCCJIT_ABI_35 { gcc_jit_target_info_arch; gcc_jit_target_info_supports_target_dependent_type; } LIBGCCJIT_ABI_34; + +LIBGCCJIT_ABI_36 { + global: + gcc_jit_context_set_abort_on_unsupported_target_builtin; +} LIBGCCJIT_ABI_35;