Debian Codegraph @

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

raw
1 /* { dg-do compile { target x86_64-*-* } } */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include "libgccjit.h"
7
8 /* We don't want set_options() in harness.h to set -O3 to see that the restrict
9 attribute affects the optimizations. */
10 #define TEST_ESCHEWS_SET_OPTIONS
11 static void set_options (gcc_jit_context *ctxt, const char *argv0)
12 {
13 // Set "-O3".
14 gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
15 }
16
17 #define TEST_COMPILING_TO_FILE
18 #define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
19 #define OUTPUT_FILENAME "output-of-test-restrict.c.s"
20 #include "harness.h"
21
22 void
23 create_code (gcc_jit_context *ctxt, void *user_data)
24 {
25 /* Let's try to inject the equivalent of:
26 void t(int *__restrict__ a, int *__restrict__ b, char *__restrict__ c) {
27 *a += *c;
28 *b += *c;
29 }
30 */
31 gcc_jit_type *int_type =
32 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
33 gcc_jit_type *pint_type = gcc_jit_type_get_pointer(int_type);
34 gcc_jit_type *pint_restrict_type = gcc_jit_type_get_restrict(pint_type);
35
36 gcc_jit_type *void_type =
37 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
38
39 gcc_jit_param *a =
40 gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "a");
41 gcc_jit_param *b =
42 gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "b");
43 gcc_jit_param *c =
44 gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "c");
45 gcc_jit_param *params[3] = {a, b, c};
46
47 gcc_jit_function *func_t =
48 gcc_jit_context_new_function (ctxt, NULL,
49 GCC_JIT_FUNCTION_EXPORTED,
50 void_type,
51 "t",
52 3, params,
53 0);
54
55 gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL);
56
57 /* *a += *c; */
58 gcc_jit_block_add_assignment_op (
59 block, NULL,
60 gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (a), NULL),
61 GCC_JIT_BINARY_OP_PLUS,
62 gcc_jit_lvalue_as_rvalue (
63 gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL)));
64 /* *b += *c; */
65 gcc_jit_block_add_assignment_op (
66 block, NULL,
67 gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (b), NULL),
68 GCC_JIT_BINARY_OP_PLUS,
69 gcc_jit_lvalue_as_rvalue (
70 gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL)));
71
72 gcc_jit_block_end_with_void_return (block, NULL);
73 }
74
75 /* { dg-final { jit-verify-output-file-was-created "" } } */
76 /* { dg-final { jit-verify-assembler-output "addl %eax, (%rdi)
77 addl %eax, (%rsi)" } } */