1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - -femit-all-decls -disable-llvm-passes | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s -femit-all-decls -disable-llvm-passes
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -femit-all-decls -disable-llvm-passes | FileCheck --check-prefix=CHECK-LOAD %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - -femit-all-decls -disable-llvm-passes | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s -femit-all-decls -disable-llvm-passes
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -femit-all-decls -disable-llvm-passes | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
14 // CHECK: [[SSS_INT:.+]] = type { i32 }
15 // CHECK-LOAD: [[SSS_INT:.+]] = type { i32 }
18 void add(short &out, short &in) {}
20 #pragma omp declare reduction(my_add : short : add(omp_out, omp_in))
22 // CHECK: define internal void @.
23 // CHECK: call void @{{.+}}add{{.+}}(
26 // CHECK: foo_reduction_array
27 void foo_reduction_array() {
29 // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
30 #pragma omp parallel for reduction(my_add : y)
31 for (int i = 0; i < 1; i++) {
35 // CHECK: define internal void @
37 #pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
38 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
39 // CHECK: [[MUL:%.+]] = mul nsw i32
40 // CHECK-NEXT: store i32 [[MUL]], i32*
41 // CHECK-NEXT: ret void
43 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
44 // CHECK-LOAD: [[MUL:%.+]] = mul nsw i32
45 // CHECK-LOAD-NEXT: store i32 [[MUL]], i32*
46 // CHECK-LOAD-NEXT: ret void
49 // CHECK: define internal {{.*}}void @{{[^(]+}}(i8* noalias, i8* noalias)
52 // CHECK: [[MUL:%.+]] = mul nsw i32
53 // CHECK-NEXT: [[TRUNC:%.+]] = trunc i32 [[MUL]] to i8
54 // CHECK-NEXT: store i8 [[TRUNC]], i8*
55 // CHECK-NEXT: ret void
58 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i8* noalias, i8* noalias)
59 // CHECK-LOAD: sext i8
60 // CHECK-LOAD: sext i8
61 // CHECK-LOAD: [[MUL:%.+]] = mul nsw i32
62 // CHECK-LOAD-NEXT: [[TRUNC:%.+]] = trunc i32 [[MUL]] to i8
63 // CHECK-LOAD-NEXT: store i8 [[TRUNC]], i8*
64 // CHECK-LOAD-NEXT: ret void
71 #pragma omp declare reduction(fun : T : omp_out ^= omp_in) initializer(omp_priv = 24 + omp_orig)
76 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
77 // CHECK: [[XOR:%.+]] = xor i32
78 // CHECK-NEXT: store i32 [[XOR]], i32*
79 // CHECK-NEXT: ret void
82 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
83 // CHECK: [[ADD:%.+]] = add nsw i32 24,
84 // CHECK-NEXT: store i32 [[ADD]], i32*
85 // CHECK-NEXT: ret void
88 // CHECK: define {{.*}}void [[INIT:@[^(]+]]([[SSS_INT]]*
89 // CHECK-LOAD: define {{.*}}void [[INIT:@[^(]+]]([[SSS_INT]]*
90 void init(SSS<int> &lhs, SSS<int> &rhs) {}
92 #pragma omp declare reduction(fun : SSS < int > : omp_out = omp_in) initializer(init(omp_priv, omp_orig))
93 // CHECK: define internal {{.*}}void @{{[^(]+}}([[SSS_INT]]* noalias, [[SSS_INT]]* noalias)
94 // CHECK: call void @llvm.memcpy
95 // CHECK-NEXT: ret void
97 // CHECK: define internal {{.*}}void @{{[^(]+}}([[SSS_INT]]* noalias, [[SSS_INT]]* noalias)
98 // CHECK: call {{.*}}void [[INIT]](
99 // CHECK-NEXT: ret void
102 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}([[SSS_INT]]* noalias, [[SSS_INT]]* noalias)
103 // CHECK-LOAD: call void @llvm.memcpy
104 // CHECK-LOAD-NEXT: ret void
105 // CHECK-LOAD-NEXT: }
106 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}([[SSS_INT]]* noalias, [[SSS_INT]]* noalias)
107 // CHECK-LOAD: call {{.*}}void [[INIT]](
108 // CHECK-LOAD-NEXT: ret void
109 // CHECK-LOAD-NEXT: }
111 template <typename T>
113 #pragma omp declare reduction(fun : T : omp_out += omp_in) initializer(omp_priv = 15 * omp_orig)
115 #pragma omp declare reduction(fun : T : omp_out /= omp_in) initializer(omp_priv = 11 - omp_orig)
121 void merge(const Summary& other) {}
124 template <typename K>
126 Summary global_summary;
127 #pragma omp declare reduction(+ : Summary : omp_out.merge(omp_in))
128 #pragma omp parallel for reduction(+ : global_summary)
129 for (int k = 1; k <= 100; ++k) {
136 // CHECK-LABEL: @main
140 #pragma omp parallel reduction(SSS < int > ::fun : i)
144 #pragma omp parallel reduction(::fun : sss)
147 #pragma omp declare reduction(fun : SSS < int > : init(omp_out, omp_in))
148 #pragma omp parallel reduction(fun : sss)
151 // CHECK: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
152 // CHECK: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
153 // CHECK: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call({{[^@]*}} @{{[^@]*}}[[REGION:@[^ ]+]]
160 // CHECK: define internal {{.*}}void [[REGION]](
161 // CHECK: [[SSS_PRIV:%.+]] = alloca %struct.SSS,
162 // CHECK: invoke {{.*}} @_ZN3SSSIiEC1Ev(%struct.SSS* [[SSS_PRIV]])
163 // CHECK-NOT: {{call |invoke }}
164 // CHECK: call {{.*}}i32 @__kmpc_reduce_nowait(
166 // CHECK-LABEL: i32 @{{.+}}foo{{[^(].+}}(i32
167 // CHECK-LOAD-LABEL: i32 @{{.+}}foo{{[^(].+}}(i32
169 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
170 // CHECK-LOAD: [[XOR:%.+]] = xor i32
171 // CHECK-LOAD-NEXT: store i32 [[XOR]], i32*
172 // CHECK-LOAD-NEXT: ret void
173 // CHECK-LOAD-NEXT: }
175 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
176 // CHECK-LOAD: [[ADD:%.+]] = add nsw i32 24,
177 // CHECK-LOAD-NEXT: store i32 [[ADD]], i32*
178 // CHECK-LOAD-NEXT: ret void
179 // CHECK-LOAD-NEXT: }
181 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
182 // CHECK: [[ADD:%.+]] = add nsw i32
183 // CHECK-NEXT: store i32 [[ADD]], i32*
184 // CHECK-NEXT: ret void
186 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
187 // CHECK-LOAD: [[ADD:%.+]] = add nsw i32
188 // CHECK-LOAD-NEXT: store i32 [[ADD]], i32*
189 // CHECK-LOAD-NEXT: ret void
190 // CHECK-LOAD-NEXT: }
192 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
193 // CHECK: [[MUL:%.+]] = mul nsw i32 15,
194 // CHECK-NEXT: store i32 [[MUL]], i32*
195 // CHECK-NEXT: ret void
197 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
198 // CHECK-LOAD: [[MUL:%.+]] = mul nsw i32 15,
199 // CHECK-LOAD-NEXT: store i32 [[MUL]], i32*
200 // CHECK-LOAD-NEXT: ret void
201 // CHECK-LOAD-NEXT: }
203 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
204 // CHECK: [[DIV:%.+]] = sdiv i32
205 // CHECK-NEXT: store i32 [[DIV]], i32*
206 // CHECK-NEXT: ret void
208 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
209 // CHECK-LOAD: [[DIV:%.+]] = sdiv i32
210 // CHECK-LOAD-NEXT: store i32 [[DIV]], i32*
211 // CHECK-LOAD-NEXT: ret void
212 // CHECK-LOAD-NEXT: }
214 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
215 // CHECK: [[SUB:%.+]] = sub nsw i32 11,
216 // CHECK-NEXT: store i32 [[SUB]], i32*
217 // CHECK-NEXT: ret void
219 // CHECK-LOAD: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
220 // CHECK-LOAD: [[SUB:%.+]] = sub nsw i32 11,
221 // CHECK-LOAD-NEXT: store i32 [[SUB]], i32*
222 // CHECK-LOAD-NEXT: ret void
223 // CHECK-LOAD-NEXT: }