| 1 |
// { dg-do run } |
| 2 |
// { dg-additional-options "-fdump-tree-gimple -fdump-tree-optimized" } |
| 3 |
// { dg-additional-options -foffload-options=-fdump-tree-optimized { target { offload_target_nvptx || offload_target_amdgcn } } } |
| 4 |
|
| 5 |
// { dg-final { scan-tree-dump-times "omp_is_initial_device" 1 "gimple" } } |
| 6 |
// { dg-final { scan-tree-dump-times "_GLOBAL__off_I_v1" 1 "gimple" } } |
| 7 |
// { dg-final { scan-tree-dump-times "__omp_target_static_init_and_destruction" 2 "gimple" } } |
| 8 |
// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare target nohost" 2 "gimple" } } |
| 9 |
|
| 10 |
// { dg-final { scan-tree-dump-not "omp_is_initial_device" "optimized" } } |
| 11 |
// { dg-final { scan-tree-dump-not "__omp_target_static_init_and_destruction" "optimized" } } |
| 12 |
|
| 13 |
// (A) No offloading configured: The symbols aren't present |
| 14 |
// Caveat: They are present with -foffload=disable - or offloading |
| 15 |
// configured but none of the optional offload packages/binaries installed. |
| 16 |
// But the 'offload_target_any' check cannot distinguish those |
| 17 |
// { dg-final { scan-tree-dump-not "void _GLOBAL__off_I_v1" "optimized" { target { ! offload_target_any } } } } |
| 18 |
// { dg-final { scan-tree-dump-not "__attribute__\\(\\(\[^\n\r]*omp declare target nohost" "optimized" { target { ! offload_target_any } } } } |
| 19 |
|
| 20 |
// (B) With offload configured (and compiling for an offload target) |
| 21 |
// the symbols are present (missed optimization). Hence: FIXME. |
| 22 |
// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" { target offload_target_any } } } |
| 23 |
// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare target nohost" 1 "optimized" { target offload_target_any } } } |
| 24 |
|
| 25 |
|
| 26 |
// { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target offload_target_amdgcn } } } |
| 27 |
// { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump "v1\\._x = 5;" "optimized" { target offload_target_amdgcn } } } |
| 28 |
// { dg-final { only_for_offload_target nvptx-none scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target offload_target_nvptx } } } |
| 29 |
// { dg-final { only_for_offload_target nvptx-none scan-offload-tree-dump "v1\\._x = 5;" "optimized" { target offload_target_nvptx } } } |
| 30 |
|
| 31 |
|
| 32 |
#include <cassert> |
| 33 |
|
| 34 |
#pragma omp declare target |
| 35 |
|
| 36 |
template<typename T> |
| 37 |
struct str { |
| 38 |
str(T x) : _x(x) { } |
| 39 |
T add(str o) { return _x + o._x; } |
| 40 |
T _x; |
| 41 |
}; |
| 42 |
|
| 43 |
str<long> v1(5); |
| 44 |
|
| 45 |
#pragma omp end declare target |
| 46 |
|
| 47 |
int main() |
| 48 |
{ |
| 49 |
long res = -1; |
| 50 |
str<long> v2(2); |
| 51 |
|
| 52 |
#pragma omp target map(from:res) |
| 53 |
{ |
| 54 |
res = v1.add(v2); |
| 55 |
} |
| 56 |
|
| 57 |
assert (res == 7); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |