1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix=CHECK %s
4 // expected-no-diagnostics
5 #ifndef HEADER
6 #define HEADER
7
8 void fn1();
9 void fn2();
10 void fn3();
11 void fn4();
12 void fn5();
13 void fn6();
14
15 int Arg;
16
17 // CHECK-LABEL: define {{.*}}void @{{.+}}gtid_test
gtid_test()18 void gtid_test() {
19 // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{.+}} 0, {{.+}}* [[GTID_TEST_REGION1:@.+]] to void
20 #pragma omp parallel
21 #pragma omp parallel if (parallel: false)
22 gtid_test();
23 // CHECK: ret void
24 }
25
26 // CHECK: define internal {{.*}}void [[GTID_TEST_REGION1]](i{{.+}}* noalias [[GTID_PARAM:%.+]], i32* noalias
27 // CHECK: store i{{[0-9]+}}* [[GTID_PARAM]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]],
28 // CHECK: [[GTID_ADDR:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[GTID_ADDR_REF]]
29 // CHECK: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_ADDR]]
30 // CHECK: call {{.*}}void @__kmpc_serialized_parallel(%{{.+}}* @{{.+}}, i{{.+}} [[GTID]])
31 // CHECK: [[GTID_ADDR:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[GTID_ADDR_REF]]
32 // CHECK: call void [[GTID_TEST_REGION2:@.+]](i{{[0-9]+}}* [[GTID_ADDR]]
33 // CHECK: call {{.*}}void @__kmpc_end_serialized_parallel(%{{.+}}* @{{.+}}, i{{.+}} [[GTID]])
34 // CHECK: ret void
35
36 // CHECK: define internal {{.*}}void [[GTID_TEST_REGION2]](
37 // CHECK: call {{.*}}void @{{.+}}gtid_test
38 // CHECK: ret void
39
40 template <typename T>
tmain(T Arg)41 int tmain(T Arg) {
42 #pragma omp parallel if (true)
43 fn1();
44 #pragma omp parallel if (false)
45 fn2();
46 #pragma omp parallel if (parallel: Arg)
47 fn3();
48 return 0;
49 }
50
51 // CHECK-LABEL: define {{.*}}i{{[0-9]+}} @main()
main()52 int main() {
53 // CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(
54 // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{.+}} 0, void {{.+}}* [[CAP_FN4:@.+]] to void
55 #pragma omp parallel if (true)
56 fn4();
57 // CHECK: call {{.*}}void @__kmpc_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
58 // CHECK: store i32 [[GTID]], i32* [[GTID_ADDR:%.+]],
59 // CHECK: call void [[CAP_FN5:@.+]](i32* [[GTID_ADDR]],
60 // CHECK: call {{.*}}void @__kmpc_end_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
61 #pragma omp parallel if (false)
62 fn5();
63
64 // CHECK: br i1 %{{.+}}, label %[[OMP_THEN:.+]], label %[[OMP_ELSE:.+]]
65 // CHECK: [[OMP_THEN]]
66 // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{.+}} 0, void {{.+}}* [[CAP_FN6:@.+]] to void
67 // CHECK: br label %[[OMP_END:.+]]
68 // CHECK: [[OMP_ELSE]]
69 // CHECK: call {{.*}}void @__kmpc_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
70 // CHECK: store i32 [[GTID]], i32* [[GTID_ADDR:%.+]],
71 // CHECK: call void [[CAP_FN6]](i32* [[GTID_ADDR]],
72 // CHECK: call {{.*}}void @__kmpc_end_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
73 // CHECK: br label %[[OMP_END]]
74 // CHECK: [[OMP_END]]
75 #pragma omp parallel if (Arg)
76 fn6();
77 // CHECK: = call {{.*}}i{{.+}} @{{.+}}tmain
78 return tmain(Arg);
79 }
80
81 // CHECK: define internal {{.*}}void [[CAP_FN4]]
82 // CHECK: call {{.*}}void @{{.+}}fn4
83 // CHECK: ret void
84
85 // CHECK: define internal {{.*}}void [[CAP_FN5]]
86 // CHECK: call {{.*}}void @{{.+}}fn5
87 // CHECK: ret void
88
89 // CHECK: define internal {{.*}}void [[CAP_FN6]]
90 // CHECK: call {{.*}}void @{{.+}}fn6
91 // CHECK: ret void
92
93 // CHECK-LABEL: define {{.+}} @{{.+}}tmain
94 // CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(
95 // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{.+}} 0, void {{.+}}* [[CAP_FN1:@.+]] to void
96 // CHECK: call {{.*}}void @__kmpc_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
97 // CHECK: store i32 [[GTID]], i32* [[GTID_ADDR:%.+]],
98 // CHECK: call void [[CAP_FN2:@.+]](i32* [[GTID_ADDR]],
99 // CHECK: call {{.*}}void @__kmpc_end_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
100 // CHECK: br i1 %{{.+}}, label %[[OMP_THEN:.+]], label %[[OMP_ELSE:.+]]
101 // CHECK: [[OMP_THEN]]
102 // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{.+}} 0, void {{.+}}* [[CAP_FN3:@.+]] to void
103 // CHECK: br label %[[OMP_END:.+]]
104 // CHECK: [[OMP_ELSE]]
105 // CHECK: call {{.*}}void @__kmpc_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
106 // CHECK: store i32 [[GTID]], i32* [[GTID_ADDR:%.+]],
107 // CHECK: call void [[CAP_FN3]](i32* [[GTID_ADDR]],
108 // CHECK: call {{.*}}void @__kmpc_end_serialized_parallel(%{{.+}}* @{{.+}}, i32 [[GTID]])
109 // CHECK: br label %[[OMP_END]]
110 // CHECK: [[OMP_END]]
111
112 // CHECK: define internal {{.*}}void [[CAP_FN1]]
113 // CHECK: call {{.*}}void @{{.+}}fn1
114 // CHECK: ret void
115
116 // CHECK: define internal {{.*}}void [[CAP_FN2]]
117 // CHECK: call {{.*}}void @{{.+}}fn2
118 // CHECK: ret void
119
120 // CHECK: define internal {{.*}}void [[CAP_FN3]]
121 // CHECK: call {{.*}}void @{{.+}}fn3
122 // CHECK: ret void
123
124 #endif
125