* :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`
.. 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
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));
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;
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
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
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);
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; }
};
/* 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
{
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
{
return type (gcc_jit_type_get_const (get_inner_type ()));
}
+inline type
+type::get_restrict ()
+{
+ return type (gcc_jit_type_get_restrict (get_inner_type ()));
+}
+
inline type
type::get_volatile ()
{
return (gcc_jit_type *)type->get_volatile ();
}
+/* 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
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.
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;
#undef create_code
#undef verify_code
+/* test-restrict.c: This can't be in the testcases array as it needs
+ the `-O3` flag. */
+
/* test-register-variable.c: This can't be in the testcases array as it
is target-specific. */
--- /dev/null
+/* { dg-do compile { target x86_64-*-* } } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+/* We don't want set_options() in harness.h to set -O3 to see that the restrict
+ attribute affects the optimizations. */
+#define TEST_ESCHEWS_SET_OPTIONS
+static void set_options (gcc_jit_context *ctxt, const char *argv0)
+{
+ // Set "-O3".
+ gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
+}
+
+#define TEST_COMPILING_TO_FILE
+#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
+#define OUTPUT_FILENAME "output-of-test-restrict.c.s"
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Let's try to inject the equivalent of:
+void t(int *__restrict__ a, int *__restrict__ b, char *__restrict__ c) {
+ *a += *c;
+ *b += *c;
+}
+ */
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_type *pint_type = gcc_jit_type_get_pointer(int_type);
+ gcc_jit_type *pint_restrict_type = gcc_jit_type_get_restrict(pint_type);
+
+ gcc_jit_type *void_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+
+ gcc_jit_param *a =
+ gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "a");
+ gcc_jit_param *b =
+ gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "b");
+ gcc_jit_param *c =
+ gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "c");
+ gcc_jit_param *params[3] = {a, b, c};
+
+ gcc_jit_function *func_t =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ void_type,
+ "t",
+ 3, params,
+ 0);
+
+ gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL);
+
+ /* *a += *c; */
+ gcc_jit_block_add_assignment_op (
+ block, NULL,
+ gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (a), NULL),
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_lvalue_as_rvalue (
+ gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL)));
+ /* *b += *c; */
+ gcc_jit_block_add_assignment_op (
+ block, NULL,
+ gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (b), NULL),
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_lvalue_as_rvalue (
+ gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL)));
+
+ gcc_jit_block_end_with_void_return (block, NULL);
+}
+
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-assembler-output "addl %eax, (%rdi)
+ addl %eax, (%rsi)" } } */