[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / sections_codegen.cpp
blob5a5e32751c6775bf3866836f929c72f1d4397230
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -include-pch %t -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -include-pch %t -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
12 // CHECK-DAG: [[IMPLICIT_BARRIER_SECTIONS_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 194, i32 0, i32 {{[0-9]+}}, ptr
13 // CHECK-DAG: [[SECTIONS_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 1026, i32 0, i32 {{[0-9]+}}, ptr
14 // CHECK-LABEL: foo
15 void foo() { extern void mayThrow(); mayThrow(); };
16 // CHECK-LABEL: bar
17 void bar() { extern void mayThrow(); mayThrow(); };
19 template <class T>
20 T tmain() {
21 #pragma omp parallel
22 #pragma omp sections
24 foo();
26 return T();
29 // CHECK-LABEL: @main
30 int main() {
31 float l = 0.0; // Used as a base point in checks.
32 // CHECK: [[GTID:%.+]] = call{{.*}} i32 @__kmpc_global_thread_num({{.*}})
33 // CHECK: store float
34 #pragma omp sections
36 // CHECK: store i32 0, ptr [[LB_PTR:%.+]],
37 // CHECK: store i32 1, ptr [[UB_PTR:%.+]],
38 // CHECK: call void @__kmpc_for_static_init_4(ptr [[SECTIONS_LOC]], i32 [[GTID]], i32 34, ptr [[IS_LAST_PTR:%.+]], ptr [[LB_PTR]], ptr [[UB_PTR]], ptr [[STRIDE_PTR:%.+]], i32 1, i32 1)
39 // <<UB = min(UB, GlobalUB);>>
40 // CHECK: [[UB:%.+]] = load i32, ptr [[UB_PTR]]
41 // CHECK: [[CMP:%.+]] = icmp slt i32 [[UB]], 1
42 // CHECK: [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1
43 // CHECK: store i32 [[MIN_UB_GLOBALUB]], ptr [[UB_PTR]]
44 // <<IV = LB;>>
45 // CHECK: [[LB:%.+]] = load i32, ptr [[LB_PTR]]
46 // CHECK: store i32 [[LB]], ptr [[IV_PTR:%.+]]
47 // CHECK: br label %[[INNER_FOR_COND:.+]]
48 // CHECK: [[INNER_FOR_COND]]
49 // <<IV <= UB?>>
50 // CHECK: [[IV:%.+]] = load i32, ptr [[IV_PTR]]
51 // CHECK: [[UB:%.+]] = load i32, ptr [[UB_PTR]]
52 // CHECK: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
53 // CHECK: br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]]
54 // CHECK: [[INNER_LOOP_BODY]]
55 // <<TRUE>> - > <BODY>
56 // CHECK: [[IV:%.+]] = load i32, ptr [[IV_PTR]]
57 // CHECK: switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [
58 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]]
59 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]]
60 #pragma omp section
61 // CHECK: [[SECTIONS_CASE0]]
62 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}()
63 // CHECK: br label %[[SECTIONS_EXIT]]
64 foo();
65 #pragma omp section
66 // CHECK: [[SECTIONS_CASE1]]
67 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}()
68 // CHECK: br label %[[SECTIONS_EXIT]]
69 bar();
70 // CHECK: [[SECTIONS_EXIT]]
71 // <<++IV;>>
72 // CHECK: [[IV:%.+]] = load i32, ptr [[IV_PTR]]
73 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1
74 // CHECK-NEXT: store i32 [[INC]], ptr [[IV_PTR]]
75 // CHECK-NEXT: br label %[[INNER_FOR_COND]]
76 // CHECK: [[INNER_LOOP_END]]
78 // CHECK: call void @__kmpc_for_static_fini(ptr [[SECTIONS_LOC]], i32 [[GTID]])
79 // CHECK: call void @__kmpc_barrier(ptr [[IMPLICIT_BARRIER_SECTIONS_LOC]],
80 #pragma omp sections nowait
82 foo();
83 #pragma omp section
84 bar();
86 // CHECK-NOT: __kmpc_cancel_barrier
87 return tmain<int>();
90 // CHECK-LABEL: tmain
91 // CHECK: call void {{.*}} @__kmpc_fork_call(
92 // CHECK-NOT: __kmpc_global_thread_num
93 // CHECK: call void @__kmpc_for_static_init_4(
94 // CHECK: invoke void @{{.*}}foo{{.*}}()
95 // CHECK-NEXT: unwind label %[[TERM_LPAD:.+]]
96 // CHECK: call void @__kmpc_for_static_fini(
97 // CHECK: call void @__kmpc_barrier(ptr [[IMPLICIT_BARRIER_SECTIONS_LOC]],
98 // CHECK: ret
99 // CHECK: [[TERM_LPAD]]
100 // CHECK: call void @__clang_call_terminate(ptr
101 // CHECK-NEXT: unreachable
103 #endif