public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libgccjit: Add support for types used by atomic builtins [PR96066] [PR96067]
@ 2021-05-18  1:02 Antoni Boucher
  2021-05-20 20:24 ` David Malcolm
  0 siblings, 1 reply; 8+ messages in thread
From: Antoni Boucher @ 2021-05-18  1:02 UTC (permalink / raw)
  To: jit, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 96 bytes --]

Hello.
This patch fixes the issue with using atomic builtins in libgccjit.
Thanks to review it.

[-- Attachment #2: 0001-Add-support-for-types-used-by-atomic-builtins-PR9606.patch --]
[-- Type: text/x-patch, Size: 5064 bytes --]

From 0ce53d373ffba9f3f80a2d2b4e1a7d724ba31b7d Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Sun, 9 May 2021 20:14:37 -0400
Subject: [PATCH] Add support for types used by atomic builtins [PR96066]
 [PR96067]

2021-05-17  Antoni Boucher  <bouanto@zoho.com>

    gcc/jit/
            PR target/PR96066
            PR target/PR96067
            * jit-builtins.c: Implement missing types for builtins.
            * jit-recording.c:: Allow sending a volatile const void * as
            argument.
    gcc/testsuite/
            PR target/PR96066
            PR target/PR96067
            * jit.dg/all-non-failing-tests.h: Add test-builtin-types.c.
            * jit.dg/test-builtin-types.c
---
 gcc/jit/jit-builtins.c                       | 10 ++---
 gcc/jit/jit-recording.c                      | 14 ++++++-
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  7 ++++
 gcc/testsuite/jit.dg/test-builtin-types.c    | 41 ++++++++++++++++++++
 4 files changed, 65 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/jit.dg/test-builtin-types.c

diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
index 1ea96f4e025..c279dd858f9 100644
--- a/gcc/jit/jit-builtins.c
+++ b/gcc/jit/jit-builtins.c
@@ -541,11 +541,11 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id)
     // case BT_DFLOAT128:
     // case BT_VALIST_REF:
     // case BT_VALIST_ARG:
-    // case BT_I1:
-    // case BT_I2:
-    // case BT_I4:
-    // case BT_I8:
-    // case BT_I16:
+    case BT_I1: return m_ctxt->get_int_type (1, true);
+    case BT_I2: return m_ctxt->get_int_type (2, true);
+    case BT_I4: return m_ctxt->get_int_type (4, true);
+    case BT_I8: return m_ctxt->get_int_type (8, true);
+    case BT_I16: return m_ctxt->get_int_type (16, true);
     // case BT_PTR_CONST_STRING:
     }
 }
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index 117ff70114c..de876ff9fa6 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -2598,8 +2598,18 @@ recording::memento_of_get_pointer::accepts_writes_from (type *rtype)
     return false;
 
   /* It's OK to assign to a (const T *) from a (T *).  */
-  return m_other_type->unqualified ()
-    ->accepts_writes_from (rtype_points_to);
+  if (m_other_type->unqualified ()
+    ->accepts_writes_from (rtype_points_to)) {
+      return true;
+  }
+
+  /* It's OK to assign to a (volatile const T *) from a (volatile const T *). */
+  if (m_other_type->unqualified ()->unqualified ()
+    ->accepts_writes_from (rtype_points_to->unqualified ())) {
+      return true;
+  }
+
+  return false;
 }
 
 /* Implementation of pure virtual hook recording::memento::replay_into
diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h
index 4202eb7798b..dfc6596358c 100644
--- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
+++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
@@ -181,6 +181,13 @@
 #undef create_code
 #undef verify_code
 
+/* test-builtin-types.c */
+#define create_code create_code_builtin_types
+#define verify_code verify_code_builtin_types
+#include "test-builtin-types.c"
+#undef create_code
+#undef verify_code
+
 /* test-hello-world.c */
 #define create_code create_code_hello_world
 #define verify_code verify_code_hello_world
diff --git a/gcc/testsuite/jit.dg/test-builtin-types.c b/gcc/testsuite/jit.dg/test-builtin-types.c
new file mode 100644
index 00000000000..e20d71571b5
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-builtin-types.c
@@ -0,0 +1,41 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  CHECK_NON_NULL (gcc_jit_context_get_builtin_function (ctxt, "__atomic_fetch_add_4"));
+
+  gcc_jit_function *atomic_load = gcc_jit_context_get_builtin_function (ctxt, "__atomic_load_8");
+
+  gcc_jit_type *volatile_void_ptr =
+    gcc_jit_type_get_volatile(gcc_jit_type_get_const(gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR)));
+  gcc_jit_type *void_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+  gcc_jit_type *long_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+  gcc_jit_type *int_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+  gcc_jit_function *func =
+    gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED, void_type, "atomics", 0, NULL, 0);
+
+  gcc_jit_lvalue *variable = gcc_jit_function_new_local (func, NULL, long_type, "variable");
+  gcc_jit_rvalue *builtin_args[2];
+  gcc_jit_rvalue *param1 = gcc_jit_lvalue_get_address(variable, NULL);
+  builtin_args[0] = gcc_jit_context_new_cast(ctxt, NULL, param1, volatile_void_ptr);
+  builtin_args[1] = gcc_jit_context_new_rvalue_from_long(ctxt, int_type, 0);
+  gcc_jit_context_new_call (ctxt, NULL, atomic_load, 2, builtin_args);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  /* Verify that no errors were emitted.  */
+  CHECK_NON_NULL (result);
+}
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-09 20:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18  1:02 [PATCH] libgccjit: Add support for types used by atomic builtins [PR96066] [PR96067] Antoni Boucher
2021-05-20 20:24 ` David Malcolm
2021-05-26 21:58   ` Antoni Boucher
2021-11-20 16:27   ` Antoni Boucher
2021-11-20 18:50     ` David Malcolm
2021-11-21 21:44       ` Antoni Boucher
2021-12-04  4:37         ` Antoni Boucher
2021-12-09 20:25         ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).