| 1 |
/* { dg-do compile { target x86_64-*-* } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#include "libgccjit.h" |
| 7 |
|
| 8 |
#define TEST_ESCHEWS_SET_OPTIONS |
| 9 |
static void set_options (gcc_jit_context *ctxt, const char *argv0) |
| 10 |
{ |
| 11 |
// Set "-O2". |
| 12 |
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 2); |
| 13 |
} |
| 14 |
|
| 15 |
#define TEST_COMPILING_TO_FILE |
| 16 |
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER |
| 17 |
#define OUTPUT_FILENAME "output-of-test-noinline-attribute.c.s" |
| 18 |
#include "harness.h" |
| 19 |
|
| 20 |
gcc_jit_function* |
| 21 |
create_function (gcc_jit_context *ctxt, |
| 22 |
const char *func_name, |
| 23 |
gcc_jit_type *int_type, |
| 24 |
int returned_value) |
| 25 |
{ |
| 26 |
gcc_jit_function *func |
| 27 |
= gcc_jit_context_new_function(ctxt, NULL, |
| 28 |
GCC_JIT_FUNCTION_INTERNAL, |
| 29 |
int_type, |
| 30 |
func_name, |
| 31 |
0, NULL, |
| 32 |
0); |
| 33 |
gcc_jit_block *block = gcc_jit_function_new_block (func, NULL); |
| 34 |
|
| 35 |
gcc_jit_block_add_extended_asm (block, NULL, ""); |
| 36 |
gcc_jit_block_end_with_return (block, NULL, |
| 37 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, returned_value)); |
| 38 |
|
| 39 |
return func; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
void |
| 44 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 45 |
{ |
| 46 |
/* Let's try to inject the equivalent of: |
| 47 |
__attribute__ ((noinline)) |
| 48 |
static int not_removed() { |
| 49 |
asm(""); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
static int removed() { |
| 53 |
asm(""); |
| 54 |
return 2; |
| 55 |
} |
| 56 |
int foo () { |
| 57 |
int x = 0; |
| 58 |
x += removed(); |
| 59 |
x += not_removed(); |
| 60 |
return x; |
| 61 |
} |
| 62 |
*/ |
| 63 |
gcc_jit_type *int_type = |
| 64 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 65 |
|
| 66 |
/* Creating the `not_removed` function. */ |
| 67 |
gcc_jit_function *not_removed_func = |
| 68 |
create_function (ctxt, "not_removed", int_type, 1); |
| 69 |
/* __attribute__ ((no_inline)) */ |
| 70 |
gcc_jit_function_add_attribute(not_removed_func, GCC_JIT_FN_ATTRIBUTE_NOINLINE); |
| 71 |
|
| 72 |
/* Creating the `removed` function. */ |
| 73 |
gcc_jit_function *removed_func = |
| 74 |
create_function (ctxt, "removed", int_type, 2); |
| 75 |
|
| 76 |
/* Creating the `foo` function. */ |
| 77 |
gcc_jit_function *foo_func = |
| 78 |
gcc_jit_context_new_function (ctxt, NULL, |
| 79 |
GCC_JIT_FUNCTION_EXPORTED, |
| 80 |
int_type, |
| 81 |
"foo", |
| 82 |
0, NULL, |
| 83 |
0); |
| 84 |
|
| 85 |
gcc_jit_block *foo_block = gcc_jit_function_new_block (foo_func, NULL); |
| 86 |
|
| 87 |
/* Build locals: */ |
| 88 |
gcc_jit_lvalue *x = |
| 89 |
gcc_jit_function_new_local (foo_func, NULL, int_type, "x"); |
| 90 |
|
| 91 |
/* int x = 0; */ |
| 92 |
gcc_jit_block_add_assignment ( |
| 93 |
foo_block, NULL, |
| 94 |
x, |
| 95 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0)); |
| 96 |
|
| 97 |
/* x += removed(); */ |
| 98 |
gcc_jit_block_add_assignment_op ( |
| 99 |
foo_block, NULL, |
| 100 |
x, |
| 101 |
GCC_JIT_BINARY_OP_PLUS, |
| 102 |
gcc_jit_context_new_call (ctxt, NULL, removed_func, 0, NULL)); |
| 103 |
|
| 104 |
/* x += not_removed(); */ |
| 105 |
gcc_jit_block_add_assignment_op ( |
| 106 |
foo_block, NULL, |
| 107 |
x, |
| 108 |
GCC_JIT_BINARY_OP_PLUS, |
| 109 |
gcc_jit_context_new_call (ctxt, NULL, not_removed_func, 0, NULL)); |
| 110 |
|
| 111 |
/* return x; */ |
| 112 |
gcc_jit_block_end_with_return (foo_block, NULL, gcc_jit_lvalue_as_rvalue(x)); |
| 113 |
} |
| 114 |
|
| 115 |
/* { dg-final { jit-verify-output-file-was-created "" } } */ |
| 116 |
/* Check that the "removed" function was inlined, but not the others */ |
| 117 |
/* { dg-final { jit-verify-assembler-output-not ".type\\s+removed.isra.0,\\s+@function" { target { ! *-*-darwin* } } } } */ |
| 118 |
/* { dg-final { jit-verify-assembler-output ".type\\s+not_removed.isra.0,\\s+@function" { target { ! *-*-darwin* } } } } */ |
| 119 |
/* { dg-final { jit-verify-assembler-output ".type\\s+foo,\\s+@function" { target { ! *-*-darwin* } } } } */ |
| 120 |
|
| 121 |
/* { dg-final { jit-verify-assembler-output-not "\\n_removed.isra.0:" { target *-*-darwin* } } } */ |
| 122 |
/* { dg-final { jit-verify-assembler-output "\\n_not_removed.isra.0:" { target *-*-darwin* } } } */ |
| 123 |
/* { dg-final { jit-verify-assembler-output "\\n_foo:" { target *-*-darwin* } } } */ |