aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-10-04 13:41:01 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-10-04 13:41:01 +0000
commit6069fe72870e410c08570e94ce2b141c6bc88219 (patch)
tree5a934460e85fcef8a36ea6e8242e0d10b59be28e /gcc/jit/libgccjit.c
parent4f15b6a282bc4c11ee8b32dac4f05aab10ce3e10 (diff)
downloadgcc-6069fe72870e410c08570e94ce2b141c6bc88219.zip
gcc-6069fe72870e410c08570e94ce2b141c6bc88219.tar.gz
gcc-6069fe72870e410c08570e94ce2b141c6bc88219.tar.bz2
jit: implement gcc_jit_context_new_rvalue_from_vector
This patch implements a new API entrypoint: /* Build a vector rvalue from an array of elements. "vec_type" should be a vector type, created using gcc_jit_type_get_vector. This API entrypoint was added in LIBGCCJIT_ABI_10; you can test for its presence using #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector */ extern gcc_jit_rvalue * gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *vec_type, size_t num_elements, gcc_jit_rvalue **elements); gcc/jit/ChangeLog: * docs/cp/topics/expressions.rst (Vector expressions): New section. * docs/topics/compatibility.rst (LIBGCCJIT_ABI_10): New ABI tag. * docs/topics/expressions.rst (Vector expressions): New section. * docs/topics/types.rst (gcc_jit_type_get_vector): Add link to gcc_jit_context_new_rvalue_from_vector. * jit-common.h (gcc::jit:recording::vector_type): New forward decl. * jit-playback.c (gcc::jit::playback::context::new_rvalue_from_vector): New method. * jit-playback.h (gcc::jit::playback::context::new_rvalue_from_vector): New method. * jit-recording.c: In namespace gcc::jit:: (class comma_separated_string): New class. (comma_separated_string::comma_separated_string): New ctor, adapted from recording::call::make_debug_string. (comma_separated_string::~comma_separated_string): New dtor. In namespace gcc::jit::recording:: (context::new_rvalue_from_vector): New method. (type::get_vector): Update for renaming of memento_of_get_vector. (class memento_of_get_vector): Rename to... (class vector_type): ..this. (memento_of_new_rvalue_from_vector::memento_of_new_rvalue_from_vector): New ctor. (memento_of_new_rvalue_from_vector::replay_into): New method. (memento_of_new_rvalue_from_vector::visit_children): New method. (memento_of_new_rvalue_from_vector::make_debug_string): New method. (memento_of_new_rvalue_from_vector::write_reproducer): New method. (call::make_debug_string): Split out arg-printing code into ctor for comma_separated_string. * jit-recording.h: In namespace gcc::jit::recording:: (context::new_rvalue_from_vector): New method. (type::dyn_cast_vector_type): New virtual function. (class memento_of_get_vector): Rename to... (class vector_type): ...this. (vector_type::unqualified): Remove this vfunc override in favor of... (vector_type::get_element_type): ...this new method. (vector_type::get_num_units): New method. (vector_type::dyn_cast_vector_type): New vfunc override. (class memento_of_new_rvalue_from_vector): New class. * libgccjit++.h (gccjit::context::new_rvalue): Add overload for vector of rvalue. * libgccjit.c (gcc_jit_context_new_binary_op): Strip off type qualifications when checking that both operands have same type. (gcc_jit_context_new_rvalue_from_vector): New API entrypoint. * libgccjit.h (LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector): New macro. (gcc_jit_context_new_rvalue_from_vector): New API entrypoint. * libgccjit.map (LIBGCCJIT_ABI_10): New ABI tag. gcc/testsuite/ChangeLog: * jit.dg/test-expressions.c (make_test_of_vectors): New function. (create_code): Call it. * jit.dg/test-vector-rvalues.cc: New test case. From-SVN: r253409
Diffstat (limited to 'gcc/jit/libgccjit.c')
-rw-r--r--gcc/jit/libgccjit.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 37cb695..c00acbf 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -1335,7 +1335,7 @@ gcc_jit_context_new_binary_op (gcc_jit_context *ctxt,
RETURN_NULL_IF_FAIL (a, ctxt, loc, "NULL a");
RETURN_NULL_IF_FAIL (b, ctxt, loc, "NULL b");
RETURN_NULL_IF_FAIL_PRINTF4 (
- a->get_type () == b->get_type (),
+ a->get_type ()->unqualified () == b->get_type ()->unqualified (),
ctxt, loc,
"mismatching types for binary op:"
" a: %s (type: %s) b: %s (type: %s)",
@@ -3042,3 +3042,61 @@ gcc_jit_function_get_address (gcc_jit_function *fn,
return (gcc_jit_rvalue *)fn->get_address (loc);
}
+
+/* Public entrypoint. See description in libgccjit.h.
+
+ After error-checking, the real work is done by the
+ gcc::jit::recording::context::new_rvalue_from_vector method, in
+ jit-recording.c. */
+
+extern gcc_jit_rvalue *
+gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
+ gcc_jit_location *loc,
+ gcc_jit_type *vec_type,
+ size_t num_elements,
+ gcc_jit_rvalue **elements)
+{
+ RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL ctxt");
+ JIT_LOG_FUNC (ctxt->get_logger ());
+
+ /* LOC can be NULL. */
+ RETURN_NULL_IF_FAIL (vec_type, ctxt, loc, "NULL vec_type");
+
+ /* "vec_type" must be a vector type. */
+ gcc::jit::recording::vector_type *as_vec_type
+ = vec_type->dyn_cast_vector_type ();
+ RETURN_NULL_IF_FAIL_PRINTF1 (as_vec_type, ctxt, loc,
+ "%s is not a vector type",
+ vec_type->get_debug_string ());
+
+ /* "num_elements" must match. */
+ RETURN_NULL_IF_FAIL_PRINTF1 (
+ num_elements == as_vec_type->get_num_units (), ctxt, loc,
+ "num_elements != %zi", as_vec_type->get_num_units ());
+
+ /* "elements must be non-NULL. */
+ RETURN_NULL_IF_FAIL (elements, ctxt, loc, "NULL elements");
+
+ /* Each of "elements" must be non-NULL and of the correct type. */
+ gcc::jit::recording::type *element_type
+ = as_vec_type->get_element_type ();
+ for (size_t i = 0; i < num_elements; i++)
+ {
+ RETURN_NULL_IF_FAIL_PRINTF1 (
+ elements[i], ctxt, loc, "NULL elements[%zi]", i);
+ RETURN_NULL_IF_FAIL_PRINTF4 (
+ compatible_types (element_type,
+ elements[i]->get_type ()),
+ ctxt, loc,
+ "mismatching type for element[%zi] (expected type: %s): %s (type: %s)",
+ i,
+ element_type->get_debug_string (),
+ elements[i]->get_debug_string (),
+ elements[i]->get_type ()->get_debug_string ());
+ }
+
+ return (gcc_jit_rvalue *)ctxt->new_rvalue_from_vector
+ (loc,
+ as_vec_type,
+ (gcc::jit::recording::rvalue **)elements);
+}