| 1 |
/* { dg-additional-options "-fdump-tree-omplower" } */ |
| 2 |
|
| 3 |
/* { dg-final { scan-tree-dump-times "omp declare target\[^ \]" 3 "omplower" } } */ |
| 4 |
|
| 5 |
/* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target\\)\\)\[\n\r\]*int called_in_target1" 1 "omplower" } } */ |
| 6 |
/* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target\\)\\)\[\n\r\]*int called_in_target2" 1 "omplower" } } */ |
| 7 |
/* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target\\)\\)\[\n\r\]*void tg_fn" 1 "omplower" } } */ |
| 8 |
|
| 9 |
#pragma omp requires reverse_offload |
| 10 |
|
| 11 |
extern int add_3 (int); |
| 12 |
|
| 13 |
static int global_var = 5; |
| 14 |
|
| 15 |
void |
| 16 |
check_offload (int *x, int *y) |
| 17 |
{ |
| 18 |
*x = add_3 (*x); |
| 19 |
*y = add_3 (*y); |
| 20 |
} |
| 21 |
|
| 22 |
int |
| 23 |
called_in_target1 () |
| 24 |
{ |
| 25 |
return 42; |
| 26 |
} |
| 27 |
|
| 28 |
int |
| 29 |
called_in_target2 () |
| 30 |
{ |
| 31 |
return -6; |
| 32 |
} |
| 33 |
|
| 34 |
#pragma omp declare target |
| 35 |
void |
| 36 |
tg_fn (int *x, int *y) |
| 37 |
{ |
| 38 |
int x2 = *x, y2 = *y; |
| 39 |
if (x2 != 2 || y2 != 3) |
| 40 |
__builtin_abort (); |
| 41 |
x2 = x2 + 2 + called_in_target1 (); |
| 42 |
y2 = y2 + 7; |
| 43 |
|
| 44 |
#pragma omp target device(ancestor : 1) map(tofrom: x2) |
| 45 |
check_offload(&x2, &y2); |
| 46 |
|
| 47 |
if (x2 != 2+2+3+42 || y2 != 3 + 7) |
| 48 |
__builtin_abort (); |
| 49 |
*x = x2, *y = y2; |
| 50 |
} |
| 51 |
#pragma omp end declare target |
| 52 |
|
| 53 |
void |
| 54 |
my_func (int *x, int *y) |
| 55 |
{ |
| 56 |
if (global_var != 5) |
| 57 |
__builtin_abort (); |
| 58 |
global_var = 242; |
| 59 |
*x = 2*add_3(*x); |
| 60 |
*y = 3*add_3(*y); |
| 61 |
} |
| 62 |
|
| 63 |
int |
| 64 |
main () |
| 65 |
{ |
| 66 |
#pragma omp target |
| 67 |
{ |
| 68 |
int x = 2, y = 3; |
| 69 |
tg_fn (&x, &y); |
| 70 |
} |
| 71 |
|
| 72 |
#pragma omp target |
| 73 |
{ |
| 74 |
int x = -2, y = -1; |
| 75 |
x += called_in_target2 (); |
| 76 |
#pragma omp target device ( ancestor:1 ) firstprivate(y) map(tofrom:x) |
| 77 |
{ |
| 78 |
if (x != -2-6 || y != -1) |
| 79 |
__builtin_abort (); |
| 80 |
my_func (&x, &y); |
| 81 |
if (x != 2*(3-2) || y != 3*(3-1)) |
| 82 |
__builtin_abort (); |
| 83 |
} |
| 84 |
if (x != 2*(3-2) || y != -1) |
| 85 |
__builtin_abort (); |
| 86 |
} |
| 87 |
|
| 88 |
if (global_var != 242) |
| 89 |
__builtin_abort (); |
| 90 |
return 0; |
| 91 |
} |