Skip to content

Commit

Permalink
libgccjit: Allow comparing array types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antoyo committed Feb 9, 2024
1 parent ec837b3 commit ea90a91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions gcc/jit/jit-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ namespace recording {
class struct_;
class union_;
class vector_type;
class array_type;
class field;
class bitfield;
class fields;
Expand Down
17 changes: 17 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ class type : public memento
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)
Expand Down Expand Up @@ -823,6 +824,11 @@ class memento_of_get_const : public decorated_type

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;
Expand Down Expand Up @@ -1001,6 +1007,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; }

type* copy(context* ctxt) final override
{
type* result = new array_type (ctxt, m_loc, m_element_type->copy (ctxt), m_num_elements);
Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/jit.dg/test-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit ea90a91

Please sign in to comment.