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: [[IMPLICIT_BARRIER_SINGLE_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 322, i32 0, i32 0, i8*
     10 // CHECK-LABEL: foo
     11 void foo() {};
     12 // CHECK-LABEL: bar
     13 void bar() {};
     14 
     15 template <class T>
     16 T tmain() {
     17 #pragma omp parallel
     18 #pragma omp sections
     19   {
     20     foo();
     21   }
     22   return T();
     23 }
     24 
     25 // CHECK-LABEL: @main
     26 int main() {
     27   float l = 0.0; // Used as a base point in checks.
     28 // CHECK: [[GTID:%.+]] = call{{.*}} i32 @__kmpc_global_thread_num({{.*}})
     29 // CHECK: store float
     30 #pragma omp sections
     31   {
     32 // CHECK:      store i32 0, i32* [[LB_PTR:%.+]],
     33 // CHECK:      store i32 1, i32* [[UB_PTR:%.+]],
     34 // 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)
     35 // <<UB = min(UB, GlobalUB);>>
     36 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
     37 // CHECK:      [[CMP:%.+]] = icmp slt i32 [[UB]], 1
     38 // CHECK:      [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1
     39 // CHECK:      store i32 [[MIN_UB_GLOBALUB]], i32* [[UB_PTR]]
     40 // <<IV = LB;>>
     41 // CHECK:      [[LB:%.+]] = load i32, i32* [[LB_PTR]]
     42 // CHECK:      store i32 [[LB]], i32* [[IV_PTR:%.+]]
     43 // CHECK:      br label %[[INNER_FOR_COND:.+]]
     44 // CHECK:      [[INNER_FOR_COND]]
     45 // <<IV <= UB?>>
     46 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     47 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
     48 // CHECK:      [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
     49 // CHECK:      br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]]
     50 // CHECK:      [[INNER_LOOP_BODY]]
     51 // <<TRUE>> - > <BODY>
     52 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     53 // CHECK:      switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [
     54 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]]
     55 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]]
     56 #pragma omp section
     57 // CHECK:      [[SECTIONS_CASE0]]
     58 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}()
     59 // CHECK:      br label %[[SECTIONS_EXIT]]
     60     foo();
     61 #pragma omp section
     62 // CHECK:      [[SECTIONS_CASE1]]
     63 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}()
     64 // CHECK:      br label %[[SECTIONS_EXIT]]
     65     bar();
     66 // CHECK:      [[SECTIONS_EXIT]]
     67 // <<++IV;>>
     68 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
     69 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1
     70 // CHECK-NEXT: store i32 [[INC]], i32* [[IV_PTR]]
     71 // CHECK-NEXT: br label %[[INNER_FOR_COND]]
     72 // CHECK:      [[INNER_LOOP_END]]
     73   }
     74 // CHECK:      call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
     75 // CHECK:      call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SECTIONS_LOC]],
     76 #pragma omp sections nowait
     77   {
     78     foo();
     79 #pragma omp section
     80     bar();
     81   }
     82 // CHECK-NOT:  __kmpc_cancel_barrier
     83   return tmain<int>();
     84 }
     85 
     86 // CHECK-LABEL: tmain
     87 // CHECK:       call void {{.*}} @__kmpc_fork_call(
     88 // CHECK-NOT:   __kmpc_global_thread_num
     89 // CHECK:       [[RES:%.+]] = call i32 @__kmpc_single(
     90 // CHECK-NEXT:  [[BOOLRES:%.+]] = icmp ne i32 [[RES]], 0
     91 // CHECK-NEXT:  br i1 [[BOOLRES]], label %[[THEN:.+]], label %[[END:.+]]
     92 // CHECK:       [[THEN]]
     93 // CHECK-NEXT:  invoke void @{{.*}}foo{{.*}}()
     94 // CHECK-NEXT:  unwind label %[[TERM_LPAD:.+]]
     95 // CHECK:       call void @__kmpc_end_single(
     96 // CHECK-NEXT:  br label %[[END]]
     97 // CHECK:       [[END]]
     98 // CHECK-NEXT:  call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SINGLE_LOC]],
     99 // CHECK:  ret
    100 // CHECK:       [[TERM_LPAD]]
    101 // CHECK:       call void @__clang_call_terminate(i8*
    102 // CHECK-NEXT:  unreachable
    103 
    104 #endif
    105