]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgccjit: Support more target builtin types
authorAntoni Boucher <bouanto@zoho.com>
Tue, 18 Mar 2025 16:51:23 +0000 (12:51 -0400)
committerAntoni Boucher <bouanto@zoho.com>
Mon, 20 Oct 2025 21:03:50 +0000 (17:03 -0400)
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.

gcc/jit/docs/topics/compatibility.rst
gcc/jit/docs/topics/contexts.rst
gcc/jit/dummy-frontend.cc
gcc/jit/jit-playback.h
gcc/jit/jit-recording.cc
gcc/jit/jit-recording.h
gcc/jit/libgccjit.cc
gcc/jit/libgccjit.exports
gcc/jit/libgccjit.h
gcc/jit/libgccjit.map

index 19be33eb4b50a135e0f1ea9f1aac8f35cc1c77be..9379b05049e1f4a44a0b9ce3d84e684c18129d84 100644 (file)
@@ -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`
index f821e9c01ac3ea0410546bbffbdc6aa4d57ab735..2229dc772f0c88e605654acb9e4e1e41f34d4fde 100644 (file)
@@ -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
 ***************
 
index 3ffca92903f0a24a8d95c9a5602a86e3c42f8eac..4db9bdbe413f86d071e9d23848b40135a001e5cf 100644 (file)
@@ -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;
index 07dab6fa3895395c02a75f3afb3fa113372fbcab..11bc27900e40586acf83d3b6129ab19754b86591 100644 (file)
@@ -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 ();
 
index 2f4ecc3182517a90fc0b097a70b10eca0f1b5cc4..6384565384bc2b1bbdbae5fe83d807265de8ffbc 100644 (file)
@@ -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.
 
index 4d41faa0446a9313412d28d3d274110483a8cc44..73a0b06634895305376ee866a952ab0e44d2ef28 100644 (file)
@@ -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
 
index 33369447074b973b9834c4ada64fa4a256d26b0c..886ca4d44b4985a0eb914f5fc7f707dd20a63db2 100644 (file)
@@ -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
index 26dc634a0e8f06caa43462d42dbef85d4f851b73..96ce697e609f6a619efc40e080ce1c6d329afcad 100644 (file)
@@ -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
index a585510079319764798d1b12e3ae00c3285b00b2..cf2b95134615ba99a61614ac7d0621486b93cad1 100644 (file)
@@ -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 */
index 4662ca4b3c02e1b9029d2b9f161fc3cdfc04a954..500eba9f6fb0bf85eaeff6fb41d3fb9030cad334 100644 (file)
@@ -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;