Skip to content

Commit 16cf1c0

Browse files
committed
libgccjit: Allow comparing aligned int types
gcc/jit/ChangeLog: * jit-common.h: Add forward declaration of memento_of_get_aligned. * jit-recording.h (type::is_same_type_as): Compare integer types. (dyn_cast_aligned_type): New method. (type::is_aligned, memento_of_get_aligned::is_same_type_as, memento_of_get_aligned::is_aligned): new methods. gcc/testsuite/ChangeLog: * jit.dg/test-types.c: Add checks comparing aligned types.
1 parent ede1409 commit 16cf1c0

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

gcc/jit/jit-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ namespace recording {
134134
class statement;
135135
class extended_asm;
136136
class case_;
137+
class memento_of_get_aligned;
137138
class top_level_asm;
138139

139140
/* End of recording types. */

gcc/jit/jit-recording.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ class type : public memento
580580
virtual struct_ *dyn_cast_struct () { return NULL; }
581581
virtual vector_type *dyn_cast_vector_type () { return NULL; }
582582
virtual array_type *dyn_cast_array_type () { return NULL; }
583+
virtual memento_of_get_aligned *dyn_cast_aligned_type () { return NULL; }
583584

584585
/* Is it typesafe to copy to this type from rtype? */
585586
virtual bool accepts_writes_from (type *rtype)
@@ -590,6 +591,14 @@ class type : public memento
590591

591592
virtual bool is_same_type_as (type *other)
592593
{
594+
if (is_int ()
595+
&& other->is_int ()
596+
&& get_size () == other->get_size ()
597+
&& is_signed () == other->is_signed ())
598+
{
599+
/* LHS (this) is an integer of the same size and sign as rtype. */
600+
return true;
601+
}
593602
return this == other;
594603
}
595604

@@ -607,6 +616,7 @@ class type : public memento
607616
virtual type *is_volatile () { return NULL; }
608617
virtual type *is_restrict () { return NULL; }
609618
virtual type *is_const () { return NULL; }
619+
virtual type *is_aligned () { return NULL; }
610620
virtual type *is_array () = 0;
611621
virtual struct_ *is_struct () { return NULL; }
612622
virtual bool is_union () const { return false; }
@@ -661,13 +671,6 @@ class memento_of_get_type : public type
661671
accept it: */
662672
return true;
663673
}
664-
} else if (is_int ()
665-
&& rtype->is_int ()
666-
&& get_size () == rtype->get_size ()
667-
&& is_signed () == rtype->is_signed ())
668-
{
669-
/* LHS (this) is an integer of the same size and sign as rtype. */
670-
return true;
671674
}
672675

673676
return type::accepts_writes_from (rtype);
@@ -844,10 +847,27 @@ class memento_of_get_aligned : public decorated_type
844847
: decorated_type (other_type),
845848
m_alignment_in_bytes (alignment_in_bytes) {}
846849

850+
bool is_same_type_as (type *other) final override
851+
{
852+
if (!other->is_aligned ())
853+
{
854+
return m_other_type->is_same_type_as (other);
855+
}
856+
return m_alignment_in_bytes
857+
== other->dyn_cast_aligned_type ()->m_alignment_in_bytes
858+
&& m_other_type->is_same_type_as (other->is_aligned ());
859+
}
860+
861+
type *is_aligned () final override { return m_other_type; }
862+
847863
/* Strip off the alignment, giving the underlying type. */
848864
type *unqualified () final override { return m_other_type; }
849865

850866
void replay_into (replayer *) final override;
867+
memento_of_get_aligned *dyn_cast_aligned_type () final override
868+
{
869+
return this;
870+
}
851871

852872
array_type *dyn_cast_array_type () final override
853873
{

gcc/testsuite/jit.dg/test-types.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
486486

487487
CHECK_VALUE (z.m_FILE_ptr, stderr);
488488

489+
gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
490+
gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T);
489491
if (sizeof(long) == 8)
490-
CHECK (gcc_jit_compatible_types (
491-
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
492-
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
492+
CHECK (gcc_jit_compatible_types (long_type, int64_type));
493493

494494
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
495495
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
@@ -501,4 +501,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
501501
gcc_jit_type *array_type1 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
502502
gcc_jit_type *array_type2 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
503503
CHECK (gcc_jit_compatible_types (array_type1, array_type2));
504+
505+
gcc_jit_type *aligned_long = gcc_jit_type_get_aligned (long_type, 4);
506+
gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned (int64_type, 4);
507+
if (sizeof(long) == 8)
508+
CHECK (gcc_jit_compatible_types (aligned_long, aligned_int64));
504509
}

0 commit comments

Comments
 (0)