| 1 |
/* TODO: move to ../libgomp.c-c++-common once C++ is implemented. */ |
| 2 |
/* NOTE: { target c } is unsupported with with the C compiler. */ |
| 3 |
|
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-additional-options "-fdump-tree-gimple" } */ |
| 6 |
|
| 7 |
#include <omp.h> |
| 8 |
#include <stdint.h> |
| 9 |
|
| 10 |
/* { dg-final { scan-tree-dump-not "__builtin_stack_save" "gimple" } } */ |
| 11 |
/* { dg-final { scan-tree-dump-not "__builtin_alloca" "gimple" } } */ |
| 12 |
/* { dg-final { scan-tree-dump-not "__builtin_stack_restore" "gimple" } } */ |
| 13 |
|
| 14 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_alloc \\(" 5 "gimple" } } */ |
| 15 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 5 "gimple" } } */ |
| 16 |
|
| 17 |
void |
| 18 |
one () |
| 19 |
{ |
| 20 |
int result = 0, n = 3; |
| 21 |
#pragma omp target map(tofrom: result) firstprivate(n) |
| 22 |
{ |
| 23 |
int var = 5, var2[n]; |
| 24 |
#pragma omp allocate(var,var2) align(128) allocator(omp_low_lat_mem_alloc) |
| 25 |
/* { dg-final { scan-tree-dump-times "var\\.\[0-9\]+ = __builtin_GOMP_alloc \\(128, 4, 5\\);" 1 "gimple" } } */ |
| 26 |
/* { dg-final { scan-tree-dump-times "var2\\.\[0-9\]+ = __builtin_GOMP_alloc \\(128, D\\.\[0-9\]+, 5\\);" 1 "gimple" } } */ |
| 27 |
|
| 28 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(var\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 29 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(var2\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 30 |
|
| 31 |
if ((intptr_t) &var % 128 != 0) |
| 32 |
__builtin_abort (); |
| 33 |
if ((intptr_t) var2 % 128 != 0) |
| 34 |
__builtin_abort (); |
| 35 |
if (var != 5) |
| 36 |
__builtin_abort (); |
| 37 |
|
| 38 |
#pragma omp parallel for |
| 39 |
for (int i = 0; i < n; ++i) |
| 40 |
var2[i] = (i+33); |
| 41 |
|
| 42 |
#pragma omp loop reduction(+:result) |
| 43 |
for (int i = 0; i < n; ++i) |
| 44 |
result += var + var2[i]; |
| 45 |
} |
| 46 |
if (result != (3*5 + 33 + 34 + 35)) |
| 47 |
__builtin_abort (); |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
two () |
| 52 |
{ |
| 53 |
struct st { |
| 54 |
int a, b; |
| 55 |
}; |
| 56 |
int scalar = 44, array[5] = {1,2,3,4,5}; |
| 57 |
struct st s = {.a=11, .b=56}; |
| 58 |
#pragma omp allocate(scalar, array, s) |
| 59 |
/* { dg-final { scan-tree-dump-times "scalar\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 4, 0B\\);" 1 "gimple" } } */ |
| 60 |
/* { dg-final { scan-tree-dump-times "array\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 20, 0B\\);" 1 "gimple" } } */ |
| 61 |
/* { dg-final { scan-tree-dump-times "s\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 8, 0B\\);" 1 "gimple" } } */ |
| 62 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(scalar\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 63 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(array\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 64 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(s\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 65 |
|
| 66 |
#pragma omp parallel firstprivate(scalar) firstprivate(array) firstprivate(s) |
| 67 |
{ |
| 68 |
if (scalar != 44) |
| 69 |
__builtin_abort (); |
| 70 |
scalar = 33; |
| 71 |
for (int i = 0; i < 5; ++i) |
| 72 |
if (array[i] != i+1) |
| 73 |
__builtin_abort (); |
| 74 |
for (int i = 0; i < 5; ++i) |
| 75 |
array[i] = 10*(i+1); |
| 76 |
if (s.a != 11 || s.b != 56) |
| 77 |
__builtin_abort (); |
| 78 |
s.a = 74; |
| 79 |
s.b = 674; |
| 80 |
} |
| 81 |
if (scalar != 44) |
| 82 |
__builtin_abort (); |
| 83 |
for (int i = 0; i < 5; ++i) |
| 84 |
if (array[i] != i+1) |
| 85 |
__builtin_abort (); |
| 86 |
if (s.a != 11 || s.b != 56) |
| 87 |
__builtin_abort (); |
| 88 |
|
| 89 |
#pragma omp target defaultmap(firstprivate : scalar) defaultmap(none : aggregate) defaultmap(none : pointer) |
| 90 |
{ |
| 91 |
if (scalar != 44) |
| 92 |
__builtin_abort (); |
| 93 |
scalar = 33; |
| 94 |
} |
| 95 |
if (scalar != 44) |
| 96 |
__builtin_abort (); |
| 97 |
|
| 98 |
#pragma omp target defaultmap(none : scalar) defaultmap(firstprivate : aggregate) defaultmap(none : pointer) |
| 99 |
{ |
| 100 |
for (int i = 0; i < 5; ++i) |
| 101 |
if (array[i] != i+1) |
| 102 |
__builtin_abort (); |
| 103 |
for (int i = 0; i < 5; ++i) |
| 104 |
array[i] = 10*(i+1); |
| 105 |
} |
| 106 |
for (int i = 0; i < 5; ++i) |
| 107 |
if (array[i] != i+1) |
| 108 |
__builtin_abort (); |
| 109 |
#pragma omp target defaultmap(none : scalar) defaultmap(firstprivate : aggregate) defaultmap(none : pointer) |
| 110 |
{ |
| 111 |
if (s.a != 11 || s.b != 56) |
| 112 |
__builtin_abort (); |
| 113 |
s.a = 74; |
| 114 |
s.b = 674; |
| 115 |
} |
| 116 |
if (s.a != 11 || s.b != 56) |
| 117 |
__builtin_abort (); |
| 118 |
} |
| 119 |
|
| 120 |
int |
| 121 |
main () |
| 122 |
{ |
| 123 |
one (); |
| 124 |
two (); |
| 125 |
return 0; |
| 126 |
} |