| 1 |
/* Offloaded C++ objects construction and destruction. */ |
| 2 |
|
| 3 |
/* { dg-additional-options -fdump-tree-optimized-raw-asmname } |
| 4 |
{ dg-additional-options -foffload-options=-fdump-tree-optimized-raw-asmname } */ |
| 5 |
|
| 6 |
#include <omp.h> |
| 7 |
#include <vector> |
| 8 |
|
| 9 |
#pragma omp declare target |
| 10 |
|
| 11 |
struct S |
| 12 |
{ |
| 13 |
int x; |
| 14 |
|
| 15 |
S() |
| 16 |
: x(-1) |
| 17 |
{ |
| 18 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 19 |
} |
| 20 |
S(int x) |
| 21 |
: x(x) |
| 22 |
{ |
| 23 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 24 |
} |
| 25 |
~S() |
| 26 |
{ |
| 27 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
#pragma omp end declare target |
| 32 |
|
| 33 |
S sH1(7); |
| 34 |
|
| 35 |
#pragma omp declare target |
| 36 |
|
| 37 |
S sHD1(5); |
| 38 |
|
| 39 |
std::vector<S> svHD1(2); |
| 40 |
|
| 41 |
#pragma omp end declare target |
| 42 |
|
| 43 |
S sH2(3); |
| 44 |
|
| 45 |
int main() |
| 46 |
{ |
| 47 |
int c = 0; |
| 48 |
|
| 49 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 50 |
|
| 51 |
#pragma omp target map(c) |
| 52 |
{ |
| 53 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 54 |
} |
| 55 |
|
| 56 |
#pragma omp target map(c) |
| 57 |
{ |
| 58 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 59 |
} |
| 60 |
|
| 61 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 62 |
|
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
/* Verify '__cxa_atexit' calls (or '__aeabi_atexit', per 'targetm.cxx.use_aeabi_atexit'). |
| 67 |
|
| 68 |
For the host, there are four expected calls: |
| 69 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, } 4 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 70 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, } 4 optimized { target { cxa_atexit && arm_eabi } } } } |
| 71 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sH1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 72 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sH1, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 73 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sHD1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 74 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sHD1, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 75 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZNSt6vectorI1SSaIS0_EED1Ev, \&svHD1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 76 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&svHD1, _ZNSt6vectorI1SSaIS0_EED1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 77 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sH2, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 78 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sH2, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 79 |
|
| 80 |
For the device, there are two expected calls: |
| 81 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, } 2 optimized { target cxa_atexit } } } |
| 82 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sHD1, \&__dso_handle>} 1 optimized { target cxa_atexit } } } |
| 83 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZNSt6vectorI1SSaIS0_EED1Ev, \&svHD1, \&__dso_handle>} 1 optimized { target cxa_atexit } } } |
| 84 |
*/ |
| 85 |
|
| 86 |
/* C++ objects are constructed in order of appearance (..., and destructed in reverse order). |
| 87 |
{ dg-output {S, 7, 1[\r\n]+} } |
| 88 |
{ dg-output {S, 5, 1[\r\n]+} } |
| 89 |
{ dg-output {S, -1, 1[\r\n]+} } |
| 90 |
{ dg-output {S, -1, 1[\r\n]+} } |
| 91 |
{ dg-output {S, 3, 1[\r\n]+} } |
| 92 |
{ dg-output {main:1, 1[\r\n]+} } |
| 93 |
{ dg-output {S, 5, 0[\r\n]+} { target offload_device } } |
| 94 |
{ dg-output {S, -1, 0[\r\n]+} { target offload_device } } |
| 95 |
{ dg-output {S, -1, 0[\r\n]+} { target offload_device } } |
| 96 |
{ dg-output {main:2, 1[\r\n]+} { target { ! offload_device } } } |
| 97 |
{ dg-output {main:2, 0[\r\n]+} { target offload_device } } |
| 98 |
{ dg-output {main:3, 1[\r\n]+} { target { ! offload_device } } } |
| 99 |
{ dg-output {main:3, 0[\r\n]+} { target offload_device } } |
| 100 |
{ dg-output {main:4, 1[\r\n]+} } |
| 101 |
{ dg-output {~S, -1, 0[\r\n]+} { target offload_device } } |
| 102 |
{ dg-output {~S, -1, 0[\r\n]+} { target offload_device } } |
| 103 |
{ dg-output {~S, 5, 0[\r\n]+} { target offload_device } } |
| 104 |
{ dg-output {~S, 3, 1[\r\n]+} } |
| 105 |
{ dg-output {~S, -1, 1[\r\n]+} } |
| 106 |
{ dg-output {~S, -1, 1[\r\n]+} } |
| 107 |
{ dg-output {~S, 5, 1[\r\n]+} } |
| 108 |
{ dg-output {~S, 7, 1[\r\n]+} } |
| 109 |
*/ |