| 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-times "__builtin_GOMP_alloc \\(" 5 "gimple" } } */ |
| 11 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 5 "gimple" } } */ |
| 12 |
|
| 13 |
|
| 14 |
int one () |
| 15 |
{ |
| 16 |
int sum = 0; |
| 17 |
#pragma omp allocate(sum) |
| 18 |
/* { dg-final { scan-tree-dump-times "sum\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 4, 0B\\);" 1 "gimple" } } */ |
| 19 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(sum\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 20 |
|
| 21 |
/* NOTE: Initializer cannot be omp_init_allocator - as 'A' is |
| 22 |
in the same scope and the auto-omp_free comes later than |
| 23 |
any omp_destroy_allocator. */ |
| 24 |
omp_allocator_handle_t my_allocator = omp_low_lat_mem_alloc; |
| 25 |
int n = 25; |
| 26 |
int A[n]; |
| 27 |
#pragma omp allocate(A) align(128) allocator(my_allocator) |
| 28 |
/* { dg-final { scan-tree-dump-times "A\\.\[0-9\]+ = __builtin_GOMP_alloc \\(128, _\[0-9\]+, my_allocator\\);" 1 "gimple" } } */ |
| 29 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(A\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 30 |
|
| 31 |
if (((intptr_t)A) % 128 != 0) |
| 32 |
__builtin_abort (); |
| 33 |
for (int i = 0; i < n; ++i) |
| 34 |
A[i] = i; |
| 35 |
|
| 36 |
omp_alloctrait_t traits[1] = { { omp_atk_alignment, 64 } }; |
| 37 |
my_allocator = omp_init_allocator(omp_low_lat_mem_space,1,traits); |
| 38 |
{ |
| 39 |
int B[n] = { }; |
| 40 |
int C[5] = {1,2,3,4,5}; |
| 41 |
#pragma omp allocate(B,C) allocator(my_allocator) |
| 42 |
/* { dg-final { scan-tree-dump-times "B\\.\[0-9\]+ = __builtin_GOMP_alloc \\(\[0-9\]+, _\[0-9\]+, my_allocator\\);" 1 "gimple" } } */ |
| 43 |
/* { dg-final { scan-tree-dump-times "C\\.\[0-9\]+ = __builtin_GOMP_alloc \\(\[0-9\]+, 20, my_allocator\\);" 1 "gimple" } } */ |
| 44 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(B\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 45 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(C\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 46 |
|
| 47 |
int D[5] = {11,22,33,44,55}; |
| 48 |
#pragma omp allocate(D) align(256) |
| 49 |
/* { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = __builtin_GOMP_alloc \\(256, 20, 0B\\);" 1 "gimple" } } */ |
| 50 |
/* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(D\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */ |
| 51 |
|
| 52 |
if (((intptr_t) B) % 64 != 0) |
| 53 |
__builtin_abort (); |
| 54 |
if (((intptr_t) C) % 64 != 0) |
| 55 |
__builtin_abort (); |
| 56 |
if (((intptr_t) D) % 64 != 0) |
| 57 |
__builtin_abort (); |
| 58 |
|
| 59 |
for (int i = 0; i < 5; ++i) |
| 60 |
{ |
| 61 |
if (C[i] != i+1) |
| 62 |
__builtin_abort (); |
| 63 |
if (D[i] != i+1 + 10*(i+1)) |
| 64 |
__builtin_abort (); |
| 65 |
} |
| 66 |
|
| 67 |
for (int i = 0; i < n; ++i) |
| 68 |
{ |
| 69 |
if (B[i] != 0) |
| 70 |
__builtin_abort (); |
| 71 |
sum += A[i]+B[i]+C[i%5]+D[i%5]; |
| 72 |
} |
| 73 |
} |
| 74 |
omp_destroy_allocator (my_allocator); |
| 75 |
return sum; |
| 76 |
} |
| 77 |
|
| 78 |
int |
| 79 |
main () |
| 80 |
{ |
| 81 |
if (one () != 1200) |
| 82 |
__builtin_abort (); |
| 83 |
return 0; |
| 84 |
} |