aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/jit.dg/test-nested-loops.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@gcc.gnu.org>2014-11-11 21:55:52 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2014-11-11 21:55:52 +0000
commit35485da996c21efc9a574520a737e10fcbeab654 (patch)
tree50dc30071e711da437584255821706cc0e1ef426 /gcc/testsuite/jit.dg/test-nested-loops.c
parent970a9caa49aff82c46a9d9f96410653ac9a588f7 (diff)
downloadgcc-35485da996c21efc9a574520a737e10fcbeab654.zip
gcc-35485da996c21efc9a574520a737e10fcbeab654.tar.gz
gcc-35485da996c21efc9a574520a737e10fcbeab654.tar.bz2
Merger of dmalcolm/jit branch from git
ChangeLog: * ChangeLog.jit: New. * MAINTAINERS (Various Maintainers): Add myself as jit maintainer. contrib/ChangeLog: * ChangeLog.jit: New. * jit-coverage-report.py: New file: a script to print crude code-coverage information for the libgccjit API. gcc/ChangeLog: * ChangeLog.jit: New. * Makefile.in (doc_build_sys): New variable, set to "sphinx" if sphinx is installed, falling back to "texinfo" otherwise. (FULL_DRIVER_NAME): New variable, adapted from the install-driver target. New target, a symlink within the builddir, linked to "xgcc", for use when running the JIT library from the builddir. (MOSTLYCLEANFILES): Add FULL_DRIVER_NAME. (install-driver): Use $(FULL_DRIVER_NAME) rather than spelling it out. * configure.ac (doc_build_sys): New variable, set to "sphinx" if sphinx is installed, falling back to "texinfo" otherwise. (GCC_DRIVER_NAME): Generate a gcc-driver-name.h file containing GCC_DRIVER_NAME for the benefit of jit/internal-api.c. * configure: Regenerate. * doc/install.texi (--enable-host-shared): Specify that this is required when building libgccjit. (Tools/packages necessary for modifying GCC): Add Sphinx. * timevar.def (TV_JIT_REPLAY): New. (TV_ASSEMBLE): New. (TV_LINK): New. (TV_LOAD): New. gcc/java/ChangeLog: * gcc/ChangeLog.jit: New. gcc/jit/ChangeLog: * ChangeLog.jit: New. * ChangeLog: New. * Make-lang.in: New. * TODO.rst: New. * config-lang.in: New. * docs/Makefile: New. * docs/_build/texinfo/Makefile: New. * docs/_build/texinfo/factorial.png: New. * docs/_build/texinfo/libgccjit.texi: New. * docs/_build/texinfo/sum-of-squares.png: New. * docs/conf.py: New. * docs/examples/tut01-hello-world.c: New. * docs/examples/tut02-square.c: New. * docs/examples/tut03-sum-of-squares.c: New. * docs/examples/tut04-toyvm/Makefile: New. * docs/examples/tut04-toyvm/factorial.toy: New. * docs/examples/tut04-toyvm/fibonacci.toy: New. * docs/examples/tut04-toyvm/toyvm.c: New. * docs/index.rst: New. * docs/internals/index.rst: New. * docs/intro/factorial.png: New. * docs/intro/index.rst: New. * docs/intro/sum-of-squares.png: New. * docs/intro/tutorial01.rst: New. * docs/intro/tutorial02.rst: New. * docs/intro/tutorial03.rst: New. * docs/intro/tutorial04.rst: New. * docs/topics/contexts.rst: New. * docs/topics/expressions.rst: New. * docs/topics/functions.rst: New. * docs/topics/index.rst: New. * docs/topics/locations.rst: New. * docs/topics/objects.rst: New. * docs/topics/results.rst: New. * docs/topics/types.rst: New. * dummy-frontend.c: New. * jit-builtins.c: New. * jit-builtins.h: New. * jit-common.h: New. * jit-playback.c: New. * jit-playback.h: New. * jit-recording.c: New. * jit-recording.h: New. * libgccjit++.h: New. * libgccjit.c: New. * libgccjit.h: New. * libgccjit.map: New. * notes.txt: New. gcc/testsuite/ChangeLog: * ChangeLog.jit: New. * jit.dg/all-non-failing-tests.h: New. * jit.dg/harness.h: New. * jit.dg/jit.exp: New. * jit.dg/test-accessing-struct.c: New. * jit.dg/test-accessing-union.c: New. * jit.dg/test-array-as-pointer.c: New. * jit.dg/test-arrays.c: New. * jit.dg/test-calling-external-function.c: New. * jit.dg/test-calling-function-ptr.c: New. * jit.dg/test-combination.c: New. * jit.dg/test-dot-product.c: New. * jit.dg/test-empty.c: New. * jit.dg/test-error-accessing-field-in-other-struct.c: New. * jit.dg/test-error-adding-to-terminated-block.c: New. * jit.dg/test-error-array-as-pointer.c: New. * jit.dg/test-error-bad-cast.c: New. * jit.dg/test-error-block-in-wrong-function.c: New. * jit.dg/test-error-call-through-ptr-with-mismatching-args.c: New. * jit.dg/test-error-call-through-ptr-with-non-function.c: New. * jit.dg/test-error-call-through-ptr-with-non-pointer.c: New. * jit.dg/test-error-call-through-ptr-with-not-enough-args.c: New. * jit.dg/test-error-call-through-ptr-with-too-many-args.c: New. * jit.dg/test-error-call-with-mismatching-args.c: New. * jit.dg/test-error-call-with-not-enough-args.c: New. * jit.dg/test-error-call-with-too-many-args.c: New. * jit.dg/test-error-dereference-field-of-non-pointer.c: New. * jit.dg/test-error-dereference-read-of-non-pointer.c: New. * jit.dg/test-error-get-type-bad-enum.c: New. * jit.dg/test-error-index-not-a-numeric-type.c: New. * jit.dg/test-error-mismatching-types-in-assignment.c: New. * jit.dg/test-error-mismatching-types-in-call.c: New. * jit.dg/test-error-missing-return.c: New. * jit.dg/test-error-new-binary-op-bad-op.c: New. * jit.dg/test-error-new-function-bad-kind.c: New. * jit.dg/test-error-new-unary-op-bad-op.c: New. * jit.dg/test-error-null-passed-to-api.c: New. * jit.dg/test-error-return-within-void-function.c: New. * jit.dg/test-error-unreachable-block.c: New. * jit.dg/test-error-unterminated-block.c: New. * jit.dg/test-error-value-not-a-numeric-type.c: New. * jit.dg/test-expressions.c: New. * jit.dg/test-factorial.c: New. * jit.dg/test-fibonacci.c: New. * jit.dg/test-functions.c: New. * jit.dg/test-fuzzer.c: New. * jit.dg/test-hello-world.c: New. * jit.dg/test-linked-list.c: New. * jit.dg/test-long-names.c: New. * jit.dg/test-nested-contexts.c: New. * jit.dg/test-nested-loops.c: New. * jit.dg/test-operator-overloading.cc: New. * jit.dg/test-quadratic.c: New. * jit.dg/test-quadratic.cc: New. * jit.dg/test-reading-struct.c: New. * jit.dg/test-string-literal.c: New. * jit.dg/test-sum-of-squares.c: New. * jit.dg/test-threads.c: New. * jit.dg/test-types.c: New. * jit.dg/test-using-global.c: New. * jit.dg/test-volatile.c: New. include/ChangeLog: * ChangeLog.jit: New. libbacktrace/ChangeLog: * ChangeLog.jit: New. libcpp/ChangeLog: * ChangeLog.jit: New. libdecnumber/ChangeLog: * ChangeLog.jit: New. libiberty/ChangeLog: * ChangeLog.jit: New. zlib/ChangeLog: * ChangeLog.jit: New. From-SVN: r217374
Diffstat (limited to 'gcc/testsuite/jit.dg/test-nested-loops.c')
-rw-r--r--gcc/testsuite/jit.dg/test-nested-loops.c179
1 files changed, 179 insertions, 0 deletions
diff --git a/gcc/testsuite/jit.dg/test-nested-loops.c b/gcc/testsuite/jit.dg/test-nested-loops.c
new file mode 100644
index 0000000..1d1a2ba
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-nested-loops.c
@@ -0,0 +1,179 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Let's try to inject the equivalent of:
+
+ double
+ test_nested_loops (int n, double *a, double *b)
+ {
+ double result = 0.;
+ for (int i = 0; i < n; i++)
+ for (int j = 0; j < n; j++)
+ result += a[i] * b[j];
+ return result
+ }
+ */
+ gcc_jit_type *val_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE);
+ gcc_jit_type *ptr_type = gcc_jit_type_get_pointer (val_type);
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+
+ gcc_jit_type *return_type = val_type;
+ gcc_jit_param *param_n =
+ gcc_jit_context_new_param (ctxt, NULL, int_type, "n");
+ gcc_jit_param *param_a =
+ gcc_jit_context_new_param (ctxt, NULL, ptr_type, "a");
+ gcc_jit_param *param_b =
+ gcc_jit_context_new_param (ctxt, NULL, ptr_type, "b");
+ gcc_jit_param *params[3] = {param_n, param_a, param_b};
+ gcc_jit_function *func =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ return_type,
+ "test_nested_loops",
+ 3, params, 0);
+
+ /* Create locals. */
+ gcc_jit_lvalue *result =
+ gcc_jit_function_new_local (func, NULL, val_type, "result");
+ gcc_jit_lvalue *i =
+ gcc_jit_function_new_local (func, NULL, int_type, "i");
+ gcc_jit_lvalue *j =
+ gcc_jit_function_new_local (func, NULL, int_type, "j");
+
+ /* Create basic blocks. */
+ gcc_jit_block *b_entry =
+ gcc_jit_function_new_block (func, "b_entry");
+ gcc_jit_block *b_outer_loop_cond =
+ gcc_jit_function_new_block (func, "b_outer_loop_cond");
+ gcc_jit_block *b_outer_loop_head =
+ gcc_jit_function_new_block (func, "b_outer_loop_head");
+ gcc_jit_block *b_outer_loop_tail =
+ gcc_jit_function_new_block (func, "b_outer_loop_tail");
+ gcc_jit_block *b_inner_loop_cond =
+ gcc_jit_function_new_block (func, "b_inner_loop_cond");
+ gcc_jit_block *b_inner_loop_body =
+ gcc_jit_function_new_block (func, "b_inner_loop_body");
+ gcc_jit_block *b_exit =
+ gcc_jit_function_new_block (func, "b_exit");
+
+
+ /* Populate b_entry. */
+
+ /* "result = 0.;" */
+ gcc_jit_block_add_assignment (
+ b_entry, NULL,
+ result,
+ gcc_jit_context_zero (ctxt, val_type));
+ /* "i = 0;" */
+ gcc_jit_block_add_assignment (
+ b_entry, NULL,
+ i,
+ gcc_jit_context_zero (ctxt, int_type));
+ gcc_jit_block_end_with_jump (b_entry, NULL, b_outer_loop_cond);
+
+ /* Populate b_outer_loop_cond. */
+ gcc_jit_block_end_with_conditional (
+ b_outer_loop_cond,
+ NULL,
+ /* (i < n) */
+ gcc_jit_context_new_comparison (
+ ctxt, NULL,
+ GCC_JIT_COMPARISON_LT,
+ gcc_jit_lvalue_as_rvalue (i),
+ gcc_jit_param_as_rvalue (param_n)),
+ b_outer_loop_head,
+ b_exit);
+
+ /* Populate b_outer_loop_head. */
+ /* j = 0; */
+ gcc_jit_block_add_assignment (
+ b_outer_loop_head, NULL,
+ j,
+ gcc_jit_context_zero (ctxt, int_type));
+ gcc_jit_block_end_with_jump (b_outer_loop_head, NULL, b_inner_loop_cond);
+
+ /* Populate b_inner_loop_cond. */
+ gcc_jit_block_end_with_conditional (
+ b_inner_loop_cond,
+ NULL,
+ /* (j < n) */
+ gcc_jit_context_new_comparison (
+ ctxt, NULL,
+ GCC_JIT_COMPARISON_LT,
+ gcc_jit_lvalue_as_rvalue (j),
+ gcc_jit_param_as_rvalue (param_n)),
+ b_inner_loop_body,
+ b_outer_loop_tail);
+
+ /* Populate b_inner_loop_body. */
+ /* "result += a[i] * b[j];" */
+ gcc_jit_block_add_assignment_op (
+ b_inner_loop_body, NULL,
+ result,
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_context_new_binary_op (
+ ctxt, NULL,
+ GCC_JIT_BINARY_OP_MULT,
+ val_type,
+ gcc_jit_lvalue_as_rvalue (
+ gcc_jit_context_new_array_access(
+ ctxt, NULL,
+ gcc_jit_param_as_rvalue (param_a),
+ gcc_jit_lvalue_as_rvalue (i))),
+ gcc_jit_lvalue_as_rvalue (
+ gcc_jit_context_new_array_access(
+ ctxt, NULL,
+ gcc_jit_param_as_rvalue (param_b),
+ gcc_jit_lvalue_as_rvalue (j)))));
+ /* "j++" */
+ gcc_jit_block_add_assignment_op (
+ b_inner_loop_body, NULL,
+ j,
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_context_one (ctxt, int_type));
+
+ gcc_jit_block_end_with_jump (b_inner_loop_body, NULL, b_inner_loop_cond);
+
+ /* Populate b_outer_loop_tail. */
+ /* "i++" */
+ gcc_jit_block_add_assignment_op (
+ b_outer_loop_tail, NULL,
+ i,
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_context_one (ctxt, int_type));
+ gcc_jit_block_end_with_jump (b_outer_loop_tail, NULL, b_outer_loop_cond);
+
+ /* Populate b_exit. */
+ /* "return result;" */
+ gcc_jit_block_end_with_return (
+ b_exit,
+ NULL,
+ gcc_jit_lvalue_as_rvalue (result));
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ typedef double (*test_nested_loops_fn_type) (int n, double *a, double *b);
+ CHECK_NON_NULL (result);
+
+ test_nested_loops_fn_type test_nested_loops =
+ (test_nested_loops_fn_type)gcc_jit_result_get_code (result,
+ "test_nested_loops");
+ CHECK_NON_NULL (test_nested_loops);
+ double test_a[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
+ double test_b[] = {5., 6., 7., 8., 9., 10., 1., 2., 3., 4.};
+ double val = test_nested_loops (10, test_a, test_b);
+ note ("test_nested_loops returned: %f", val);
+ CHECK_VALUE (val, 3025.0);
+}