1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -x c++ -emit-llvm -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - %s | FileCheck %s 2 // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -triple x86_64-unknown-unknown -emit-pch -o %t %s 3 // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -include-pch %t -fsyntax-only -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck %s 4 // expected-no-diagnostics 5 6 #ifndef HEADER 7 #define HEADER 8 // CHECK: [[IMPLICIT_BARRIER_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 66, i32 0, i32 0, i8* 9 // CHECK-LABEL: foo 10 void foo() {}; 11 // CHECK-LABEL: bar 12 void bar() {}; 13 14 template <class T> 15 T tmain() { 16 #pragma omp parallel sections 17 { 18 foo(); 19 } 20 return T(); 21 } 22 23 // CHECK-LABEL: @main 24 int main() { 25 // CHECK: call void (%{{.+}}*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %{{.+}}*)* [[OMP_PARALLEL_FUNC:@.+]] to void (i32*, i32*, ...)*), i8* %{{.+}}) 26 // CHECK-LABEL: } 27 // CHECK: define internal void [[OMP_PARALLEL_FUNC]](i32* [[GTID_PARAM_ADDR:%.+]], i32* %{{.+}}, %{{.+}}* %{{.+}}) 28 // CHECK: store i32* [[GTID_PARAM_ADDR]], i32** [[GTID_REF_ADDR:%.+]], 29 #pragma omp parallel sections 30 { 31 // CHECK: store i32 0, i32* [[LB_PTR:%.+]], 32 // CHECK: store i32 1, i32* [[UB_PTR:%.+]], 33 // CHECK: [[GTID_REF:%.+]] = load i32*, i32** [[GTID_REF_ADDR]], 34 // CHECK: [[GTID:%.+]] = load i32, i32* [[GTID_REF]], 35 // CHECK: call void @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_PTR:%.+]], i32* [[LB_PTR]], i32* [[UB_PTR]], i32* [[STRIDE_PTR:%.+]], i32 1, i32 1) 36 // <<UB = min(UB, GlobalUB);>> 37 // CHECK: [[UB:%.+]] = load i32, i32* [[UB_PTR]] 38 // CHECK: [[CMP:%.+]] = icmp slt i32 [[UB]], 1 39 // CHECK: [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1 40 // CHECK: store i32 [[MIN_UB_GLOBALUB]], i32* [[UB_PTR]] 41 // <<IV = LB;>> 42 // CHECK: [[LB:%.+]] = load i32, i32* [[LB_PTR]] 43 // CHECK: store i32 [[LB]], i32* [[IV_PTR:%.+]] 44 // CHECK: br label %[[INNER_FOR_COND:.+]] 45 // CHECK: [[INNER_FOR_COND]] 46 // <<IV <= UB?>> 47 // CHECK: [[IV:%.+]] = load i32, i32* [[IV_PTR]] 48 // CHECK: [[UB:%.+]] = load i32, i32* [[UB_PTR]] 49 // CHECK: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]] 50 // CHECK: br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]] 51 // CHECK: [[INNER_LOOP_BODY]] 52 // <<TRUE>> - > <BODY> 53 // CHECK: [[IV:%.+]] = load i32, i32* [[IV_PTR]] 54 // CHECK: switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [ 55 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]] 56 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]] 57 #pragma omp section 58 // CHECK: [[SECTIONS_CASE0]] 59 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}() 60 // CHECK: br label %[[SECTIONS_EXIT]] 61 foo(); 62 #pragma omp section 63 // CHECK: [[SECTIONS_CASE1]] 64 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}() 65 // CHECK: br label %[[SECTIONS_EXIT]] 66 bar(); 67 // CHECK: [[SECTIONS_EXIT]] 68 // <<++IV;>> 69 // CHECK: [[IV:%.+]] = load i32, i32* [[IV_PTR]] 70 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1 71 // CHECK-NEXT: store i32 [[INC]], i32* [[IV_PTR]] 72 // CHECK-NEXT: br label %[[INNER_FOR_COND]] 73 // CHECK: [[INNER_LOOP_END]] 74 } 75 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]]) 76 // CHECK: call i32 @__kmpc_cancel_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], 77 return tmain<int>(); 78 } 79 80 // CHECK-LABEL: tmain 81 // CHECK: call void {{.*}} @__kmpc_fork_call( 82 // CHECK-NOT: __kmpc_global_thread_num 83 // CHECK: [[RES:%.+]] = call i32 @__kmpc_single( 84 // CHECK-NEXT: [[BOOLRES:%.+]] = icmp ne i32 [[RES]], 0 85 // CHECK-NEXT: br i1 [[BOOLRES]], label %[[THEN:.+]], label %[[END:.+]] 86 // CHECK: [[THEN]] 87 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}() 88 // CHECK-NEXT: unwind label %[[TERM_LPAD:.+]] 89 // CHECK: call void @__kmpc_end_single( 90 // CHECK-NEXT: br label %[[END]] 91 // CHECK: [[END]] 92 // CHECK-NEXT: call i32 @__kmpc_cancel_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], 93 // CHECK-NEXT: ret 94 // CHECK: [[TERM_LPAD]] 95 // CHECK: call void @__clang_call_terminate(i8* 96 // CHECK-NEXT: unreachable 97 98 #endif 99