Debian Codegraph @

libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C

raw
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 // { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target offload_target_amdgcn } } }
26 // { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump "v1\\._x = 5;" "optimized" { target offload_target_amdgcn } } }
27 // { dg-final { only_for_offload_target nvptx-none scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target offload_target_nvptx } } }
28 // { dg-final { only_for_offload_target nvptx-none scan-offload-tree-dump "v1\\._x = 5;" "optimized" { target offload_target_nvptx } } }
29
30 #include <cassert>
31 #include <omp.h>
32
33 #pragma omp declare target
34
35 struct str {
36 str(int x) : _x(x) { }
37 int add(str o) { return _x + o._x; }
38 int _x;
39 } v1(5);
40
41 #pragma omp end declare target
42
43 void check_host()
44 {
45 assert (v1._x == 5);
46 }
47
48 void check_devs()
49 {
50 for (int dev = omp_initial_device; dev <= omp_get_num_devices(); dev++)
51 {
52 int res = 99, dev_num = 98;
53 #pragma omp target map(from: res, dev_num) device(dev)
54 {
55 res = v1._x;
56 dev_num = omp_get_device_num();
57 }
58 assert (res == 5);
59 if (dev == omp_initial_device)
60 assert (dev_num == omp_get_num_devices());
61 else
62 assert (dev_num == dev);
63 }
64 }
65
66 int main()
67 {
68 int res = -1;
69 str v2(2);
70
71 #pragma omp target map(from:res)
72 {
73 res = v1.add(v2);
74 }
75
76 assert (res == 7);
77 check_host();
78 check_devs();
79
80 return 0;
81 }