• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
SS14   S(T a) : f(a) {}
SS15   S() : f() {}
operator TS16   operator T() { return T(); }
~SS17   ~S() {}
18 };
19 
20 volatile double g;
21 volatile double &g1 = g;
22 
23 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
24 // CHECK: [[S_INT_TY:%.+]] = type { i{{[0-9]+}} }
25 template <typename T>
tmain()26 T tmain() {
27   S<T> test;
28   T t_var = T();
29   T vec[] = {1, 2};
30   S<T> s_arr[] = {1, 2};
31   S<T> &var = test;
32 #pragma omp parallel
33 #pragma omp for private(t_var, vec, s_arr, s_arr, var, var)
34   for (int i = 0; i < 2; ++i) {
35     vec[i] = t_var;
36     s_arr[i] = var;
37   }
38   return T();
39 }
40 
main()41 int main() {
42   static int svar;
43 #ifdef LAMBDA
44   // LAMBDA: [[G:@.+]] = global double
45   // LAMBDA-LABEL: @main
46   // LAMBDA: call{{.*}} void [[OUTER_LAMBDA:@.+]](
47   [&]() {
48   static float sfvar;
49   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
50   // LAMBDA: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
51 #pragma omp parallel
52 #pragma omp for private(g, g1, svar, sfvar)
53   for (int i = 0; i < 2; ++i) {
54     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
55     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca double,
56     // LAMBDA: [[SVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
57     // LAMBDA: [[SFVAR_PRIVATE_ADDR:%.+]] = alloca float,
58     g = 1;
59     g1 = 1;
60     svar = 3;
61     sfvar = 4.0;
62     // LAMBDA: call {{.*}}void @__kmpc_for_static_init_4(
63     // LAMBDA: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
64     // LAMBDA: store i{{[0-9]+}} 3, i{{[0-9]+}}* [[SVAR_PRIVATE_ADDR]],
65     // LAMBDA: store float 4.0{{.+}}, float* [[SFVAR_PRIVATE_ADDR]],
66     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
67     // LAMBDA: store double* [[G_PRIVATE_ADDR]], double** [[G_PRIVATE_ADDR_REF]]
68     // LAMBDA: [[SVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
69     // LAMBDA: store i{{[0-9]+}}* [[SVAR_PRIVATE_ADDR]], i{{[0-9]+}}** [[SVAR_PRIVATE_ADDR_REF]]
70     // LAMBDA: [[SFVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
71     // LAMBDA: store float* [[SFVAR_PRIVATE_ADDR]], float** [[SFVAR_PRIVATE_ADDR_REF]]
72     // LAMBDA: call{{.*}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
73     // LAMBDA: call {{.*}}void @__kmpc_for_static_fini(
74     [&]() {
75       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
76       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
77       g = 2;
78       g1 = 2;
79       svar = 4;
80       sfvar = 8.0;
81       // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
82       // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
83       // LAMBDA: [[G_REF:%.+]] = load double*, double** [[G_PTR_REF]]
84       // LAMBDA: store double 2.0{{.+}}, double* [[G_REF]]
85       // LAMBDA: [[SVAR_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
86       // LAMBDA: [[SVAR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[SVAR_PTR_REF]]
87       // LAMBDA: store i{{[0-9]+}} 4, i{{[0-9]+}}* [[SVAR_REF]]
88       // LAMBDA: [[SFVAR_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
89       // LAMBDA: [[SFVAR_REF:%.+]] = load float*, float** [[SFVAR_PTR_REF]]
90       // LAMBDA: store float 8.0{{.+}}, float* [[SFVAR_REF]]
91     }();
92   }
93   }();
94   return 0;
95 #elif defined(BLOCKS)
96   // BLOCKS: [[G:@.+]] = global double
97   // BLOCKS-LABEL: @main
98   // BLOCKS: call {{.*}}void {{%.+}}(i8
99   ^{
100   static float sfvar;
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 private(g, g1, svar, sfvar)
105   for (int i = 0; i < 2; ++i) {
106     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
107     // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca double,
108     // BLOCKS: [[SVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
109     // BLOCKS: [[SFVAR_PRIVATE_ADDR:%.+]] = alloca float,
110     g = 1;
111     g1 = 1;
112     svar = 2;
113     sfvar = 3.0;
114     // BLOCKS: call {{.*}}void @__kmpc_for_static_init_4(
115     // BLOCKS: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
116     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
117     // BLOCKS: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[SVAR_PRIVATE_ADDR]],
118     // BLOCKS-NOT: [[SVAR]]{{[[^:word:]]}}
119     // BLOCKS: store float 3.0{{.+}}, float* [[SFVAR_PRIVATE_ADDR]],
120     // BLOCKS-NOT: [[SFVAR]]{{[[^:word:]]}}
121     // BLOCKS: double* [[G_PRIVATE_ADDR]]
122     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
123     // BLOCKS: i{{[0-9]+}}* [[SVAR_PRIVATE_ADDR]]
124     // BLOCKS-NOT: [[SVAR]]{{[[^:word:]]}}
125     // BLOCKS: float* [[SFVAR_PRIVATE_ADDR]]
126     // BLOCKS-NOT: [[SFVAR]]{{[[^:word:]]}}
127     // BLOCKS: call {{.*}}void {{%.+}}(i8
128     // BLOCKS: call {{.*}}void @__kmpc_for_static_fini(
129     ^{
130       // BLOCKS: define {{.+}} void {{@.+}}(i8*
131       g = 2;
132       g1 = 2;
133       svar = 4;
134       sfvar = 9.0;
135       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
136       // BLOCKS: store double 2.0{{.+}}, double*
137       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
138       // BLOCKS-NOT: [[SVAR]]{{[[^:word:]]}}
139       // BLOCKS: store i{{[0-9]+}} 4, i{{[0-9]+}}*
140       // BLOCKS-NOT: [[SVAR]]{{[[^:word:]]}}
141       // BLOCKS-NOT: [[SFVAR]]{{[[^:word:]]}}
142       // BLOCKS: store float 9.0{{.+}}, float*
143       // BLOCKS-NOT: [[SFVAR]]{{[[^:word:]]}}
144       // BLOCKS: ret
145     }();
146   }
147   }();
148   return 0;
149 #else
150   S<float> test;
151   int t_var = 0;
152   int vec[] = {1, 2};
153   S<float> s_arr[] = {1, 2};
154   S<float> &var = test;
155 #pragma omp parallel
156 #pragma omp for private(t_var, vec, s_arr, s_arr, var, var, svar)
157   for (int i = 0; i < 2; ++i) {
158     vec[i] = t_var;
159     s_arr[i] = var;
160   }
161   int i;
162 #pragma omp parallel
163 #pragma omp for private(i)
164   for (i = 0; i < 2; ++i) {
165     ;
166   }
167   return tmain<int>();
168 #endif
169 }
170 
171 // CHECK: define i{{[0-9]+}} @main()
172 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
173 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
174 // 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
175 // CHECK: = call i{{.+}} [[TMAIN_INT:@.+]]()
176 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
177 // CHECK: ret
178 //
179 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
180 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
181 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
182 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_FLOAT_TY]]],
183 // CHECK-NOT: alloca [2 x [[S_FLOAT_TY]]],
184 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_FLOAT_TY]],
185 // CHECK-NOT: alloca [[S_FLOAT_TY]],
186 // CHECK: [[S_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
187 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
188 // CHECK-NOT: [[T_VAR_PRIV]]
189 // CHECK-NOT: [[VEC_PRIV]]
190 // CHECK: {{.+}}:
191 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_FLOAT_TY]]*
192 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[S_ARR_PRIV_ITEM]])
193 // CHECK-NOT: [[T_VAR_PRIV]]
194 // CHECK-NOT: [[VEC_PRIV]]
195 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
196 // CHECK: call void @__kmpc_for_static_init_4(
197 // CHECK: call void @__kmpc_for_static_fini(
198 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
199 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]*
200 // CHECK: ret void
201 
202 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
203 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
204 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
205 // 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
206 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
207 // CHECK: ret
208 //
209 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
210 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
211 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
212 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_INT_TY]]],
213 // CHECK-NOT: alloca [2 x [[S_INT_TY]]],
214 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_INT_TY]],
215 // CHECK-NOT: alloca [[S_INT_TY]],
216 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
217 // CHECK-NOT: [[T_VAR_PRIV]]
218 // CHECK-NOT: [[VEC_PRIV]]
219 // CHECK: {{.+}}:
220 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_INT_TY]]*
221 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[S_ARR_PRIV_ITEM]])
222 // CHECK-NOT: [[T_VAR_PRIV]]
223 // CHECK-NOT: [[VEC_PRIV]]
224 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[VAR_PRIV]])
225 // CHECK: call void @__kmpc_for_static_init_4(
226 // CHECK: call void @__kmpc_for_static_fini(
227 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]* [[VAR_PRIV]])
228 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]*
229 // CHECK: ret void
230 #endif
231 
232