Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
      4 // REQUIRES: x86-registered-target
      5 // expected-no-diagnostics
      6 
      7 #ifndef HEADER
      8 #define HEADER
      9 
     10 // CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
     11 extern int n;
     12 int a[10], b[10], c[10], d[10];
     13 void foo();
     14 
     15 // CHECK-LABEL: @main()
     16 int main() {
     17   int i;
     18 // CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
     19 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
     20 // CHECK: icmp
     21 // CHECK-NEXT: br i1 %
     22 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
     23 // CHECK: call void @llvm.memset.p0i8.i64(i8* [[CAST]], i8 0, i64 24, i32 8, i1 false)
     24 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 1
     25 // CHECK: store i64 %{{.+}}, i64* %
     26 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 2
     27 // CHECK: store i64 1, i64* %
     28 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
     29 // CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
     30 // CHECK: call void @__kmpc_for_static_init_4(
     31 #pragma omp for ordered(1)
     32   for (i = 0; i < n; ++i) {
     33     a[i] = b[i] + 1;
     34     foo();
     35 // CHECK: invoke void [[FOO:.+]](
     36 // CHECK: load i32, i32* [[CNT:%.+]],
     37 // CHECK-NEXT: sext i32 %{{.+}} to i64
     38 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
     39 // CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
     40 #pragma omp ordered depend(source)
     41     c[i] = c[i] + 1;
     42     foo();
     43 // CHECK: invoke void [[FOO]]
     44 // CHECK: load i32, i32* [[CNT]],
     45 // CHECK-NEXT: sub nsw i32 %{{.+}}, 2
     46 // CHECK-NEXT: sext i32 %{{.+}} to i64
     47 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
     48 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
     49 #pragma omp ordered depend(sink : i - 2)
     50     d[i] = a[i - 2];
     51   }
     52   // CHECK: landingpad
     53   // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
     54   // CHECK: br label %
     55 
     56   // CHECK: call void @__kmpc_for_static_fini(
     57   // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
     58   // CHECK: ret i32 0
     59   return 0;
     60 }
     61 
     62 // CHECK: define {{.+}}TestStruct
     63 template <typename T>
     64 struct TestStruct {
     65   static const int M = 10;
     66   static const int N = 20;
     67   T i;
     68   T a[N][M];
     69   T b[N][M];
     70   T foo(T, T);
     71   T bar(T, T, T);
     72   void baz(T, T);
     73   TestStruct() {
     74 // CHECK: [[CNT:%.+]] = alloca i64,
     75 // CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
     76 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
     77 // CHECK: icmp
     78 // CHECK-NEXT: br i1 %
     79 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
     80 // CHECK: call void @llvm.memset.p0i8.i64(i8* [[CAST]], i8 0, i64 24, i32 8, i1 false)
     81 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 1
     82 // CHECK: store i64 %{{.+}}, i64* %
     83 // CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 2
     84 // CHECK: store i64 1, i64* %
     85 // CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
     86 // CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
     87 // CHECK: call void @__kmpc_for_static_init_8(
     88 #pragma omp for ordered(2)
     89     for (T j = 0; j < M; j++)
     90       for (i = 0; i < n; i += 2) {
     91         a[i][j] = foo(i, j);
     92 // CHECK: invoke {{.+TestStruct.+foo}}
     93 // CHECK: load i64, i64* [[CNT]],
     94 // CHECK-NEXT: sub nsw i64 %{{.+}}, 1
     95 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
     96 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
     97 // CHECK-NEXT: load i64, i64* [[CNT]],
     98 // CHECK-NEXT: load i32, i32* %
     99 // CHECK-NEXT: mul nsw i32 1, %
    100 // CHECK-NEXT: sext i32 %{{.+}} to i64
    101 // CHECK-NEXT: sub nsw i64 %
    102 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
    103 // CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
    104 #pragma omp ordered depend(sink : j, i - 2) depend(sink : j - 1, i)
    105         b[i][j] = bar(a[i][j], b[i - 1][j], b[i][j - 1]);
    106 // CHECK: invoke {{.+TestStruct.+bar}}
    107 // CHECK: load i64, i64* [[CNT]],
    108 // CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
    109 // CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
    110 #pragma omp ordered depend(source)
    111         baz(a[i][j], b[i][j]);
    112       }
    113   }
    114   // CHECK: landingpad
    115   // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
    116   // CHECK: br label %
    117 
    118   // CHECK: call void @__kmpc_for_static_fini(
    119   // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
    120   // CHECK: ret
    121 };
    122 
    123 TestStruct<int> s;
    124 #endif // HEADER
    125