1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
10
11 #ifndef HEADER
12 #define HEADER
13
14 // CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
15 extern int n;
16 int a[10], b[10], c[10], d[10];
17 void foo();
18
19 // CHECK-LABEL:bar
bar()20 void bar() {
21 int i,j;
22 // CHECK: call void @__kmpc_doacross_init(
23 // CHECK: call void @__kmpc_doacross_fini(
24 #pragma omp parallel for ordered(2)
25 for (i = 0; i < n; ++i)
26 for (j = 0; j < n; ++j)
27 a[i] = b[i] + 1;
28 // CHECK: call void @__kmpc_doacross_init(
29 // CHECK: call void @__kmpc_doacross_fini(
30 #pragma omp for collapse(2) ordered(2)
31 for (int i = 0; i < n; i++)
32 for (int j = 0; j < n; j++)
33 ;
34 }
35
36 // CHECK-LABEL: @main()
main()37 int main() {
38 int i;
39 // CHECK: [[DIMS:%.+]] = alloca [1 x [[KMP_DIM]]],
40 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
41 // CHECK: icmp
42 // CHECK-NEXT: br i1 %
43 // CHECK: [[CAST:%.+]] = bitcast [1 x [[KMP_DIM]]]* [[DIMS]] to i8*
44 // CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 [[CAST]], i8 0, i64 24, i1 false)
45 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], [1 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
46 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 1
47 // CHECK: store i64 %{{.+}}, i64* %
48 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 2
49 // CHECK: store i64 1, i64* %
50 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], [1 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
51 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIM]] to i8*
52 // CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
53 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* @{{.+}}, i32 [[GTID]], i32 33, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
54 #pragma omp for ordered(1)
55 for (int i = 0; i < n; ++i) {
56 a[i] = b[i] + 1;
57 foo();
58 // CHECK: invoke void [[FOO:.+]](
59 // CHECK: load i32, i32* [[I:%.+]],
60 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
61 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
62 // CHECK-NEXT: sext i32 %{{.+}} to i64
63 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT:%.+]], i64 0, i64 0
64 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
65 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT]], i64 0, i64 0
66 // CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
67 #pragma omp ordered depend(source)
68 c[i] = c[i] + 1;
69 foo();
70 // CHECK: invoke void [[FOO]]
71 // CHECK: load i32, i32* [[I]],
72 // CHECK-NEXT: sub nsw i32 %{{.+}}, 2
73 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
74 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
75 // CHECK-NEXT: sext i32 %{{.+}} to i64
76 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT:%.+]], i64 0, i64 0
77 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
78 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT]], i64 0, i64 0
79 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
80 #pragma omp ordered depend(sink : i - 2)
81 d[i] = a[i - 2];
82 }
83 // CHECK: landingpad
84 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
85 // CHECK: br label %
86
87 // CHECK: call void @__kmpc_for_static_fini(
88 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
89 // CHECK: ret i32 0
90 return 0;
91 }
92
93 // CHECK-LABEL: main1
main1()94 int main1() {
95 // CHECK: [[DIMS:%.+]] = alloca [1 x [[KMP_DIM]]],
96 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
97 // CHECK: icmp
98 // CHECK-NEXT: br i1 %
99 // CHECK: [[CAST:%.+]] = bitcast [1 x [[KMP_DIM]]]* [[DIMS]] to i8*
100 // CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 [[CAST]], i8 0, i64 24, i1 false)
101 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], [1 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
102 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 1
103 // CHECK: store i64 %{{.+}}, i64* %
104 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 2
105 // CHECK: store i64 1, i64* %
106 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], [1 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
107 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIM]] to i8*
108 // CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
109 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* @{{.+}}, i32 [[GTID]], i32 33, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
110 #pragma omp for ordered(1)
111 for (int i = n; i > 0; --i) {
112 a[i] = b[i] + 1;
113 foo();
114 // CHECK: invoke void [[FOO:.+]](
115 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB:%.+]],
116 // CHECK-NEXT: [[I_VAL:%.+]] = load i32, i32* [[I:%.+]],
117 // CHECK-NEXT: sub i32 [[UB_VAL]], [[I_VAL]]
118 // CHECK-NEXT: udiv i32 %{{.+}}, 1
119 // CHECK-NEXT: zext i32 %{{.+}} to i64
120 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT:%.+]], i64 0, i64 0
121 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
122 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT]], i64 0, i64 0
123 // CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
124 #pragma omp ordered depend(source)
125 c[i] = c[i] + 1;
126 foo();
127 // CHECK: invoke void [[FOO]]
128 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
129 // CHECK-NEXT: [[I_VAL:%.+]] = load i32, i32* [[I]],
130 // CHECK-NEXT: [[SUB:%.+]] = sub nsw i32 [[I_VAL]], 2
131 // CHECK-NEXT: sub i32 [[UB_VAL]], [[SUB]]
132 // CHECK-NEXT: udiv i32 %{{.+}}, 1
133 // CHECK-NEXT: zext i32 %{{.+}} to i64
134 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT:%.+]], i64 0, i64 0
135 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
136 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], [1 x i64]* [[CNT]], i64 0, i64 0
137 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
138 #pragma omp ordered depend(sink : i - 2)
139 d[i] = a[i - 2];
140 }
141 // CHECK: landingpad
142 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
143 // CHECK: br label %
144
145 // CHECK: call void @__kmpc_for_static_fini(
146 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
147 // CHECK: ret i32 0
148 return 0;
149 }
150
151 // CHECK: define {{.+}}TestStruct
152 template <typename T>
153 struct TestStruct {
154 static const int M = 10;
155 static const int N = 20;
156 T i;
157 T a[N][M];
158 T b[N][M];
159 T foo(T, T);
160 T bar(T, T, T);
161 void baz(T, T);
TestStructTestStruct162 TestStruct() {
163 // CHECK: [[DIMS:%.+]] = alloca [2 x [[KMP_DIM]]],
164 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
165 // CHECK: [[CAST:%.+]] = bitcast [2 x [[KMP_DIM]]]* [[DIMS]] to i8*
166 // CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 [[CAST]], i8 0, i64 48, i1 false)
167 // CHECK: [[DIM:%.+]] = getelementptr inbounds [2 x [[KMP_DIM]]], [2 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
168 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 1
169 // CHECK: store i64 10, i64* %
170 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 2
171 // CHECK: store i64 1, i64* %
172 // CHECK: [[DIM:%.+]] = getelementptr inbounds [2 x [[KMP_DIM]]], [2 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 1
173 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 1
174 // CHECK: store i64 %{{.+}}, i64* %
175 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIM]], i32 0, i32 2
176 // CHECK: store i64 1, i64* %
177 // CHECK: [[DIM:%.+]] = getelementptr inbounds [2 x [[KMP_DIM]]], [2 x [[KMP_DIM]]]* [[DIMS]], i64 0, i64 0
178 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIM]] to i8*
179 // CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 2, i8* [[CAST]])
180 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* @{{.+}}, i32 [[GTID]], i32 33, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
181 #pragma omp for ordered(2)
182 for (T j = 0; j < M; j++)
183 for (i = 0; i < n; i += 2) {
184 a[i][j] = foo(i, j);
185 // CHECK: invoke {{.+TestStruct.+foo}}
186 // CHECK: load i32*, i32** %
187 // CHECK: load i32, i32* %
188 // CHECK: load i32, i32* %
189 // CHECK: load i32, i32* [[J:%.+]],
190 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
191 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
192 // CHECK-NEXT: sext i32 %{{.+}} to i64
193 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT:%.+]], i64 0, i64 0
194 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
195 // CHECK-NEXT: [[I:%.+]] = load i32*, i32** [[I_REF:%.+]],
196 // CHECK-NEXT: load i32, i32* [[I]],
197 // CHECK-NEXT: sub nsw i32 %{{.+}}, 2
198 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
199 // CHECK-NEXT: sdiv i32 %{{.+}}, 2
200 // CHECK-NEXT: sext i32 %{{.+}} to i64
201 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 1
202 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
203 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 0
204 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
205 // CHECK-NEXT: load i32, i32* [[J:%.+]],
206 // CHECK-NEXT: sub nsw i32 %{{.+}}, 1
207 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
208 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
209 // CHECK-NEXT: sext i32 %{{.+}} to i64
210 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT:%.+]], i64 0, i64 0
211 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
212 // CHECK-NEXT: [[I:%.+]] = load i32*, i32** [[I_REF]],
213 // CHECK-NEXT: load i32, i32* [[I]],
214 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
215 // CHECK-NEXT: sdiv i32 %{{.+}}, 2
216 // CHECK-NEXT: sext i32 %{{.+}} to i64
217 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 1
218 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
219 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 0
220 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
221 #pragma omp ordered depend(sink : j, i - 2) depend(sink : j - 1, i)
222 b[i][j] = bar(a[i][j], b[i - 1][j], b[i][j - 1]);
223 // CHECK: invoke {{.+TestStruct.+bar}}
224 // CHECK: load i32*, i32** %
225 // CHECK: load i32, i32* %
226 // CHECK: load i32, i32* %
227 // CHECK: load i32, i32* [[J]],
228 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
229 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
230 // CHECK-NEXT: sext i32 %{{.+}} to i64
231 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT:%.+]], i64 0, i64 0
232 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
233 // CHECK-NEXT: [[I:%.+]] = load i32*, i32** [[I_REF]],
234 // CHECK-NEXT: load i32, i32* [[I]],
235 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
236 // CHECK-NEXT: sdiv i32 %{{.+}}, 2
237 // CHECK-NEXT: sext i32 %{{.+}} to i64
238 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 1
239 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP]],
240 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* [[CNT]], i64 0, i64 0
241 // CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
242 #pragma omp ordered depend(source)
243 baz(a[i][j], b[i][j]);
244 }
245 }
246 // CHECK: landingpad
247 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
248 // CHECK: br label %
249
250 // CHECK: call void @__kmpc_for_static_fini(
251 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
252 // CHECK: ret
253 };
254
255 TestStruct<int> s;
256 #endif // HEADER
257