Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / distribute_simd_ast_print.cpp
blobaed9d6376ef5880fb9e9d691652d2457a185c4f0
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
10 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ast-print %s -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
17 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
18 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
19 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
20 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
21 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
22 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
23 // expected-no-diagnostics
24 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ast-print %s -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
25 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
26 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
27 // expected-no-diagnostics
29 #ifndef HEADER
30 #define HEADER
32 struct S {
33 S(): a(0) {}
34 S(int v) : a(v) {}
35 int a;
36 typedef int type;
39 template <typename T>
40 class S7 : public T {
41 protected:
42 T a;
43 S7() : a(0) {}
45 public:
46 S7(typename T::type v) : a(v) {
47 #pragma omp target
48 #pragma omp teams
49 #pragma omp distribute simd private(a) private(this->a) private(T::a) allocate(T::a)
50 for (int k = 0; k < a.a; ++k)
51 ++this->a.a;
53 S7 &operator=(S7 &s) {
54 #pragma omp target
55 #pragma omp teams
56 #pragma omp distribute simd allocate(a) private(a) private(this->a)
57 for (int k = 0; k < s.a.a; ++k)
58 ++s.a.a;
59 return *this;
63 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(T::a) allocate(T::a){{$}}
64 // CHECK: #pragma omp distribute simd allocate(this->a) private(this->a) private(this->a)
65 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S::a) allocate(this->S::a)
67 class S8 : public S7<S> {
68 S8() {}
70 public:
71 S8(int v) : S7<S>(v){
72 #pragma omp target
73 #pragma omp teams
74 #pragma omp distribute simd private(a) private(this->a) private(S7<S>::a)
75 for (int k = 0; k < a.a; ++k)
76 ++this->a.a;
78 S8 &operator=(S8 &s) {
79 #pragma omp target
80 #pragma omp teams
81 #pragma omp distribute simd private(a) private(this->a)
82 for (int k = 0; k < s.a.a; ++k)
83 ++s.a.a;
84 return *this;
88 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S7<S>::a)
89 // CHECK: #pragma omp distribute simd private(this->a) private(this->a)
91 template <class T, int N>
92 T tmain(T argc) {
93 T b = argc, c, d, e, f, h;
94 static T a;
95 // CHECK: static T a;
96 static T g;
97 #pragma omp threadprivate(g)
99 #pragma omp target
100 #pragma omp teams
101 #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
102 for (int i = 0; i < 2; ++i)
103 a = 2;
104 // CHECK: #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
105 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
106 // CHECK-NEXT: a = 2;
108 #pragma omp target
109 #pragma omp teams
110 #pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) reduction(+ : h) dist_schedule(static,N)
111 for (int i = 0; i < 2; ++i)
112 for (int j = 0; j < 2; ++j)
113 for (int k = 0; k < 10; ++k)
114 for (int m = 0; m < 10; ++m)
115 for (int n = 0; n < 10; ++n)
116 a++;
117 // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) reduction(+: h) dist_schedule(static, N)
118 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
119 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
120 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
121 // CHECK-NEXT: for (int m = 0; m < 10; ++m)
122 // CHECK-NEXT: for (int n = 0; n < 10; ++n)
123 // CHECK-NEXT: a++;
124 return T();
127 int main(int argc, char **argv) {
128 int b = argc, c, d, e, f, h;
129 int x[200];
130 static int a;
131 // CHECK: static int a;
132 static float g;
133 #pragma omp threadprivate(g)
135 #pragma omp target
136 #pragma omp teams
137 #pragma omp distribute simd dist_schedule(static, a) private(a)
138 for (int i = 0; i < 2; ++i)
139 a = 2;
140 // CHECK: #pragma omp distribute simd dist_schedule(static, a) private(a)
141 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
142 // CHECK-NEXT: a = 2;
144 #pragma omp target
145 #pragma omp teams
146 #ifdef OMP5
147 #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b) if(simd:argc)
148 #else
149 #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b)
150 #endif // OMP5
151 for (int i = 0; i < 10; ++i)
152 for (int j = 0; j < 10; ++j)
153 a++;
154 // OMP45: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b)
155 // OMP50: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b) if(simd: argc)
156 // OMP51: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b)
157 // OMP52: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b)
158 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
159 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
160 // CHECK-NEXT: a++;
162 int i;
163 #pragma omp target
164 #pragma omp teams
165 #ifdef OMP52
166 #pragma omp distribute simd aligned(x:8) linear(i: step(2)) safelen(8) simdlen(8) if(argc) nontemporal(argc, c, d) order(reproducible:concurrent)
167 #elif OMP51
168 #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(argc) nontemporal(argc, c, d) order(reproducible:concurrent)
169 #elif OMP5
170 #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(argc) nontemporal(argc, c, d) order(concurrent)
171 #else
172 #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8)
173 #endif // OMP51
174 for (i = 0; i < 100; i++)
175 for (int j = 0; j < 200; j++)
176 a += h + x[j];
177 // OMP45: #pragma omp distribute simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8)
178 // OMP50: #pragma omp distribute simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8) if(argc) nontemporal(argc,c,d) order(concurrent)
179 // OMP51: #pragma omp distribute simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8) if(argc) nontemporal(argc,c,d) order(reproducible: concurrent)
180 // OMP52: #pragma omp distribute simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8) if(argc) nontemporal(argc,c,d) order(reproducible: concurrent)
181 // CHECK-NEXT: for (i = 0; i < 100; i++)
182 // CHECK-NEXT: for (int j = 0; j < 200; j++)
183 // CHECK-NEXT: a += h + x[j];
185 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
188 #endif