Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -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 x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
      5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-apple-darwin10 -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   S<T> &operator=(const S<T> &);
     17   operator T() { return T(); }
     18   ~S() {}
     19 };
     20 
     21 volatile int g = 1212;
     22 volatile int &g1 = g;
     23 float f;
     24 char cnt;
     25 
     26 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
     27 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
     28 // CHECK-DAG: [[IMPLICIT_BARRIER_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 66, i32 0, i32 0, i8*
     29 // CHECK-DAG: [[F:@.+]] = global float 0.0
     30 // CHECK-DAG: [[CNT:@.+]] = global i8 0
     31 template <typename T>
     32 T tmain() {
     33   S<T> test;
     34   T *pvar = &test.f;
     35   T &lvar = test.f;
     36 #pragma omp parallel
     37 #pragma omp for linear(pvar, lvar)
     38   for (int i = 0; i < 2; ++i) {
     39     ++pvar, ++lvar;
     40   }
     41   return T();
     42 }
     43 
     44 int main() {
     45 #ifdef LAMBDA
     46   // LAMBDA: [[G:@.+]] = global i{{[0-9]+}} 1212,
     47   // LAMBDA-LABEL: @main
     48   // LAMBDA: call void [[OUTER_LAMBDA:@.+]](
     49   [&]() {
     50   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
     51   // LAMBDA: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
     52 #pragma omp parallel
     53 #pragma omp for linear(g, g1:5)
     54   for (int i = 0; i < 2; ++i) {
     55     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
     56     // LAMBDA: alloca i{{[0-9]+}},
     57     // LAMBDA: [[G_START_ADDR:%.+]] = alloca i{{[0-9]+}},
     58     // LAMBDA: alloca i{{[0-9]+}},
     59     // LAMBDA: alloca i{{[0-9]+}},
     60     // LAMBDA: alloca i{{[0-9]+}},
     61     // LAMBDA: alloca i{{[0-9]+}},
     62     // LAMBDA: alloca i{{[0-9]+}},
     63     // LAMBDA: alloca i{{[0-9]+}},
     64     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
     65     // LAMBDA: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}
     66     // LAMBDA: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]]
     67     // LAMBDA: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
     68     // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_START_ADDR]]
     69     // LAMBDA: [[CNT:%.+]] = load i32, i32*
     70     // LAMBDA: [[MUL:%.+]] = mul nsw i32 [[CNT]], 5
     71     // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], [[MUL]]
     72     // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
     73     // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_PRIVATE_ADDR]],
     74     // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], 5
     75     // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
     76     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     77     // LAMBDA: store i{{[0-9]+}}* [[G_PRIVATE_ADDR]], i{{[0-9]+}}** [[G_PRIVATE_ADDR_REF]]
     78     // LAMBDA: call void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
     79     // LAMBDA: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
     80     g += 5;
     81     g1 += 5;
     82     // LAMBDA: call void @__kmpc_barrier(%{{.+}}* @{{.+}}, i{{[0-9]+}} [[GTID]])
     83     [&]() {
     84       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
     85       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
     86       g = 2;
     87       g1 = 2;
     88       // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
     89       // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
     90       // LAMBDA: [[G_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[G_PTR_REF]]
     91       // LAMBDA: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[G_REF]]
     92     }();
     93   }
     94   }();
     95   return 0;
     96 #elif defined(BLOCKS)
     97   // BLOCKS: [[G:@.+]] = global i{{[0-9]+}} 1212,
     98   // BLOCKS-LABEL: @main
     99   // BLOCKS: call void {{%.+}}(i8
    100   ^{
    101   // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
    102   // BLOCKS: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
    103 #pragma omp parallel
    104 #pragma omp for linear(g, g1:5)
    105   for (int i = 0; i < 2; ++i) {
    106     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
    107     // BLOCKS: alloca i{{[0-9]+}},
    108     // BLOCKS: [[G_START_ADDR:%.+]] = alloca i{{[0-9]+}},
    109     // BLOCKS: alloca i{{[0-9]+}},
    110     // BLOCKS: alloca i{{[0-9]+}},
    111     // BLOCKS: alloca i{{[0-9]+}},
    112     // BLOCKS: alloca i{{[0-9]+}},
    113     // BLOCKS: alloca i{{[0-9]+}},
    114     // BLOCKS: alloca i{{[0-9]+}},
    115     // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
    116     // BLOCKS: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}
    117     // BLOCKS: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]]
    118     // BLOCKS: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
    119     // BLOCKS: [[VAL:%.+]] = load i32, i32* [[G_START_ADDR]]
    120     // BLOCKS: [[CNT:%.+]] = load i32, i32*
    121     // BLOCKS: [[MUL:%.+]] = mul nsw i32 [[CNT]], 5
    122     // BLOCKS: [[ADD:%.+]] = add nsw i32 [[VAL]], [[MUL]]
    123     // BLOCKS: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
    124     // BLOCKS: [[VAL:%.+]] = load i32, i32* [[G_PRIVATE_ADDR]],
    125     // BLOCKS: [[ADD:%.+]] = add nsw i32 [[VAL]], 5
    126     // BLOCKS: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
    127     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    128     // BLOCKS: i{{[0-9]+}}* [[G_PRIVATE_ADDR]]
    129     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    130     // BLOCKS: call void {{%.+}}(i8
    131     // BLOCKS: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
    132     g += 5;
    133     g1 += 5;
    134     // BLOCKS: call void @__kmpc_barrier(%{{.+}}* @{{.+}}, i{{[0-9]+}} [[GTID]])
    135     g = 1;
    136     g1 = 5;
    137     ^{
    138       // BLOCKS: define {{.+}} void {{@.+}}(i8*
    139       g = 2;
    140       g1 = 2;
    141       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    142       // BLOCKS: store i{{[0-9]+}} 2, i{{[0-9]+}}*
    143       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
    144       // BLOCKS: ret
    145     }();
    146   }
    147   }();
    148   return 0;
    149 #else
    150   S<float> test;
    151   float *pvar = &test.f;
    152   long long lvar = 0;
    153 #pragma omp parallel
    154 #pragma omp for linear(pvar, lvar : 3)
    155   for (int i = 0; i < 2; ++i) {
    156     pvar += 3, lvar += 3;
    157   }
    158   return tmain<int>();
    159 #endif
    160 }
    161 
    162 // CHECK: define i{{[0-9]+}} @main()
    163 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
    164 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
    165 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 2, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, float**, i64*)* [[MAIN_MICROTASK:@.+]] to void
    166 // CHECK: = call {{.+}} [[TMAIN_INT:@.+]]()
    167 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
    168 // CHECK: ret
    169 
    170 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, float** dereferenceable(8) %{{.+}}, i64* dereferenceable(8) %{{.+}})
    171 // CHECK: alloca i{{[0-9]+}},
    172 // CHECK: [[PVAR_START:%.+]] = alloca float*,
    173 // CHECK: [[LVAR_START:%.+]] = alloca i64,
    174 // CHECK: alloca i{{[0-9]+}},
    175 // CHECK: alloca i{{[0-9]+}},
    176 // CHECK: alloca i{{[0-9]+}},
    177 // CHECK: alloca i{{[0-9]+}},
    178 // CHECK: alloca i{{[0-9]+}},
    179 // CHECK: [[PVAR_PRIV:%.+]] = alloca float*,
    180 // CHECK: [[LVAR_PRIV:%.+]] = alloca i64,
    181 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    182 
    183 // Check for default initialization.
    184 // CHECK: [[PVAR_REF:%.+]] = load float**, float*** %
    185 // CHECK: [[LVAR_REF:%.+]] = load i64*, i64** %
    186 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_REF]],
    187 // CHECK: store float* [[PVAR_VAL]], float** [[PVAR_START]],
    188 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_REF]],
    189 // CHECK: store i64 [[LVAR_VAL]], i64* [[LVAR_START]],
    190 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
    191 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_START]],
    192 // CHECK: [[CNT:%.+]] = load i32, i32*
    193 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
    194 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
    195 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 [[IDX]]
    196 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
    197 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_START]],
    198 // CHECK: [[CNT:%.+]] = load i32, i32*
    199 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
    200 // CHECK: [[CONV:%.+]] = sext i32 [[MUL]] to i64
    201 // CHECK: [[VAL:%.+]] = add nsw i64 [[LVAR_VAL]], [[CONV]]
    202 // CHECK: store i64 [[VAL]], i64* [[LVAR_PRIV]],
    203 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_PRIV]]
    204 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 3
    205 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
    206 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_PRIV]],
    207 // CHECK: [[ADD:%.+]] = add nsw i64 [[LVAR_VAL]], 3
    208 // CHECK: store i64 [[ADD]], i64* [[LVAR_PRIV]],
    209 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
    210 // CHECK: call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], i{{[0-9]+}} [[GTID]])
    211 // CHECK: ret void
    212 
    213 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
    214 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
    215 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
    216 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 2, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, i32**, i32*)* [[TMAIN_MICROTASK:@.+]] to void
    217 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
    218 // CHECK: ret
    219 //
    220 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i32** dereferenceable(8) %{{.+}}, i32* dereferenceable(4) %{{.+}})
    221 // CHECK: alloca i{{[0-9]+}},
    222 // CHECK: [[PVAR_START:%.+]] = alloca i32*,
    223 // CHECK: [[LVAR_START:%.+]] = alloca i32,
    224 // CHECK: alloca i{{[0-9]+}},
    225 // CHECK: alloca i{{[0-9]+}},
    226 // CHECK: alloca i{{[0-9]+}},
    227 // CHECK: alloca i{{[0-9]+}},
    228 // CHECK: alloca i{{[0-9]+}},
    229 // CHECK: [[PVAR_PRIV:%.+]] = alloca i32*,
    230 // CHECK: [[LVAR_PRIV:%.+]] = alloca i32,
    231 // CHECK: [[LVAR_PRIV_REF:%.+]] = alloca i32*,
    232 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
    233 
    234 // Check for default initialization.
    235 // CHECK: [[PVAR_REF:%.+]] = load i32**, i32*** %
    236 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_REF]],
    237 // CHECK: store i32* [[PVAR_VAL]], i32** [[PVAR_START]],
    238 // CHECK: [[LVAR_REF:%.+]] = load i32*, i32** %
    239 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_REF]],
    240 // CHECK: store i32 [[LVAR_VAL]], i32* [[LVAR_START]],
    241 // CHECK: store i32* [[LVAR_PRIV]], i32** [[LVAR_PRIV_REF]],
    242 
    243 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
    244 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_START]],
    245 // CHECK: [[CNT:%.+]] = load i32, i32*
    246 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
    247 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
    248 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i64 [[IDX]]
    249 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
    250 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_START]],
    251 // CHECK: [[CNT:%.+]] = load i32, i32*
    252 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
    253 // CHECK: [[VAL:%.+]] = add nsw i32 [[LVAR_VAL]], [[MUL]]
    254 // CHECK: store i32 [[VAL]], i32* [[LVAR_PRIV]],
    255 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_PRIV]]
    256 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i32 1
    257 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
    258 // CHECK: [[LVAR_PRIV:%.+]] = load i32*, i32** [[LVAR_PRIV_REF]],
    259 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_PRIV]],
    260 // CHECK: [[ADD:%.+]] = add nsw i32 [[LVAR_VAL]], 1
    261 // CHECK: store i32 [[ADD]], i32* [[LVAR_PRIV]],
    262 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
    263 // CHECK: call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], i{{[0-9]+}} [[GTID]])
    264 // CHECK: ret void
    265 #endif
    266 
    267