Home | History | Annotate | Download | only in OpenMP
      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 -fsyntax-only -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck %s
      4 // expected-no-diagnostics
      5 // REQUIRES: x86-registered-target
      6 #ifndef HEADER
      7 #define HEADER
      8 // CHECK: [[IMPLICIT_BARRIER_SECTIONS_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 194, 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
     17 #pragma omp sections
     18   {
     19     foo();
     20   }
     21   return T();
     22 }
     23 
     24 // CHECK-LABEL: @main
     25 int main() {
     26   float l = 0.0; // Used as a base point in checks.
     27 // CHECK: [[GTID:%.+]] = call{{.*}} i32 @__kmpc_global_thread_num({{.*}})
     28 // CHECK: store float
     29 #pragma omp sections
     30   {
     31 // CHECK:      store i32 0, i32* [[LB_PTR:%.+]],
     32 // CHECK:      store i32 1, i32* [[UB_PTR:%.+]],
     33 // 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)
     34 // <<UB = min(UB, GlobalUB);>>
     35 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
     36 // CHECK:      [[CMP:%.+]] = icmp slt i32 [[UB]], 1
     37 // CHECK:      [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1
     38 // CHECK:      store i32 [[MIN_UB_GLOBALUB]], i32* [[UB_PTR]]
     39 // <<IV = LB;>>
     40 // CHECK:      [[LB:%.+]] = load i32, i32* [[LB_PTR]]
     41 // CHECK:      store i32 [[LB]], i32* [[IV_PTR:%.+]]
     42 // CHECK:      br label %[[INNER_FOR_COND:.+]]
     43 // CHECK:      [[INNER_FOR_COND]]
     44 // <<IV <= UB?>>
     45 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     46 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
     47 // CHECK:      [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
     48 // CHECK:      br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]]
     49 // CHECK:      [[INNER_LOOP_BODY]]
     50 // <<TRUE>> - > <BODY>
     51 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     52 // CHECK:      switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [
     53 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]]
     54 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]]
     55 #pragma omp section
     56 // CHECK:      [[SECTIONS_CASE0]]
     57 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}()
     58 // CHECK:      br label %[[SECTIONS_EXIT]]
     59     foo();
     60 #pragma omp section
     61 // CHECK:      [[SECTIONS_CASE1]]
     62 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}()
     63 // CHECK:      br label %[[SECTIONS_EXIT]]
     64     bar();
     65 // CHECK:      [[SECTIONS_EXIT]]
     66 // <<++IV;>>
     67 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     68 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1
     69 // CHECK-NEXT: store i32 [[INC]], i32* [[IV_PTR]]
     70 // CHECK-NEXT: br label %[[INNER_FOR_COND]]
     71 // CHECK:      [[INNER_LOOP_END]]
     72   }
     73 // CHECK:      call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
     74 // CHECK:      call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SECTIONS_LOC]],
     75 #pragma omp sections nowait
     76   {
     77     foo();
     78 #pragma omp section
     79     bar();
     80   }
     81 // CHECK-NOT:  __kmpc_cancel_barrier
     82   return tmain<int>();
     83 }
     84 
     85 // CHECK-LABEL: tmain
     86 // CHECK:       call void {{.*}} @__kmpc_fork_call(
     87 // CHECK-NOT:   __kmpc_global_thread_num
     88 // CHECK:       call void @__kmpc_for_static_init_4(
     89 // CHECK:       invoke void @{{.*}}foo{{.*}}()
     90 // CHECK-NEXT:  unwind label %[[TERM_LPAD:.+]]
     91 // CHECK:       call void @__kmpc_for_static_fini(
     92 // CHECK:       call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SECTIONS_LOC]],
     93 // CHECK:       ret
     94 // CHECK:       [[TERM_LPAD]]
     95 // CHECK:       call void @__clang_call_terminate(i8*
     96 // CHECK-NEXT:  unreachable
     97 
     98 #endif
     99