| 1 |
/* Offloaded 'constructor' and 'destructor' functions, and C++ objects construction and destruction. */ |
| 2 |
|
| 3 |
/* { dg-require-effective-target init_priority } */ |
| 4 |
|
| 5 |
/* { dg-additional-options -fdump-tree-optimized-raw-asmname } |
| 6 |
{ dg-additional-options -foffload-options=-fdump-tree-optimized-raw-asmname } */ |
| 7 |
|
| 8 |
#include <omp.h> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#pragma omp declare target |
| 12 |
|
| 13 |
struct S |
| 14 |
{ |
| 15 |
int x; |
| 16 |
|
| 17 |
S() |
| 18 |
: x(-1) |
| 19 |
{ |
| 20 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 21 |
} |
| 22 |
S(int x) |
| 23 |
: x(x) |
| 24 |
{ |
| 25 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 26 |
} |
| 27 |
~S() |
| 28 |
{ |
| 29 |
__builtin_printf("%s, %d, %d\n", __FUNCTION__, x, omp_is_initial_device()); |
| 30 |
} |
| 31 |
}; |
| 32 |
|
| 33 |
#pragma omp end declare target |
| 34 |
|
| 35 |
S sH1 __attribute__((init_priority(1500))) (7); |
| 36 |
|
| 37 |
#pragma omp declare target |
| 38 |
|
| 39 |
S sHD1 __attribute__((init_priority(2000))) (5); |
| 40 |
|
| 41 |
std::vector<S> svHD1 __attribute__((init_priority(1000))) (2); |
| 42 |
|
| 43 |
static void |
| 44 |
__attribute__((constructor(20000))) |
| 45 |
initDH1() |
| 46 |
{ |
| 47 |
__builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device()); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
__attribute__((destructor(20000))) |
| 52 |
finiDH1() |
| 53 |
{ |
| 54 |
__builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device()); |
| 55 |
} |
| 56 |
|
| 57 |
#pragma omp end declare target |
| 58 |
|
| 59 |
S sH2 __attribute__((init_priority(500))) (3); |
| 60 |
|
| 61 |
static void |
| 62 |
__attribute__((constructor(10000))) |
| 63 |
initH1() |
| 64 |
{ |
| 65 |
__builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device()); |
| 66 |
} |
| 67 |
|
| 68 |
static void |
| 69 |
__attribute__((destructor(10000))) |
| 70 |
finiH1() |
| 71 |
{ |
| 72 |
__builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device()); |
| 73 |
} |
| 74 |
|
| 75 |
int main() |
| 76 |
{ |
| 77 |
int c = 0; |
| 78 |
|
| 79 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 80 |
|
| 81 |
#pragma omp target map(c) |
| 82 |
{ |
| 83 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 84 |
} |
| 85 |
|
| 86 |
#pragma omp target map(c) |
| 87 |
{ |
| 88 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 89 |
} |
| 90 |
|
| 91 |
__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device()); |
| 92 |
|
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
/* Verify '__cxa_atexit' calls (or '__aeabi_atexit', per 'targetm.cxx.use_aeabi_atexit'). |
| 97 |
|
| 98 |
For the host, there are four expected calls: |
| 99 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, } 4 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 100 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, } 4 optimized { target { cxa_atexit && arm_eabi } } } } |
| 101 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sH1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 102 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sH1, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 103 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sHD1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 104 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sHD1, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 105 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZNSt6vectorI1SSaIS0_EED1Ev, \&svHD1, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 106 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&svHD1, _ZNSt6vectorI1SSaIS0_EED1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 107 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sH2, \&__dso_handle>} 1 optimized { target { cxa_atexit && { ! arm_eabi } } } } } |
| 108 |
{ dg-final { scan-tree-dump-times {gimple_call <__aeabi_atexit, NULL, \&sH2, _ZN1SD1Ev, \&__dso_handle>} 1 optimized { target { cxa_atexit && arm_eabi } } } } |
| 109 |
|
| 110 |
For the device, there are two expected calls: |
| 111 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, } 2 optimized { target cxa_atexit } } } |
| 112 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZN1SD1Ev, \&sHD1, \&__dso_handle>} 1 optimized { target cxa_atexit } } } |
| 113 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_atexit, NULL, _ZNSt6vectorI1SSaIS0_EED1Ev, \&svHD1, \&__dso_handle>} 1 optimized { target cxa_atexit } } } |
| 114 |
*/ |
| 115 |
|
| 116 |
/* Defined order in which 'constructor' functions, and 'destructor' functions are run, and C++ objects are constructed (..., and destructed in reverse order). |
| 117 |
{ dg-output {S, 3, 1[\r\n]+} } |
| 118 |
{ dg-output {S, -1, 1[\r\n]+} } |
| 119 |
{ dg-output {S, -1, 1[\r\n]+} } |
| 120 |
{ dg-output {S, 7, 1[\r\n]+} } |
| 121 |
{ dg-output {S, 5, 1[\r\n]+} } |
| 122 |
{ dg-output {initH1, 1[\r\n]+} } |
| 123 |
{ dg-output {initDH1, 1[\r\n]+} } |
| 124 |
{ dg-output {main:1, 1[\r\n]+} } |
| 125 |
{ dg-output {S, -1, 0[\r\n]+} { target offload_device } } |
| 126 |
{ dg-output {S, -1, 0[\r\n]+} { target offload_device } } |
| 127 |
{ dg-output {S, 5, 0[\r\n]+} { target offload_device } } |
| 128 |
{ dg-output {initDH1, 0[\r\n]+} { target offload_device } } |
| 129 |
{ dg-output {main:2, 1[\r\n]+} { target { ! offload_device } } } |
| 130 |
{ dg-output {main:2, 0[\r\n]+} { target offload_device } } |
| 131 |
{ dg-output {main:3, 1[\r\n]+} { target { ! offload_device } } } |
| 132 |
{ dg-output {main:3, 0[\r\n]+} { target offload_device } } |
| 133 |
{ dg-output {main:4, 1[\r\n]+} } |
| 134 |
{ dg-output {~S, 5, 0[\r\n]+} { target offload_device } } |
| 135 |
{ dg-output {~S, -1, 0[\r\n]+} { target offload_device } } |
| 136 |
{ dg-output {~S, -1, 0[\r\n]+} { target offload_device } } |
| 137 |
{ dg-output {finiDH1, 0[\r\n]+} { target offload_device } } |
| 138 |
{ dg-output {~S, 5, 1[\r\n]+} } |
| 139 |
{ dg-output {~S, 7, 1[\r\n]+} } |
| 140 |
{ dg-output {~S, -1, 1[\r\n]+} } |
| 141 |
{ dg-output {~S, -1, 1[\r\n]+} } |
| 142 |
{ dg-output {~S, 3, 1[\r\n]+} } |
| 143 |
{ dg-output {finiDH1, 1[\r\n]+} } |
| 144 |
{ dg-output {finiH1, 1[\r\n]+} } |
| 145 |
*/ |