diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-08-29 11:32:09 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-08-29 11:32:12 -0400 |
commit | 29763b002459cba64fa76a6965046792944de41d (patch) | |
tree | f5c7c538f99c3453c6a9c36786c87a8b1d6156fe /gcc/jit | |
parent | 4b70c7c849331d45c0d6a1a4e1cf96b103be9aa6 (diff) | |
download | gcc-29763b002459cba64fa76a6965046792944de41d.zip gcc-29763b002459cba64fa76a6965046792944de41d.tar.gz gcc-29763b002459cba64fa76a6965046792944de41d.tar.bz2 |
libgccjit: add support for `restrict` attribute on function parameters
gcc/jit/Changelog:
* jit-playback.cc: Remove trailing whitespace characters.
* jit-playback.h: Add get_restrict method.
* jit-recording.cc: Add get_restrict methods.
* jit-recording.h: Add get_restrict methods.
* libgccjit++.h: Add get_restrict methods.
* libgccjit.cc: Add gcc_jit_type_get_restrict.
* libgccjit.h: Declare gcc_jit_type_get_restrict.
* libgccjit.map: Declare gcc_jit_type_get_restrict.
gcc/testsuite/ChangeLog:
* jit.dg/test-restrict.c: Add test for __restrict__ attribute.
* jit.dg/all-non-failing-tests.h: Add test-restrict.c to the list.
gcc/jit/ChangeLog:
* docs/topics/compatibility.rst: Add documentation for LIBGCCJIT_ABI_25.
* docs/topics/types.rst: Add documentation for gcc_jit_type_get_restrict.
Signed-off-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Diffstat (limited to 'gcc/jit')
-rw-r--r-- | gcc/jit/docs/topics/compatibility.rst | 7 | ||||
-rw-r--r-- | gcc/jit/docs/topics/types.rst | 12 | ||||
-rw-r--r-- | gcc/jit/jit-playback.cc | 2 | ||||
-rw-r--r-- | gcc/jit/jit-playback.h | 5 | ||||
-rw-r--r-- | gcc/jit/jit-recording.cc | 47 | ||||
-rw-r--r-- | gcc/jit/jit-recording.h | 30 | ||||
-rw-r--r-- | gcc/jit/libgccjit++.h | 6 | ||||
-rw-r--r-- | gcc/jit/libgccjit.cc | 15 | ||||
-rw-r--r-- | gcc/jit/libgccjit.h | 9 | ||||
-rw-r--r-- | gcc/jit/libgccjit.map | 5 |
10 files changed, 136 insertions, 2 deletions
diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index f4ffa07..ebede44 100644 --- a/gcc/jit/docs/topics/compatibility.rst +++ b/gcc/jit/docs/topics/compatibility.rst @@ -371,3 +371,10 @@ alignment of a variable: * :func:`gcc_jit_lvalue_set_alignment` * :func:`gcc_jit_lvalue_get_alignment` + +.. _LIBGCCJIT_ABI_25: + +``LIBGCCJIT_ABI_25`` +-------------------- +``LIBGCCJIT_ABI_25`` covers the addition of +:func:`gcc_jit_type_get_restrict` diff --git a/gcc/jit/docs/topics/types.rst b/gcc/jit/docs/topics/types.rst index f5f2aac..d8c1d15 100644 --- a/gcc/jit/docs/topics/types.rst +++ b/gcc/jit/docs/topics/types.rst @@ -541,3 +541,15 @@ Reflection API .. code-block:: c #ifdef LIBGCCJIT_HAVE_SIZED_INTEGERS + +.. function:: gcc_jit_type *\ + gcc_jit_type_get_restrict (gcc_jit_type *type) + + Given type "T", get type "restrict T". + + This entrypoint was added in :ref:`LIBGCCJIT_ABI_25`; you can test for + its presence using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_restrict diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc index e06f161..9b75738 100644 --- a/gcc/jit/jit-playback.cc +++ b/gcc/jit/jit-playback.cc @@ -3393,7 +3393,7 @@ if (t) \ NAME_TYPE (complex_float_type_node, "complex float"); NAME_TYPE (complex_double_type_node, "complex double"); NAME_TYPE (complex_long_double_type_node, "complex long double"); - + m_const_char_ptr = build_pointer_type( build_qualified_type (char_type_node, TYPE_QUAL_CONST)); diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 883159f..438f395 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -446,6 +446,11 @@ public: return new type (build_qualified_type (m_inner, TYPE_QUAL_VOLATILE)); } + type *get_restrict () const + { + return new type (build_qualified_type (m_inner, TYPE_QUAL_RESTRICT)); + } + type *get_aligned (size_t alignment_in_bytes) const; type *get_vector (size_t num_units) const; diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index df0368f..326c8c28 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -2267,6 +2267,19 @@ recording::type::get_const () return result; } +/* Given a type T, get the type restrict T. + + Implements the post-error-checking part of + gcc_jit_type_get_restrict. */ + +recording::type * +recording::type::get_restrict () +{ + recording::type *result = new memento_of_get_restrict (this); + m_ctxt->record (result); + return result; +} + /* Given a type T, get the type volatile T. Implements the post-error-checking part of @@ -2960,6 +2973,40 @@ recording::memento_of_get_volatile::write_reproducer (reproducer &r) r.get_identifier_as_type (m_other_type)); } +/* The implementation of class gcc::jit::recording::memento_of_get_restrict. */ + +/* Implementation of pure virtual hook recording::memento::replay_into + for recording::memento_of_get_restrict. */ + +void +recording::memento_of_get_restrict::replay_into (replayer *) +{ + set_playback_obj (m_other_type->playback_type ()->get_restrict ()); +} + +/* Implementation of recording::memento::make_debug_string for + results of get_restrict, prepending "restrict ". */ + +recording::string * +recording::memento_of_get_restrict::make_debug_string () +{ + return string::from_printf (m_ctxt, + "restrict %s", m_other_type->get_debug_string ()); +} + +/* Implementation of recording::memento::write_reproducer for restrict + types. */ + +void +recording::memento_of_get_restrict::write_reproducer (reproducer &r) +{ + const char *id = r.make_identifier (this, "type"); + r.write (" gcc_jit_type *%s =\n" + " gcc_jit_type_get_restrict (%s);\n", + id, + r.get_identifier_as_type (m_other_type)); +} + /* The implementation of class gcc::jit::recording::memento_of_get_aligned. */ /* Implementation of pure virtual hook recording::memento::replay_into diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 400cf34..4a80829 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -524,6 +524,7 @@ public: type *get_pointer (); type *get_const (); type *get_volatile (); + type *get_restrict (); type *get_aligned (size_t alignment_in_bytes); type *get_vector (size_t num_units); @@ -568,6 +569,7 @@ public: virtual bool is_bool () const = 0; virtual type *is_pointer () = 0; virtual type *is_volatile () { return NULL; } + virtual type *is_restrict () { return NULL; } virtual type *is_const () { return NULL; } virtual type *is_array () = 0; virtual struct_ *is_struct () { return NULL; } @@ -686,7 +688,7 @@ private: }; /* A decorated version of a type, for get_const, get_volatile, - get_aligned, and get_vector. */ + get_aligned, get_restrict, and get_vector. */ class decorated_type : public type { @@ -769,6 +771,32 @@ private: void write_reproducer (reproducer &r) final override; }; +/* Result of "gcc_jit_type_get_restrict". */ +class memento_of_get_restrict : public decorated_type +{ +public: + memento_of_get_restrict (type *other_type) + : decorated_type (other_type) {} + + bool is_same_type_as (type *other) final override + { + if (!other->is_restrict ()) + return false; + return m_other_type->is_same_type_as (other->is_restrict ()); + } + + /* Strip off the "restrict", giving the underlying type. */ + type *unqualified () final override { return m_other_type; } + + type *is_restrict () final override { return m_other_type; } + + void replay_into (replayer *) final override; + +private: + string * make_debug_string () final override; + void write_reproducer (reproducer &r) final override; +}; + /* Result of "gcc_jit_type_get_aligned". */ class memento_of_get_aligned : public decorated_type { diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h index df07889..4a04db3 100644 --- a/gcc/jit/libgccjit++.h +++ b/gcc/jit/libgccjit++.h @@ -1411,6 +1411,12 @@ type::get_const () } inline type +type::get_restrict () +{ + return type (gcc_jit_type_get_restrict (get_inner_type ())); +} + +inline type type::get_volatile () { return type (gcc_jit_type_get_volatile (get_inner_type ())); diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 2def58f..0451b4d 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -537,6 +537,21 @@ gcc_jit_type_get_volatile (gcc_jit_type *type) /* Public entrypoint. See description in libgccjit.h. After error-checking, the real work is done by the + gcc::jit::recording::type::get_restrict method, in + jit-recording.cc. */ + +gcc_jit_type * +gcc_jit_type_get_restrict (gcc_jit_type *type) +{ + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); + RETURN_NULL_IF_FAIL (type->is_pointer (), NULL, NULL, "not a pointer type"); + + return (gcc_jit_type *)type->get_restrict (); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the gcc::jit::recording::type::get_size method, in jit-recording.cc. */ diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 057d3e5..749f6c2 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -630,6 +630,15 @@ gcc_jit_type_get_const (gcc_jit_type *type); extern gcc_jit_type * gcc_jit_type_get_volatile (gcc_jit_type *type); +#define LIBGCCJIT_HAVE_gcc_jit_type_get_restrict + +/* Given type "T", get type "restrict T". + This API entrypoint was added in LIBGCCJIT_ABI_25; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_restrict */ +extern gcc_jit_type * +gcc_jit_type_get_restrict (gcc_jit_type *type); + #define LIBGCCJIT_HAVE_SIZED_INTEGERS /* Given types LTYPE and RTYPE, return non-zero if they are compatible. diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index 25463b9..8b90a0e 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -271,3 +271,8 @@ LIBGCCJIT_ABI_24 { gcc_jit_lvalue_set_alignment; gcc_jit_lvalue_get_alignment; } LIBGCCJIT_ABI_23; + +LIBGCCJIT_ABI_25 { + global: + gcc_jit_type_get_restrict; +} LIBGCCJIT_ABI_24; |