blob: 8233bb68db6b504b1e28960d0307079e25bd6ac5 [file] [log] [blame]
Alexey Bataev8b427062016-05-25 12:36:08 +00001// 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
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00004
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}}
Alexey Bataev8b427062016-05-25 12:36:08 +00009// expected-no-diagnostics
10
11#ifndef HEADER
12#define HEADER
13
14// CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
15extern int n;
16int a[10], b[10], c[10], d[10];
17void foo();
18
19// CHECK-LABEL: @main()
20int main() {
21 int i;
22// CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
23// CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
24// CHECK: icmp
25// CHECK-NEXT: br i1 %
26// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
27// CHECK: call void @llvm.memset.p0i8.i64(i8* [[CAST]], i8 0, i64 24, i32 8, i1 false)
28// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 1
29// CHECK: store i64 %{{.+}}, i64* %
30// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 2
31// CHECK: store i64 1, i64* %
32// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
33// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
34// CHECK: call void @__kmpc_for_static_init_4(
35#pragma omp for ordered(1)
36 for (i = 0; i < n; ++i) {
37 a[i] = b[i] + 1;
38 foo();
39// CHECK: invoke void [[FOO:.+]](
40// CHECK: load i32, i32* [[CNT:%.+]],
41// CHECK-NEXT: sext i32 %{{.+}} to i64
42// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
43// CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
44#pragma omp ordered depend(source)
45 c[i] = c[i] + 1;
46 foo();
47// CHECK: invoke void [[FOO]]
48// CHECK: load i32, i32* [[CNT]],
49// CHECK-NEXT: sub nsw i32 %{{.+}}, 2
50// CHECK-NEXT: sext i32 %{{.+}} to i64
51// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
52// CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
53#pragma omp ordered depend(sink : i - 2)
54 d[i] = a[i - 2];
55 }
56 // CHECK: landingpad
57 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
58 // CHECK: br label %
59
60 // CHECK: call void @__kmpc_for_static_fini(
61 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
62 // CHECK: ret i32 0
63 return 0;
64}
65
66// CHECK: define {{.+}}TestStruct
67template <typename T>
68struct TestStruct {
69 static const int M = 10;
70 static const int N = 20;
71 T i;
72 T a[N][M];
73 T b[N][M];
74 T foo(T, T);
75 T bar(T, T, T);
76 void baz(T, T);
77 TestStruct() {
78// CHECK: [[CNT:%.+]] = alloca i64,
79// CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
80// CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
81// CHECK: icmp
82// CHECK-NEXT: br i1 %
83// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
84// CHECK: call void @llvm.memset.p0i8.i64(i8* [[CAST]], i8 0, i64 24, i32 8, i1 false)
85// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 1
86// CHECK: store i64 %{{.+}}, i64* %
87// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 2
88// CHECK: store i64 1, i64* %
89// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
90// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
91// CHECK: call void @__kmpc_for_static_init_8(
92#pragma omp for ordered(2)
93 for (T j = 0; j < M; j++)
94 for (i = 0; i < n; i += 2) {
95 a[i][j] = foo(i, j);
96// CHECK: invoke {{.+TestStruct.+foo}}
97// CHECK: load i64, i64* [[CNT]],
98// CHECK-NEXT: sub nsw i64 %{{.+}}, 1
99// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
100// CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
101// CHECK-NEXT: load i64, i64* [[CNT]],
102// CHECK-NEXT: load i32, i32* %
103// CHECK-NEXT: mul nsw i32 1, %
104// CHECK-NEXT: sext i32 %{{.+}} to i64
105// CHECK-NEXT: sub nsw i64 %
106// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
107// CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
108#pragma omp ordered depend(sink : j, i - 2) depend(sink : j - 1, i)
109 b[i][j] = bar(a[i][j], b[i - 1][j], b[i][j - 1]);
110// CHECK: invoke {{.+TestStruct.+bar}}
111// CHECK: load i64, i64* [[CNT]],
112// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
113// CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
114#pragma omp ordered depend(source)
115 baz(a[i][j], b[i][j]);
116 }
117 }
118 // CHECK: landingpad
119 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
120 // CHECK: br label %
121
122 // CHECK: call void @__kmpc_for_static_fini(
123 // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
124 // CHECK: ret
125};
126
127TestStruct<int> s;
128#endif // HEADER