Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_for_ast_print.cpp
blobdf5e7596f6a90512b2071df0ca0fa9ca195aac2d
1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ast-print %s -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
11 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
13 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
17 // expected-no-diagnostics
18 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ast-print %s -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
20 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
21 // expected-no-diagnostics
23 #ifndef HEADER
24 #define HEADER
26 void foo() {}
28 struct S {
29 S(): a(0) {}
30 S(int v) : a(v) {}
31 int a;
32 typedef int type;
35 template <typename T>
36 class S7 : public T {
37 protected:
38 T a;
39 S7() : a(0) {}
41 public:
42 S7(typename T::type v) : a(v) {
43 #pragma omp parallel for private(a) private(this->a) private(T::a)
44 for (int k = 0; k < a.a; ++k)
45 ++this->a.a;
47 S7 &operator=(S7 &s) {
48 #pragma omp parallel for private(a) private(this->a)
49 for (int k = 0; k < s.a.a; ++k)
50 ++s.a.a;
51 return *this;
55 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(T::a){{$}}
56 // CHECK: #pragma omp parallel for private(this->a) private(this->a)
57 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(this->S::a)
59 class S8 : public S7<S> {
60 S8() {}
62 public:
63 S8(int v) : S7<S>(v){
64 #pragma omp parallel for private(a) private(this->a) private(S7<S>::a)
65 for (int k = 0; k < a.a; ++k)
66 ++this->a.a;
68 S8 &operator=(S8 &s) {
69 #pragma omp parallel for private(a) private(this->a)
70 for (int k = 0; k < s.a.a; ++k)
71 ++s.a.a;
72 return *this;
76 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(this->S7<S>::a)
77 // CHECK: #pragma omp parallel for private(this->a) private(this->a)
79 template <class T, int N>
80 T tmain(T argc) {
81 T b = argc, c, d, e, f, h;
82 static T a;
83 // CHECK: static T a;
84 static T g;
85 #pragma omp threadprivate(g)
86 #if defined(OMP51) || defined(OMP52)
87 #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) allocate(a) lastprivate(conditional: d, e,f) order(reproducible:concurrent)
88 #else
89 #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) allocate(a) lastprivate(conditional: d, e,f) order(concurrent)
90 #endif // OMP51
91 // OMP50: #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) allocate(a) lastprivate(conditional: d,e,f) order(concurrent)
92 // OMP51: #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) allocate(a) lastprivate(conditional: d,e,f) order(reproducible: concurrent)
93 // OMP52: #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) allocate(a) lastprivate(conditional: d,e,f) order(reproducible: concurrent)
94 for (int i = 0; i < 2; ++i)
95 a = 2;
96 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
97 // CHECK-NEXT: a = 2;
98 #pragma omp parallel for allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h)
99 for (int i = 0; i < 2; ++i)
100 for (int j = 0; j < 2; ++j)
101 for (int j = 0; j < 2; ++j)
102 for (int j = 0; j < 2; ++j)
103 for (int j = 0; j < 2; ++j)
104 for (int i = 0; i < 2; ++i)
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 j = 0; j < 2; ++j)
109 foo();
110 // CHECK-NEXT: #pragma omp parallel for allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h)
111 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
112 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
113 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
114 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
115 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
116 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
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 j = 0; j < 2; ++j)
121 // CHECK-NEXT: foo();
122 return T();
125 int increment () {
126 #pragma omp for
127 for (int i = 5 ; i != 0; ++i)
129 // CHECK: int increment() {
130 // CHECK-NEXT: #pragma omp for
131 // CHECK-NEXT: for (int i = 5; i != 0; ++i)
132 // CHECK-NEXT: ;
133 return 0;
136 int decrement_nowait () {
137 #pragma omp for nowait
138 for (int j = 5 ; j != 0; --j)
140 // CHECK: int decrement_nowait() {
141 // CHECK-NEXT: #pragma omp for nowait
142 // CHECK-NEXT: for (int j = 5; j != 0; --j)
143 // CHECK-NEXT: ;
144 return 0;
148 int main(int argc, char **argv) {
149 int b = argc, c, d, e, f, h;
150 static int a;
151 // CHECK: static int a;
152 static float g;
153 #pragma omp threadprivate(g)
154 #pragma omp parallel for schedule(guided, argc) default(none) copyin(g) linear(a) shared(argc) reduction(task,&:d)
155 // CHECK: #pragma omp parallel for schedule(guided, argc) default(none) copyin(g) linear(a) shared(argc) reduction(task, &: d)
156 for (int i = 0; i < 2; ++i)
157 a = 2;
158 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
159 // CHECK-NEXT: a = 2;
160 #ifdef OMP52
161 #pragma omp parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a: step(-5))
162 #else
163 #pragma omp parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a:-5)
164 #endif
165 for (int i = 0; i < 10; ++i)
166 for (int j = 0; j < 10; ++j)
167 foo();
168 // CHECK-NEXT: #pragma omp parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) linear(a: step(-5))
169 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
170 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
171 // CHECK-NEXT: foo();
172 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
175 #endif