1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -triple x86_64-apple-darwin10 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -triple x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
5 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -emit-llvm -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-apple-darwin10 -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
14 // CHECK-DAG: [[MAIN_A:@.+]] = internal global ptr null,
15 // CHECK-DAG: [[TMAIN_A:@.+]] = linkonce_odr global ptr null,
17 typedef void *omp_depend_t
;
22 #pragma omp depobj(obj) depend(inout: omp_all_memory)
24 volatile omp_depend_t temp
= obj
;
25 char* char_ptr
= reinterpret_cast<char*>(temp
);
34 #pragma omp depobj(a) depend(in:argv, ([3][*(int*)argv][4])argv)
35 #pragma omp depobj(argc) destroy
36 #pragma omp depobj(argc) update(inout)
40 int main(int argc
, char **argv
) {
41 static omp_depend_t a
;
43 #pragma omp depobj(a) depend(out:argc, argv)
44 #pragma omp depobj(b) destroy
45 #pragma omp depobj(b) update(mutexinoutset)
46 #pragma omp depobj(a) depend(iterator(char *p = argv[argc]:argv[0]:-1), out: p[0])
47 (void)tmain(a
), tmain(b
);
51 // CHECK-LABEL: tmainc
52 // CHECK: [[D_ADDR:%obj]] = alloca ptr,
53 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
54 // CHECK: [[DEP_ADDR_ADDR2:%.+]] = call ptr @__kmpc_alloc(i32 [[GTID]], i64 48, ptr null)
55 // CHECK: [[SZ_DEOOBJ:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_ADDR_ADDR2]], i{{.+}} 0, i{{.+}} 0
56 // CHECK: store i64 1, ptr [[SZ_DEOOBJ]], align 8
57 // CHECK: [[DEPOBJ_BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_ADDR2]], i{{.+}} 1
58 // CHECK: [[ADDR_ONE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEPOBJ_BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
59 // CHECK: store i64 0, ptr [[ADDR_ONE]], align 8
60 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEPOBJ_BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
61 // CHECK: store i64 0, ptr [[SZ_ADDR]], align 8
62 // CHECK: [[SZ_ADDR_NEW:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEPOBJ_BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
63 // CHECK: store {{i[0-9]+}} {{-?[0-9]+}}, ptr [[SZ_ADDR_NEW]], align 8
64 // CHECK: [[DEP_NEW:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_ADDR2]], i{{.+}} 1
65 // CHECK: store ptr [[DEP_NEW]], ptr [[D_ADDR]], align 8
67 // CHECK: [[B_ADDR:%b]] = alloca ptr,
68 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
69 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 [[GTID]], i64 72, ptr null)
70 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
71 // CHECK: store i64 2, ptr [[SZ_BASE]], align 8
72 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
73 // CHECK: [[ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
74 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
75 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
76 // CHECK: store i64 4, ptr [[SZ_ADDR]], align 8
77 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
78 // CHECK: store i8 3, ptr [[FLAGS_ADDR]], align 8
79 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 2
80 // CHECK: [[ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
81 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
82 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
83 // CHECK: store i64 8, ptr [[SZ_ADDR]], align 8
84 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
85 // CHECK: store i8 3, ptr [[FLAGS_ADDR]], align 8
86 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
87 // CHECK: store ptr [[BASE_ADDR]], ptr [[MAIN_A]], align 8
88 // CHECK: [[B:%.+]] = load ptr, ptr [[B_ADDR]], align 8
89 // CHECK: [[B_REF:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B]], i{{.+}} -1
90 // CHECK: call void @__kmpc_free(i32 [[GTID]], ptr [[B_REF]], ptr null)
91 // CHECK: [[B_BASE:%.+]] = load ptr, ptr [[B_ADDR]], align 8
92 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B_BASE]], i64 -1
93 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0
94 // CHECK: [[NUMDEPS:%.+]] = load i64, ptr [[NUMDEPS_ADDR]], align 8
95 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B_BASE]], i64 [[NUMDEPS]]
98 // CHECK: br label %[[BODY:.+]]
100 // CHECK: [[EL:%.+]] = phi ptr [ [[B_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ]
101 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 0, i{{.+}} 2
102 // CHECK: store i8 4, ptr [[FLAG_BASE]], align 8
103 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 1
104 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[EL_NEXT]], [[END]]
105 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]]
108 // Claculate toal number of elements.
109 // (argv[argc]-argv[0]-(-1)-1) / -(-1);
110 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR:%.+]], align 8
111 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR:%.+]], align 4
112 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
113 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
114 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
115 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
116 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 0
117 // CHECK: [[END:%.+]] = load ptr, ptr [[END_ADDR]], align 8
118 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint ptr [[BEGIN]] to i64
119 // CHECK: [[END_INT:%.+]] = ptrtoint ptr [[END]] to i64
120 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]]
121 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1
122 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1
123 // CHECK: [[BE_SUB_ST_SUB_1_SUB_1_DIV:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1
124 // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[BE_SUB_ST_SUB_1_SUB_1_DIV]]
126 // Allocate size is (NELEMS + 1) * sizeof(%struct.kmp_depend_info).
127 // sizeof(%struct.kmp_depend_info) == 24;
128 // CHECK: [[EXTRA_SZ:%.+]] = add nuw i64 1, [[NELEMS]]
129 // CHECK: [[SIZE:%.+]] = mul nuw i64 [[EXTRA_SZ]], 24
132 // kmp_depend_info* dep = (kmp_depend_info*)kmpc_alloc(SIZE);
133 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 %{{.+}}, i64 [[SIZE]], ptr null)
135 // dep[0].base_addr = NELEMS.
136 // CHECK: [[BASE_ADDR_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
137 // CHECK: store i64 [[NELEMS]], ptr [[BASE_ADDR_ADDR]], align 8
139 // iterator_counter = 1;
140 // CHECK: store i64 1, ptr [[ITERATOR_COUNTER_ADDR:%.+]], align 8
142 // NITER = (argv[argc]-argv[0]-(-1)-1) / -(-1);
143 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
144 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR]], align 4
145 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
146 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
147 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
148 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
149 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 0
150 // CHECK: [[END:%.+]] = load ptr, ptr [[END_ADDR]], align 8
151 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint ptr [[BEGIN]] to i64
152 // CHECK: [[END_INT:%.+]] = ptrtoint ptr [[END]] to i64
153 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]]
154 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1
155 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1
156 // CHECK: [[NITER:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1
159 // CHECK: store i64 0, ptr [[COUNTER_ADDR:%.+]], align 8
160 // CHECK: br label %[[CONT:.+]]
163 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
164 // CHECK: [[CMP:%.+]] = icmp slt i64 [[COUNTER]], [[NITER]]
165 // CHECK: br i1 [[CMP]], label %[[BODY:.+]], label %[[EXIT:.+]]
169 // p = BEGIN + COUNTER * STEP;
170 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
171 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR]], align 4
172 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
173 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
174 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
175 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
176 // CHECK: [[CS_MUL:%.+]] = mul nsw i64 [[COUNTER]], -1
177 // CHECK: [[CS_MUL_BEGIN_ADD:%.+]] = getelementptr inbounds i8, ptr [[BEGIN]], i64 [[CS_MUL]]
178 // CHECK: store ptr [[CS_MUL_BEGIN_ADD]], ptr [[P_ADDR:%.+]], align 8
181 // CHECK: [[P:%.+]] = load ptr, ptr [[P_ADDR]], align 8
182 // CHECK: [[P0:%.+]] = getelementptr inbounds i8, ptr [[P]], i64 0
183 // CHECK: [[P0_ADDR:%.+]] = ptrtoint ptr [[P0]] to i64
185 // dep[ITERATOR_COUNTER].base_addr = &p[0];
186 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, ptr [[ITERATOR_COUNTER_ADDR]], align 8
187 // CHECK: [[DEP_IC:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i64 [[ITERATOR_COUNTER]]
188 // CHECK: [[DEP_IC_BASE_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 0
189 // CHECK: store i64 [[P0_ADDR]], ptr [[DEP_IC_BASE_ADDR]], align 8
191 // dep[ITERATOR_COUNTER].size = sizeof(p[0]);
192 // CHECK: [[DEP_IC_SIZE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 1
193 // CHECK: store i64 1, ptr [[DEP_IC_SIZE]], align 8
194 // dep[ITERATOR_COUNTER].flags = in_out;
195 // CHECK: [[DEP_IC_FLAGS:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 2
196 // CHECK: store i8 3, ptr [[DEP_IC_FLAGS]], align 8
198 // ITERATOR_COUNTER = ITERATOR_COUNTER + 1;
199 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, ptr [[ITERATOR_COUNTER_ADDR]], align 8
200 // CHECK: [[INC:%.+]] = add nuw i64 [[ITERATOR_COUNTER]], 1
201 // CHECK: store i64 [[INC]], ptr [[ITERATOR_COUNTER_ADDR]], align 8
203 // COUNTER = COUNTER + 1;
204 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
205 // CHECK: [[INC:%.+]] = add nsw i64 [[COUNTER]], 1
206 // CHECK: store i64 [[INC]], ptr [[COUNTER_ADDR]], align 8
207 // CHECK: br label %[[CONT]]
212 // CHECK: [[DEP_BEGIN:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i64 1
213 // CHECK: store ptr [[DEP_BEGIN]], ptr [[MAIN_A]], align 8
215 // CHECK-LABEL: tmain
216 // CHECK: [[ARGC_ADDR:%.+]] = alloca ptr,
217 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
218 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 [[GTID]], i64 72, ptr null)
219 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
220 // CHECK: store i64 2, ptr [[SZ_BASE]], align 8
221 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
222 // CHECK: [[ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
223 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
224 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
225 // CHECK: store i64 8, ptr [[SZ_ADDR]], align 8
226 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
227 // CHECK: store i8 1, ptr [[FLAGS_ADDR]], align 8
228 // CHECK: [[SHAPE_ADDR:%.+]] = load ptr, ptr [[ARGV_ADDR:%.+]], align 8
229 // CHECK: [[SZ1:%.+]] = mul nuw i64 12, %{{.+}}
230 // CHECK: [[SZ:%.+]] = mul nuw i64 [[SZ1]], 4
231 // CHECK: [[SHAPE:%.+]] = ptrtoint ptr [[SHAPE_ADDR]] to i64
232 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 2
233 // CHECK: [[ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
234 // CHECK: store i64 [[SHAPE]], ptr [[ADDR]], align 8
235 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
236 // CHECK: store i64 [[SZ]], ptr [[SZ_ADDR]], align 8
237 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
238 // CHECK: store i8 1, ptr [[FLAGS_ADDR]], align 8
239 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
240 // CHECK: store ptr [[BASE_ADDR]], ptr [[TMAIN_A]], align 8
241 // CHECK: [[ARGC:%.+]] = load ptr, ptr [[ARGC_ADDR]], align 8
242 // CHECK: [[ARGC_REF:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC]], i{{.+}} -1
243 // CHECK: call void @__kmpc_free(i32 [[GTID]], ptr [[ARGC_REF]], ptr null)
244 // CHECK: [[ARGC_BASE:%.+]] = load ptr, ptr [[ARGC_ADDR]], align 8
245 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC_BASE]], i64 -1
246 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0
247 // CHECK: [[NUMDEPS:%.+]] = load i64, ptr [[NUMDEPS_ADDR]], align 8
248 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC_BASE]], i64 [[NUMDEPS]]
249 // CHECK: br label %[[BODY:.+]]
251 // CHECK: [[EL:%.+]] = phi ptr [ [[ARGC_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ]
252 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds nuw %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 0, i{{.+}} 2
253 // CHECK: store i8 3, ptr [[FLAG_BASE]], align 8
254 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 1
255 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[EL_NEXT]], [[END]]
256 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]]