Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
      4 // RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
      5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck -check-prefix=BLOCKS %s
      6 // expected-no-diagnostics
      7 // REQUIRES: x86-registered-target
      8 #ifndef HEADER
      9 #define HEADER
     10 
     11 template <class T>
     12 struct S {
     13   T f;
     14   S(T a) : f(a) {}
     15   S() : f() {}
     16   operator T() { return T(); }
     17   ~S() {}
     18 };
     19 
     20 volatile double g;
     21 
     22 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
     23 // CHECK: [[S_INT_TY:%.+]] = type { i{{[0-9]+}} }
     24 template <typename T>
     25 T tmain() {
     26   S<T> test;
     27   T t_var = T();
     28   T vec[] = {1, 2};
     29   S<T> s_arr[] = {1, 2};
     30   S<T> var(3);
     31 #pragma omp parallel
     32 #pragma omp single private(t_var, vec, s_arr, s_arr, var, var)
     33   {
     34     vec[0] = t_var;
     35     s_arr[0] = var;
     36   }
     37   return T();
     38 }
     39 
     40 int main() {
     41   static int sivar;
     42 #ifdef LAMBDA
     43   // LAMBDA: [[G:@.+]] = global double
     44   // LAMBDA-LABEL: @main
     45   // LAMBDA: call{{.*}} void [[OUTER_LAMBDA:@.+]](
     46   [&]() {
     47   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
     48   // LAMBDA: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
     49 #pragma omp parallel
     50 #pragma omp single private(g, sivar)
     51   {
     52     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
     53     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca double,
     54     // LAMBDA: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
     55     g = 1;
     56     sivar = 101;
     57     // LAMBDA: call {{.*}}i32 @__kmpc_single(
     58     // LAMBDA: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
     59     // LAMBDA: store i{{[0-9]+}} 101, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
     60     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     61     // LAMBDA: store double* [[G_PRIVATE_ADDR]], double** [[G_PRIVATE_ADDR_REF]]
     62     // LAMBDA: [[SIVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
     63     // LAMBDA: store i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]], i{{[0-9]+}}** [[SIVAR_PRIVATE_ADDR_REF]]
     64     // LAMBDA: call{{.*}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
     65     // LAMBDA: call {{.*}}void @__kmpc_end_single(
     66     [&]() {
     67       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
     68       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
     69       g = 2;
     70       sivar = 211;
     71       // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
     72       // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     73       // LAMBDA: [[G_REF:%.+]] = load double*, double** [[G_PTR_REF]]
     74       // LAMBDA: store double 2.0{{.+}}, double* [[G_REF]]
     75       // LAMBDA: [[SIVAR_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
     76       // LAMBDA: [[SIVAR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[SIVAR_PTR_REF]]
     77       // LAMBDA: store i{{[0-9]+}} 211, i{{[0-9]+}}* [[SIVAR_REF]]
     78     }();
     79   }
     80   }();
     81   return 0;
     82 #elif defined(BLOCKS)
     83   // BLOCKS: [[G:@.+]] = global double
     84   // BLOCKS-LABEL: @main
     85   // BLOCKS: call {{.*}}void {{%.+}}(i8
     86   ^{
     87   // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
     88   // BLOCKS: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
     89 #pragma omp parallel
     90 #pragma omp single private(g, sivar)
     91   {
     92     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
     93     // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca double,
     94     // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
     95     g = 1;
     96     sivar = 101;
     97     // BLOCKS: call {{.*}}i32 @__kmpc_single(
     98     // BLOCKS: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
     99     // BLOCKS: store i{{[0-9]+}} 101, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
    100     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    101     // BLOCKS: double* [[G_PRIVATE_ADDR]]
    102     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    103     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    104     // BLOCKS: i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]]
    105     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    106     // BLOCKS: call {{.*}}void {{%.+}}(i8
    107     // BLOCKS: call {{.*}}void @__kmpc_end_single(
    108     ^{
    109       // BLOCKS: define {{.+}} void {{@.+}}(i8*
    110       g = 2;
    111       sivar = 203;
    112       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    113       // BLOCKS: store double 2.0{{.+}}, double*
    114       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    115       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    116       // BLOCKS: store i{{[0-9]+}} 203, i{{[0-9]+}}*
    117       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    118       // BLOCKS: ret
    119     }();
    120   }
    121   }();
    122   return 0;
    123 #else
    124   S<float> test;
    125   int t_var = 0;
    126   int vec[] = {1, 2};
    127   S<float> s_arr[] = {1, 2};
    128   S<float> var(3);
    129 #pragma omp parallel
    130 #pragma omp single private(t_var, vec, s_arr, s_arr, var, var, sivar)
    131   {
    132     vec[0] = t_var;
    133     s_arr[0] = var;
    134     sivar = 303;
    135   }
    136   return tmain<int>();
    137 #endif
    138 }
    139 
    140 // CHECK: define i{{[0-9]+}} @main()
    141 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
    142 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
    143 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 0, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*)* [[MAIN_MICROTASK:@.+]] to void
    144 // CHECK: = call i{{.+}} [[TMAIN_INT:@.+]]()
    145 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
    146 // CHECK: ret
    147 //
    148 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
    149 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    150 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
    151 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_FLOAT_TY]]],
    152 // CHECK-NOT: alloca [2 x [[S_FLOAT_TY]]],
    153 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_FLOAT_TY]],
    154 // CHECK-NOT: alloca [[S_FLOAT_TY]],
    155 // CHECK: [[SIVAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    156 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    157 // CHECK: call i32 @__kmpc_single(
    158 // CHECK-NOT: [[T_VAR_PRIV]]
    159 // CHECK-NOT: [[VEC_PRIV]]
    160 // CHECK-NOT: [[SIVAR_PRIV]]
    161 // CHECK: {{.+}}:
    162 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_FLOAT_TY]]*
    163 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[S_ARR_PRIV_ITEM]])
    164 // CHECK-NOT: [[T_VAR_PRIV]]
    165 // CHECK-NOT: [[VEC_PRIV]]
    166 // CHECK-NOT: [[SIVAR_PRIV]]
    167 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
    168 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
    169 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]*
    170 // CHECK: call void @__kmpc_end_single(
    171 // CHECK: ret void
    172 
    173 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
    174 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
    175 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
    176 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 0, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*)* [[TMAIN_MICROTASK:@.+]] to void
    177 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
    178 // CHECK: ret
    179 //
    180 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
    181 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    182 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
    183 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_INT_TY]]],
    184 // CHECK-NOT: alloca [2 x [[S_INT_TY]]],
    185 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_INT_TY]],
    186 // CHECK-NOT: alloca [[S_INT_TY]],
    187 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    188 // CHECK: call i32 @__kmpc_single(
    189 // CHECK-NOT: [[T_VAR_PRIV]]
    190 // CHECK-NOT: [[VEC_PRIV]]
    191 // CHECK: {{.+}}:
    192 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_INT_TY]]*
    193 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[S_ARR_PRIV_ITEM]])
    194 // CHECK-NOT: [[T_VAR_PRIV]]
    195 // CHECK-NOT: [[VEC_PRIV]]
    196 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[VAR_PRIV]])
    197 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]* [[VAR_PRIV]])
    198 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]*
    199 // CHECK: call void @__kmpc_end_single(
    200 // CHECK: ret void
    201 #endif
    202 
    203