From: Antoni Boucher <bouanto@zoho.com>
To: "jit@gcc.gnu.org" <jit@gcc.gnu.org>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH] libgccjit: Allow comparing array types
Date: Fri, 19 Jan 2024 16:55:52 -0500 [thread overview]
Message-ID: <b4a07b1bbfcfad5ab8ba6295c9b3aed108a6d5c0.camel@zoho.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 104 bytes --]
Hi.
This patch allows comparing different instances of array types as
equal.
Thanks for the review.
[-- Attachment #2: 0001-libgccjit-Allow-comparing-array-types.patch --]
[-- Type: text/x-patch, Size: 3440 bytes --]
From ef4afd9de440f10502f3cc84b2112cf83cde2610 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Tue, 2 Jan 2024 16:04:10 -0500
Subject: [PATCH] libgccjit: Allow comparing array types
gcc/jit/ChangeLog:
* jit-common.h: Add array_type class.
* jit-recording.h (type::dyn_cast_array_type,
memento_of_get_aligned::dyn_cast_array_type,
array_type::dyn_cast_array_type, array_type::is_same_type_as):
New methods.
gcc/testsuite/ChangeLog:
* jit.dg/test-types.c: Add array type comparison to the test.
---
gcc/jit/jit-common.h | 1 +
gcc/jit/jit-recording.h | 17 +++++++++++++++++
gcc/testsuite/jit.dg/test-types.c | 5 +++++
3 files changed, 23 insertions(+)
diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index 80c1618da96..57a667e6d12 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -118,6 +118,7 @@ namespace recording {
class struct_;
class union_;
class vector_type;
+ class array_type;
class field;
class bitfield;
class fields;
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 4a8082991fb..df33ce219fc 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -545,6 +545,7 @@ public:
virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
virtual struct_ *dyn_cast_struct () { return NULL; }
virtual vector_type *dyn_cast_vector_type () { return NULL; }
+ virtual array_type *dyn_cast_array_type () { return NULL; }
/* Is it typesafe to copy to this type from rtype? */
virtual bool accepts_writes_from (type *rtype)
@@ -810,6 +811,11 @@ public:
void replay_into (replayer *) final override;
+ array_type *dyn_cast_array_type () final override
+ {
+ return m_other_type->dyn_cast_array_type ();
+ }
+
private:
string * make_debug_string () final override;
void write_reproducer (reproducer &r) final override;
@@ -868,6 +874,17 @@ class array_type : public type
type *dereference () final override;
+ bool is_same_type_as (type *other) final override
+ {
+ array_type *other_array_type = other->dyn_cast_array_type ();
+ if (!other_array_type)
+ return false;
+ return m_num_elements == other_array_type->m_num_elements
+ && m_element_type->is_same_type_as (other_array_type->m_element_type);
+ }
+
+ array_type *dyn_cast_array_type () final override { return this; }
+
bool is_int () const final override { return false; }
bool is_float () const final override { return false; }
bool is_bool () const final override { return false; }
diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c
index a01944e35fa..79f7ea21026 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -492,4 +492,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
+
+ gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_type *array_type1 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
+ gcc_jit_type *array_type2 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
+ CHECK (gcc_jit_compatible_types (array_type1, array_type2));
}
--
2.43.0
next reply other threads:[~2024-01-19 21:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 21:55 Antoni Boucher [this message]
2024-01-24 17:14 ` David Malcolm
2024-01-25 12:52 ` Antoni Boucher
2024-02-29 15:53 ` Antoni Boucher
2024-06-26 15:41 ` David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b4a07b1bbfcfad5ab8ba6295c9b3aed108a6d5c0.camel@zoho.com \
--to=bouanto@zoho.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jit@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).