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 sections private(t_var, vec, s_arr, s_arr, var, var)
     33   {
     34     vec[0] = t_var;
     35 #pragma omp section
     36     s_arr[0] = var;
     37   }
     38   return T();
     39 }
     40 
     41 int main() {
     42   static int sivar;
     43 #ifdef LAMBDA
     44   // LAMBDA: [[G:@.+]] = global double
     45   // LAMBDA-LABEL: @main
     46   // LAMBDA: call{{.*}} void [[OUTER_LAMBDA:@.+]](
     47   [&]() {
     48   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
     49   // LAMBDA: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
     50 #pragma omp parallel
     51 #pragma omp sections private(g, sivar)
     52   {
     53     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
     54     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca double,
     55     // LAMBDA: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
     56     {
     57       g = 1;
     58       sivar = 11;
     59     }
     60     // LAMBDA: call {{.*}}void @__kmpc_for_static_init_4(
     61     // LAMBDA: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
     62     // LAMBDA: store i{{[0-9]+}} 11, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
     63     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     64     // LAMBDA: store double* [[G_PRIVATE_ADDR]], double** [[G_PRIVATE_ADDR_REF]]
     65     // LAMBDA: [[SIVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
     66     // LAMBDA: store i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]], i{{[0-9]+}}** [[SIVAR_PRIVATE_ADDR_REF]]
     67     // LAMBDA: call{{.*}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
     68     // LAMBDA: call {{.*}}void @__kmpc_for_static_fini(
     69 #pragma omp section
     70     [&]() {
     71       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
     72       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
     73       g = 2;
     74       sivar = 22;
     75       // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
     76 
     77       // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     78       // LAMBDA: [[G_REF:%.+]] = load double*, double** [[G_PTR_REF]]
     79       // LAMBDA: store double 2.0{{.+}}, double* [[G_REF]]
     80 
     81       // LAMBDA: [[SIVAR_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
     82       // LAMBDA: [[SIVAR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[SIVAR_PTR_REF]]
     83       // LAMBDA: store i{{[0-9]+}} 22, i{{[0-9]+}}* [[SIVAR_REF]]
     84     }();
     85   }
     86   }();
     87   return 0;
     88 #elif defined(BLOCKS)
     89   // BLOCKS: [[G:@.+]] = global double
     90   // BLOCKS-LABEL: @main
     91   // BLOCKS: call {{.*}}void {{%.+}}(i8
     92   ^{
     93   // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
     94   // BLOCKS: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
     95 #pragma omp parallel
     96 #pragma omp sections private(g, sivar)
     97     {
     98     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
     99     // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca double,
    100     // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
    101     {
    102       g = 1;
    103       sivar = 111;
    104     }
    105     // BLOCKS: call {{.*}}void @__kmpc_for_static_init_4(
    106     // BLOCKS: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
    107     // BLOCKS: store i{{[0-9]+}} 111, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
    108     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    109     // BLOCKS: double* [[G_PRIVATE_ADDR]]
    110     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    111     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    112     // BLOCKS: i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]]
    113     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    114     // BLOCKS: call {{.*}}void {{%.+}}(i8
    115     // BLOCKS: call {{.*}}void @__kmpc_for_static_fini(
    116 #pragma omp section
    117     ^{
    118       // BLOCKS: define {{.+}} void {{@.+}}(i8*
    119       g = 2;
    120       sivar = 222;
    121       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    122       // BLOCKS: store double 2.0{{.+}}, double*
    123       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    124       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    125       // BLOCKS: store i{{[0-9]+}} 222, i{{[0-9]+}}*
    126       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
    127       // BLOCKS: ret
    128     }();
    129   }
    130   }();
    131   return 0;
    132 #else
    133   S<float> test;
    134   int t_var = 0;
    135   int vec[] = {1, 2};
    136   S<float> s_arr[] = {1, 2};
    137   S<float> var(3);
    138 #pragma omp parallel
    139 #pragma omp sections private(t_var, vec, s_arr, s_arr, var, var, sivar)
    140   {
    141     {
    142     vec[0] = t_var;
    143     s_arr[0] = var;
    144     sivar = 2;
    145     }
    146   }
    147   return tmain<int>();
    148 #endif
    149 }
    150 
    151 // CHECK: define i{{[0-9]+}} @main()
    152 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
    153 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
    154 // 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
    155 // CHECK: = call i{{.+}} [[TMAIN_INT:@.+]]()
    156 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
    157 // CHECK: ret
    158 //
    159 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
    160 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    161 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
    162 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_FLOAT_TY]]],
    163 // CHECK-NOT: alloca [2 x [[S_FLOAT_TY]]],
    164 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_FLOAT_TY]],
    165 // CHECK: [[SIVAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    166 // CHECK-NOT: alloca [[S_FLOAT_TY]],
    167 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    168 // CHECK: call i32 @__kmpc_single(
    169 // CHECK-NOT: [[T_VAR_PRIV]]
    170 // CHECK-NOT: [[VEC_PRIV]]
    171 // CHECK-NOT: [[SIVAR_PRIV]]
    172 // CHECK: {{.+}}:
    173 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_FLOAT_TY]]*
    174 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[S_ARR_PRIV_ITEM]])
    175 // CHECK-NOT: [[T_VAR_PRIV]]
    176 // CHECK-NOT: [[VEC_PRIV]]
    177 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
    178 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
    179 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]*
    180 // CHECK: call void @__kmpc_end_single(
    181 // CHECK: ret void
    182 
    183 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
    184 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
    185 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
    186 // 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
    187 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
    188 // CHECK: ret
    189 //
    190 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
    191 // CHECK: alloca i32,
    192 // CHECK: alloca i32,
    193 // CHECK: alloca i32,
    194 // CHECK: alloca i32,
    195 // CHECK: alloca i32,
    196 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
    197 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
    198 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_INT_TY]]],
    199 // CHECK-NOT: alloca [2 x [[S_INT_TY]]],
    200 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_INT_TY]],
    201 // CHECK-NOT: alloca [[S_INT_TY]],
    202 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    203 // CHECK-NOT: [[T_VAR_PRIV]]
    204 // CHECK-NOT: [[VEC_PRIV]]
    205 // CHECK: {{.+}}:
    206 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_INT_TY]]*
    207 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[S_ARR_PRIV_ITEM]])
    208 // CHECK-NOT: [[T_VAR_PRIV]]
    209 // CHECK-NOT: [[VEC_PRIV]]
    210 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[VAR_PRIV]])
    211 // CHECK: call void @__kmpc_for_static_init_4(
    212 // CHECK: call void @__kmpc_for_static_fini(
    213 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]* [[VAR_PRIV]])
    214 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]*
    215 // CHECK: ret void
    216 #endif
    217 
    218