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
;
25 #pragma omp depobj(a) depend(in:argv, ([3][*(int*)argv][4])argv)
26 #pragma omp depobj(argc) destroy
27 #pragma omp depobj(argc) update(inout)
31 int main(int argc
, char **argv
) {
32 static omp_depend_t a
;
34 #pragma omp depobj(a) depend(out:argc, argv)
35 #pragma omp depobj(b) destroy
36 #pragma omp depobj(b) update(mutexinoutset)
37 #pragma omp depobj(a) depend(iterator(char *p = argv[argc]:argv[0]:-1), out: p[0])
38 (void)tmain(a
), tmain(b
);
43 // CHECK: [[B_ADDR:%b]] = alloca ptr,
44 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
45 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 [[GTID]], i64 72, ptr null)
46 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
47 // CHECK: store i64 2, ptr [[SZ_BASE]], align 8
48 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
49 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
50 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
51 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
52 // CHECK: store i64 4, ptr [[SZ_ADDR]], align 8
53 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
54 // CHECK: store i8 3, ptr [[FLAGS_ADDR]], align 8
55 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 2
56 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
57 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
58 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
59 // CHECK: store i64 8, ptr [[SZ_ADDR]], align 8
60 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
61 // CHECK: store i8 3, ptr [[FLAGS_ADDR]], align 8
62 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
63 // CHECK: store ptr [[BASE_ADDR]], ptr [[MAIN_A]], align 8
64 // CHECK: [[B:%.+]] = load ptr, ptr [[B_ADDR]], align 8
65 // CHECK: [[B_REF:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B]], i{{.+}} -1
66 // CHECK: call void @__kmpc_free(i32 [[GTID]], ptr [[B_REF]], ptr null)
67 // CHECK: [[B_BASE:%.+]] = load ptr, ptr [[B_ADDR]], align 8
68 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B_BASE]], i64 -1
69 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0
70 // CHECK: [[NUMDEPS:%.+]] = load i64, ptr [[NUMDEPS_ADDR]], align 8
71 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[B_BASE]], i64 [[NUMDEPS]]
72 // CHECK: br label %[[BODY:.+]]
74 // CHECK: [[EL:%.+]] = phi ptr [ [[B_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ]
75 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 0, i{{.+}} 2
76 // CHECK: store i8 4, ptr [[FLAG_BASE]], align 8
77 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 1
78 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[EL_NEXT]], [[END]]
79 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]]
82 // Claculate toal number of elements.
83 // (argv[argc]-argv[0]-(-1)-1) / -(-1);
84 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR:%.+]], align 8
85 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR:%.+]], align 4
86 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
87 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
88 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
89 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
90 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 0
91 // CHECK: [[END:%.+]] = load ptr, ptr [[END_ADDR]], align 8
92 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint ptr [[BEGIN]] to i64
93 // CHECK: [[END_INT:%.+]] = ptrtoint ptr [[END]] to i64
94 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]]
95 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1
96 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1
97 // CHECK: [[BE_SUB_ST_SUB_1_SUB_1_DIV:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1
98 // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[BE_SUB_ST_SUB_1_SUB_1_DIV]]
100 // Allocate size is (NELEMS + 1) * sizeof(%struct.kmp_depend_info).
101 // sizeof(%struct.kmp_depend_info) == 24;
102 // CHECK: [[EXTRA_SZ:%.+]] = add nuw i64 1, [[NELEMS]]
103 // CHECK: [[SIZE:%.+]] = mul nuw i64 [[EXTRA_SZ]], 24
106 // kmp_depend_info* dep = (kmp_depend_info*)kmpc_alloc(SIZE);
107 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 %{{.+}}, i64 [[SIZE]], ptr null)
109 // dep[0].base_addr = NELEMS.
110 // CHECK: [[BASE_ADDR_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
111 // CHECK: store i64 [[NELEMS]], ptr [[BASE_ADDR_ADDR]], align 8
113 // iterator_counter = 1;
114 // CHECK: store i64 1, ptr [[ITERATOR_COUNTER_ADDR:%.+]], align 8
116 // NITER = (argv[argc]-argv[0]-(-1)-1) / -(-1);
117 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
118 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR]], align 4
119 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
120 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
121 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
122 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
123 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 0
124 // CHECK: [[END:%.+]] = load ptr, ptr [[END_ADDR]], align 8
125 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint ptr [[BEGIN]] to i64
126 // CHECK: [[END_INT:%.+]] = ptrtoint ptr [[END]] to i64
127 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]]
128 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1
129 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1
130 // CHECK: [[NITER:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1
133 // CHECK: store i64 0, ptr [[COUNTER_ADDR:%.+]], align 8
134 // CHECK: br label %[[CONT:.+]]
137 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
138 // CHECK: [[CMP:%.+]] = icmp slt i64 [[COUNTER]], [[NITER]]
139 // CHECK: br i1 [[CMP]], label %[[BODY:.+]], label %[[EXIT:.+]]
143 // p = BEGIN + COUNTER * STEP;
144 // CHECK: [[ARGV:%.+]] = load ptr, ptr [[ARGV_ADDR]], align 8
145 // CHECK: [[ARGC:%.+]] = load i32, ptr [[ARGC_ADDR]], align 4
146 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64
147 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds ptr, ptr [[ARGV]], i64 [[IDX]]
148 // CHECK: [[BEGIN:%.+]] = load ptr, ptr [[BEGIN_ADDR]], align 8
149 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
150 // CHECK: [[CS_MUL:%.+]] = mul nsw i64 [[COUNTER]], -1
151 // CHECK: [[CS_MUL_BEGIN_ADD:%.+]] = getelementptr inbounds i8, ptr [[BEGIN]], i64 [[CS_MUL]]
152 // CHECK: store ptr [[CS_MUL_BEGIN_ADD]], ptr [[P_ADDR:%.+]], align 8
155 // CHECK: [[P:%.+]] = load ptr, ptr [[P_ADDR]], align 8
156 // CHECK: [[P0:%.+]] = getelementptr inbounds i8, ptr [[P]], i64 0
157 // CHECK: [[P0_ADDR:%.+]] = ptrtoint ptr [[P0]] to i64
159 // dep[ITERATOR_COUNTER].base_addr = &p[0];
160 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, ptr [[ITERATOR_COUNTER_ADDR]], align 8
161 // CHECK: [[DEP_IC:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i64 [[ITERATOR_COUNTER]]
162 // CHECK: [[DEP_IC_BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 0
163 // CHECK: store i64 [[P0_ADDR]], ptr [[DEP_IC_BASE_ADDR]], align 8
165 // dep[ITERATOR_COUNTER].size = sizeof(p[0]);
166 // CHECK: [[DEP_IC_SIZE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 1
167 // CHECK: store i64 1, ptr [[DEP_IC_SIZE]], align 8
168 // dep[ITERATOR_COUNTER].flags = in_out;
169 // CHECK: [[DEP_IC_FLAGS:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_IC]], i{{.+}} 0, i{{.+}} 2
170 // CHECK: store i8 3, ptr [[DEP_IC_FLAGS]], align 8
172 // ITERATOR_COUNTER = ITERATOR_COUNTER + 1;
173 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, ptr [[ITERATOR_COUNTER_ADDR]], align 8
174 // CHECK: [[INC:%.+]] = add nuw i64 [[ITERATOR_COUNTER]], 1
175 // CHECK: store i64 [[INC]], ptr [[ITERATOR_COUNTER_ADDR]], align 8
177 // COUNTER = COUNTER + 1;
178 // CHECK: [[COUNTER:%.+]] = load i64, ptr [[COUNTER_ADDR]], align 8
179 // CHECK: [[INC:%.+]] = add nsw i64 [[COUNTER]], 1
180 // CHECK: store i64 [[INC]], ptr [[COUNTER_ADDR]], align 8
181 // CHECK: br label %[[CONT]]
186 // CHECK: [[DEP_BEGIN:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i64 1
187 // CHECK: store ptr [[DEP_BEGIN]], ptr [[MAIN_A]], align 8
189 // CHECK-LABEL: tmain
190 // CHECK: [[ARGC_ADDR:%.+]] = alloca ptr,
191 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
192 // CHECK: [[DEP_ADDR_VOID:%.+]] = call ptr @__kmpc_alloc(i32 [[GTID]], i64 72, ptr null)
193 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 0, i{{.+}} 0
194 // CHECK: store i64 2, ptr [[SZ_BASE]], align 8
195 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
196 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
197 // CHECK: store i64 %{{.+}}, ptr [[ADDR]], align 8
198 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
199 // CHECK: store i64 8, ptr [[SZ_ADDR]], align 8
200 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
201 // CHECK: store i8 1, ptr [[FLAGS_ADDR]], align 8
202 // CHECK: [[SHAPE_ADDR:%.+]] = load ptr, ptr [[ARGV_ADDR:%.+]], align 8
203 // CHECK: [[SZ1:%.+]] = mul nuw i64 12, %{{.+}}
204 // CHECK: [[SZ:%.+]] = mul nuw i64 [[SZ1]], 4
205 // CHECK: [[SHAPE:%.+]] = ptrtoint ptr [[SHAPE_ADDR]] to i64
206 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 2
207 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0
208 // CHECK: store i64 [[SHAPE]], ptr [[ADDR]], align 8
209 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1
210 // CHECK: store i64 [[SZ]], ptr [[SZ_ADDR]], align 8
211 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2
212 // CHECK: store i8 1, ptr [[FLAGS_ADDR]], align 8
213 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[DEP_ADDR_VOID]], i{{.+}} 1
214 // CHECK: store ptr [[BASE_ADDR]], ptr [[TMAIN_A]], align 8
215 // CHECK: [[ARGC:%.+]] = load ptr, ptr [[ARGC_ADDR]], align 8
216 // CHECK: [[ARGC_REF:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC]], i{{.+}} -1
217 // CHECK: call void @__kmpc_free(i32 [[GTID]], ptr [[ARGC_REF]], ptr null)
218 // CHECK: [[ARGC_BASE:%.+]] = load ptr, ptr [[ARGC_ADDR]], align 8
219 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC_BASE]], i64 -1
220 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0
221 // CHECK: [[NUMDEPS:%.+]] = load i64, ptr [[NUMDEPS_ADDR]], align 8
222 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, ptr [[ARGC_BASE]], i64 [[NUMDEPS]]
223 // CHECK: br label %[[BODY:.+]]
225 // CHECK: [[EL:%.+]] = phi ptr [ [[ARGC_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ]
226 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 0, i{{.+}} 2
227 // CHECK: store i8 3, ptr [[FLAG_BASE]], align 8
228 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, ptr [[EL]], i{{.+}} 1
229 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[EL_NEXT]], [[END]]
230 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]]