]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgccjit: Allow comparing array types
authorAntoni Boucher <bouanto@zoho.com>
Tue, 2 Jan 2024 21:04:10 +0000 (16:04 -0500)
committerAntoni Boucher <bouanto@zoho.com>
Fri, 5 Jul 2024 14:26:08 +0000 (10:26 -0400)
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
gcc/jit/jit-recording.h
gcc/testsuite/jit.dg/test-types.c

index afb41763e46c26e0f99177f1171195d9eb2409b4..655d94e0bab4ba1b15ff1c6f2ef288321b900a00 100644 (file)
@@ -118,6 +118,7 @@ namespace recording {
         class struct_;
        class union_;
       class vector_type;
+      class array_type;
     class field;
       class bitfield;
     class fields;
index cce25f1fc0704fcf5a02a7112711ebf9ccb32f1d..abd4f6f8bb3346438fc66326f4fbf5a7b791d03f 100644 (file)
@@ -560,6 +560,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)
@@ -829,6 +830,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;
@@ -895,6 +901,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; }
index f51252e0da042e7ae4857313efce826d8cbc88a0..bfdb76383c5514f8bb4c9383620d0678040995be 100644 (file)
@@ -496,4 +496,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
 #ifdef HAVE_BFmode
   CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BFLOAT16)), sizeof (__bfloat16));
 #endif
+
+  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));
 }