• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
9 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DLAMBDA -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
11 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -fblocks -DBLOCKS -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
13 // expected-no-diagnostics
14 #ifndef HEADER
15 #define HEADER
16 
17 template <class T>
18 struct S {
19   T f;
SS20   S(T a) : f(a) {}
SS21   S() : f() {}
22   S<T> &operator=(const S<T> &);
operator TS23   operator T() { return T(); }
~SS24   ~S() {}
25 };
26 
27 volatile int g = 1212;
28 float f;
29 char cnt;
30 
31 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
32 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
33 // CHECK-DAG: [[F:@.+]] = global float 0.0
34 // CHECK-DAG: [[CNT:@.+]] = global i8 0
35 template <typename T>
tmain()36 T tmain() {
37   S<T> test;
38   T *pvar = &test.f;
39   T lvar = T();
40 #pragma omp parallel for linear(pvar, lvar)
41   for (int i = 0; i < 2; ++i) {
42     ++pvar, ++lvar;
43   }
44   return T();
45 }
46 
main()47 int main() {
48 #ifdef LAMBDA
49   // LAMBDA: [[G:@.+]] = global i{{[0-9]+}} 1212,
50   // LAMBDA-LABEL: @main
51   // LAMBDA: call void [[OUTER_LAMBDA:@.+]](
52   [&]() {
53   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
54   // LAMBDA: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i32* [[G]])
55 #pragma omp parallel for linear(g:5)
56   for (int i = 0; i < 2; ++i) {
57     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* nonnull align 4 dereferenceable(4) %{{.+}})
58     // LAMBDA: alloca i{{[0-9]+}},
59     // LAMBDA: alloca i{{[0-9]+}},
60     // LAMBDA: [[G_START_ADDR:%.+]] = alloca i{{[0-9]+}},
61     // LAMBDA: alloca i{{[0-9]+}},
62     // LAMBDA: alloca i{{[0-9]+}},
63     // LAMBDA: alloca i{{[0-9]+}},
64     // LAMBDA: alloca i{{[0-9]+}},
65     // LAMBDA: alloca i{{[0-9]+}},
66     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
67     // LAMBDA: store i32 0,
68     // LAMBDA: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}
69     // LAMBDA: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]]
70     // LAMBDA: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
71     // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_START_ADDR]]
72     // LAMBDA: [[CNT:%.+]] = load i32, i32*
73     // LAMBDA: [[MUL:%.+]] = mul nsw i32 [[CNT]], 5
74     // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], [[MUL]]
75     // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
76     // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_PRIVATE_ADDR]],
77     // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], 5
78     // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
79     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
80     // LAMBDA: store i{{[0-9]+}}* [[G_PRIVATE_ADDR]], i{{[0-9]+}}** [[G_PRIVATE_ADDR_REF]]
81     // LAMBDA: call void [[INNER_LAMBDA:@.+]](%{{.+}}* {{[^,]*}} [[ARG]])
82     // LAMBDA: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
83     g += 5;
84     [&]() {
85       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* {{[^,]*}} [[ARG_PTR:%.+]])
86       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
87       g = 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 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i32* [[G]])
103 #pragma omp parallel for linear(g:5)
104   for (int i = 0; i < 2; ++i) {
105     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* nonnull align 4 dereferenceable(4) %{{.+}})
106     // BLOCKS: alloca i{{[0-9]+}},
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: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
115     // BLOCKS: store i32 0,
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     g = 1;
134     ^{
135       // BLOCKS: define {{.+}} void {{@.+}}(i8*
136       g = 2;
137       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
138       // BLOCKS: store i{{[0-9]+}} 2, i{{[0-9]+}}*
139       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
140       // BLOCKS: ret
141     }();
142   }
143   }();
144   return 0;
145 #else
146   S<float> test;
147   float *pvar = &test.f;
148   long long lvar = 0;
149 #pragma omp parallel for linear(pvar, lvar : 3)
150   for (int i = 0; i < 2; ++i) {
151     pvar += 3, lvar += 3;
152   }
153   return tmain<int>();
154 #endif
155 }
156 
157 // CHECK: define i{{[0-9]+}} @main()
158 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
159 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* {{[^,]*}} [[TEST]])
160 // 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
161 // CHECK: = call {{.+}} [[TMAIN_INT:@.+]]()
162 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
163 // CHECK: ret
164 
165 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, float** nonnull align 8 dereferenceable(8) %{{.+}}, i64* nonnull align 8 dereferenceable(8) %{{.+}})
166 // CHECK: alloca i{{[0-9]+}},
167 // CHECK: alloca i{{[0-9]+}},
168 // CHECK: [[PVAR_START:%.+]] = alloca float*,
169 // CHECK: [[LVAR_START:%.+]] = alloca i64,
170 // CHECK: alloca i{{[0-9]+}},
171 // CHECK: alloca i{{[0-9]+}},
172 // CHECK: alloca i{{[0-9]+}},
173 // CHECK: alloca i{{[0-9]+}},
174 // CHECK: [[PVAR_PRIV:%.+]] = alloca float*,
175 // CHECK: [[LVAR_PRIV:%.+]] = alloca i64,
176 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
177 
178 // CHECK: [[PVAR_REF:%.+]] = load float**, float*** %
179 // CHECK: [[LVAR_REF:%.+]] = load i64*, i64** %
180 
181 // Check for default initialization.
182 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_REF]],
183 // CHECK: store float* [[PVAR_VAL]], float** [[PVAR_START]],
184 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_REF]],
185 // CHECK: store i64 [[LVAR_VAL]], i64* [[LVAR_START]],
186 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
187 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_START]],
188 // CHECK: [[CNT:%.+]] = load i32, i32*
189 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
190 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
191 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 [[IDX]]
192 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
193 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_START]],
194 // CHECK: [[CNT:%.+]] = load i32, i32*
195 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
196 // CHECK: [[CONV:%.+]] = sext i32 [[MUL]] to i64
197 // CHECK: [[VAL:%.+]] = add nsw i64 [[LVAR_VAL]], [[CONV]]
198 // CHECK: store i64 [[VAL]], i64* [[LVAR_PRIV]],
199 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_PRIV]]
200 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 3
201 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
202 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_PRIV]],
203 // CHECK: [[ADD:%.+]] = add nsw i64 [[LVAR_VAL]], 3
204 // CHECK: store i64 [[ADD]], i64* [[LVAR_PRIV]],
205 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
206 // CHECK: ret void
207 
208 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
209 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
210 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* {{[^,]*}} [[TEST]])
211 // 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
212 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
213 // CHECK: ret
214 //
215 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i32** nonnull align 8 dereferenceable(8) %{{.+}}, i32* nonnull align 4 dereferenceable(4) %{{.+}})
216 // CHECK: alloca i{{[0-9]+}},
217 // CHECK: alloca i{{[0-9]+}},
218 // CHECK: [[PVAR_START:%.+]] = alloca i32*,
219 // CHECK: [[LVAR_START:%.+]] = alloca i32,
220 // CHECK: alloca i{{[0-9]+}},
221 // CHECK: alloca i{{[0-9]+}},
222 // CHECK: alloca i{{[0-9]+}},
223 // CHECK: alloca i{{[0-9]+}},
224 // CHECK: [[PVAR_PRIV:%.+]] = alloca i32*,
225 // CHECK: [[LVAR_PRIV:%.+]] = alloca i32,
226 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
227 
228 // CHECK: [[PVAR_REF:%.+]] = load i32**, i32*** %
229 // CHECK: [[LVAR_REF:%.+]] = load i32*, i32** %
230 
231 // Check for default initialization.
232 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_REF]],
233 // CHECK: store i32* [[PVAR_VAL]], i32** [[PVAR_START]],
234 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_REF]],
235 // CHECK: store i32 [[LVAR_VAL]], i32* [[LVAR_START]],
236 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
237 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_START]],
238 // CHECK: [[CNT:%.+]] = load i32, i32*
239 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
240 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
241 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i64 [[IDX]]
242 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
243 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_START]],
244 // CHECK: [[CNT:%.+]] = load i32, i32*
245 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
246 // CHECK: [[VAL:%.+]] = add nsw i32 [[LVAR_VAL]], [[MUL]]
247 // CHECK: store i32 [[VAL]], i32* [[LVAR_PRIV]],
248 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_PRIV]]
249 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i32 1
250 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
251 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_PRIV]],
252 // CHECK: [[ADD:%.+]] = add nsw i32 [[LVAR_VAL]], 1
253 // CHECK: store i32 [[ADD]], i32* [[LVAR_PRIV]],
254 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
255 // CHECK: ret void
256 #endif
257 
258