1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,NORMAL
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,NORMAL
4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=51 -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
5 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
8
9 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -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
12 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fopenmp-version=51 -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
14 // expected-no-diagnostics
15 #ifndef HEADER
16 #define HEADER
17
18 // ALL: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
19 // ALL: [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
20 // ALL: [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
21 // ALL: [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
22
23 // ALL: define {{.*}}void [[FOO:@.+]]()
24
foo()25 void foo() { extern void mayThrow(); mayThrow(); }
26
27 // ALL-LABEL: @main
28 // TERM_DEBUG-LABEL: @main
main()29 int main() {
30 // ALL: [[A_ADDR:%.+]] = alloca i8
31 char a;
32
33 // ALL: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
34 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
35 // ALL-NEXT: store i8 2, i8* [[A_ADDR]]
36 // ALL-NEXT: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
37 [[omp::directive(critical)]]
38 a = 2;
39 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
40 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
41 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
42 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
43 // ALL: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
44 [[omp::directive(critical(the_name))]]
45 foo();
46 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
47 // ALL: call {{.*}}void @__kmpc_critical_with_hint([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]], i{{64|32}} 23)
48 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
49 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
50 // ALL: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]])
51 [[omp::directive(critical(the_name1) hint(23))]]
52 foo();
53 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
54 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
55 // ALL: br label
56 // ALL-NOT: call {{.*}}void @__kmpc_end_critical(
57 // ALL: br label
58 // ALL-NOT: call {{.*}}void @__kmpc_end_critical(
59 // NORMAL: br label
60 if (a)
61 [[omp::directive(critical(the_name))]]
62 while (1)
63 ;
64 // ALL: call {{.*}}void [[FOO]]()
65 foo();
66 // ALL-NOT: call void @__kmpc_critical
67 // ALL-NOT: call void @__kmpc_end_critical
68 return a;
69 }
70
71 // ALL-LABEL: lambda_critical
72 // TERM_DEBUG-LABEL: lambda_critical
lambda_critical(int a,int b)73 void lambda_critical(int a, int b) {
74 auto l = [=]() {
75 [[omp::directive(critical)]]
76 {
77 // ALL: call void @__kmpc_critical(
78 int c = a + b;
79 }
80 };
81
82 l();
83
84 auto l1 = [=]() {
85 [[omp::sequence(directive(parallel), directive(critical))]]
86 {
87 // ALL: call void @__kmpc_critical(
88 int c = a + b;
89 }
90 };
91
92 l1();
93 }
94
95 struct S {
96 int a;
97 };
98 // ALL-LABEL: critical_ref
critical_ref(S & s)99 void critical_ref(S &s) {
100 // ALL: [[S_ADDR:%.+]] = alloca %struct.S*,
101 // ALL: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
102 // ALL: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
103 ++s.a;
104 // ALL: call void @__kmpc_critical(
105 [[omp::directive(critical)]]
106 // ALL: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
107 // ALL: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
108 ++s.a;
109 // ALL: call void @__kmpc_end_critical(
110 }
111
112 // ALL-LABEL: parallel_critical
113 // TERM_DEBUG-LABEL: parallel_critical
parallel_critical()114 void parallel_critical() {
115 [[omp::sequence(directive(parallel), directive(critical))]]
116 // TERM_DEBUG-NOT: __kmpc_global_thread_num
117 // TERM_DEBUG: call void @__kmpc_critical({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
118 // TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
119 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
120 // TERM_DEBUG-NOT: __kmpc_global_thread_num
121 // TERM_DEBUG: call void @__kmpc_end_critical({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
122 // TERM_DEBUG: [[TERM_LPAD]]
123 // TERM_DEBUG: call void @__clang_call_terminate
124 // TERM_DEBUG: unreachable
125 foo();
126 }
127 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
128 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
129 #endif
130
131