Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / distribute_parallel_for_simd_ast_print.cpp
blob94ba8494d7126ebb3b3cc46cc62fd9e434c81789
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
11 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP45
12 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
13 // 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
14 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix CHECK --check-prefix OMP50
15 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
16 // 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
17 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix CHECK --check-prefix OMP51
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
19 // 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
20 // expected-no-diagnostics
22 #ifndef HEADER
23 #define HEADER
25 struct S {
26 S(): a(0) {}
27 S(int v) : a(v) {}
28 int a;
29 typedef int type;
32 template <typename T>
33 class S7 : public T {
34 protected:
35 T a;
36 S7() : a(0) {}
38 public:
39 S7(typename T::type v) : a(v) {
40 #pragma omp target
41 #pragma omp teams
42 #pragma omp distribute parallel for simd private(a) private(this->a) private(T::a)
43 for (int k = 0; k < a.a; ++k)
44 ++this->a.a;
46 S7 &operator=(S7 &s) {
47 int k;
48 #pragma omp target
49 #pragma omp teams
50 #pragma omp distribute parallel for simd private(a) private(this->a) linear(k)
51 for (k = 0; k < s.a.a; ++k)
52 ++s.a.a;
53 return *this;
57 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(T::a){{$}}
58 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) linear(k)
59 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(this->S::a)
61 class S8 : public S7<S> {
62 S8() {}
64 public:
65 S8(int v) : S7<S>(v){
66 #pragma omp target
67 #pragma omp teams
68 #pragma omp distribute parallel for simd private(a) private(this->a) private(S7<S>::a)
69 for (int k = 0; k < a.a; ++k)
70 ++this->a.a;
72 S8 &operator=(S8 &s) {
73 #pragma omp target
74 #pragma omp teams
75 #pragma omp distribute parallel for simd private(a) private(this->a)
76 for (int k = 0; k < s.a.a; ++k)
77 ++s.a.a;
78 return *this;
82 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(this->S7<S>::a)
83 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a)
85 template <class T, int N>
86 T tmain(T argc) {
87 T b = argc, c, d, e, f, h;
88 static T a;
89 // CHECK: static T a;
90 static T g;
91 #pragma omp threadprivate(g)
92 #pragma omp target
93 #pragma omp teams
94 #pragma omp distribute parallel for simd dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
95 // CHECK: #pragma omp distribute parallel for simd dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
96 for (int i = 0; i < 2; ++i)
97 a = 2;
98 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
99 // CHECK-NEXT: a = 2;
100 #pragma omp target
101 #pragma omp teams
102 #pragma omp distribute parallel for simd allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
103 for (int i = 0; i < 2; ++i)
104 for (int j = 0; j < 2; ++j)
105 for (int j = 0; j < 2; ++j)
106 for (int j = 0; j < 2; ++j)
107 for (int j = 0; j < 2; ++j)
108 for (int i = 0; i < 2; ++i)
109 for (int j = 0; j < 2; ++j)
110 for (int j = 0; j < 2; ++j)
111 for (int j = 0; j < 2; ++j)
112 for (int j = 0; j < 2; ++j)
113 a++;
114 // CHECK: #pragma omp distribute parallel for simd allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
115 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
116 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
117 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
118 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
119 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
120 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
121 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
122 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
123 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
124 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
125 // CHECK-NEXT: a++;
126 return T();
129 int main(int argc, char **argv) {
130 int b = argc, c, d, e, f, h;
131 int x[200];
132 static int a;
133 // CHECK: static int a;
134 static float g;
135 #pragma omp threadprivate(g)
136 #pragma omp target
137 #pragma omp teams
138 #pragma omp distribute parallel for simd schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
139 // CHECK: #pragma omp distribute parallel for simd schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
140 for (int i = 0; i < 2; ++i)
141 a = 2;
142 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
143 // CHECK-NEXT: a = 2;
144 #pragma omp target
145 #pragma omp teams
146 #pragma omp distribute parallel for simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
147 for (int i = 0; i < 10; ++i)
148 for (int j = 0; j < 10; ++j)
149 a++;
150 // CHECK: #pragma omp distribute parallel for simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
151 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
152 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
153 // CHECK-NEXT: a++;
155 int i;
156 #pragma omp target
157 #pragma omp teams
158 #ifdef OMP51
159 #pragma omp distribute parallel for simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc, c, d) order(unconstrained:concurrent)
160 #elif OMP5
161 #pragma omp distribute parallel for simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc, c, d) order(concurrent)
162 #else
163 #pragma omp distribute parallel for simd aligned(x:8) linear(i:2) safelen(8) simdlen(8)
164 #endif // OMP51
165 for (i = 0; i < 100; i++)
166 for (int j = 0; j < 200; j++)
167 a += h + x[j];
168 // OMP45: #pragma omp distribute parallel for simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8)
169 // OMP50: #pragma omp distribute parallel for simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc,c,d) order(concurrent)
170 // OMP51: #pragma omp distribute parallel for simd aligned(x: 8) linear(i: step(2)) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc,c,d) order(unconstrained: concurrent)
171 // CHECK-NEXT: for (i = 0; i < 100; i++)
172 // CHECK-NEXT: for (int j = 0; j < 200; j++)
173 // CHECK-NEXT: a += h + x[j];
175 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
178 #endif