1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=50 -x c -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4
5 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fopenmp-version=50 -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
12
13 typedef void *omp_depend_t;
14 typedef __UINTPTR_TYPE__ omp_event_handle_t;
15
16 void foo();
17
18 // CHECK-LABEL: @main
main()19 int main() {
20 omp_depend_t d, x;
21 omp_event_handle_t evt;
22 int a, *b;
23 // CHECK: [[D_ADDR:%.+]] = alloca i8*,
24 // CHECK: [[X_ADDR:%.+]] = alloca i8*,
25 // CHECK: [[EVT_ADDR:%.+]] = alloca i64,
26 // CHECK: [[A_ADDR:%.+]] = alloca i32,
27 // CHECK: [[DEPOBJ_SIZE_ADDR:%.+]] = alloca i64,
28 // CHECK: [[DEPOBJ_SIZE_ADDR1:%.+]] = alloca i64,
29 // CHECK: = alloca i64,
30 // CHECK: [[DEP_COUNTER_ADDR:%.+]] = alloca i64,
31 // CHECK-DAG: store i64 0, i64* [[DEPOBJ_SIZE_ADDR1]],
32 // CHECK-DAG: store i64 0, i64* [[DEPOBJ_SIZE_ADDR]],
33 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
34 // CHECK: [[ALLOC:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 [[GTID]], i32 65, i64 48, i64 0, i32 (i32, i8*)* bitcast (i32 (i32, [[PRIVATES_TY:%.+]]*)* [[TASK_ENTRY:@.+]] to i32 (i32, i8*)*))
35 // CHECK: [[EVT_VAL:%.+]] = call i8* @__kmpc_task_allow_completion_event(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[ALLOC]])
36 // CHECK: [[CAST_EVT_VAL:%.+]] = ptrtoint i8* [[EVT_VAL]] to i64
37 // CHECK: store i64 [[CAST_EVT_VAL]], i64* [[EVT_ADDR]],
38 // CHECK: [[DATA:%.+]] = bitcast i8* [[ALLOC]] to [[PRIVATES_TY]]*
39 // CHECK: [[D:%.+]] = load i8*, i8** [[D_ADDR]],
40 // CHECK: [[D_DEP:%.+]] = bitcast i8* [[D]] to %struct.kmp_depend_info*
41 // CHECK: [[D_DEP_BASE:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[D_DEP]], i{{.+}} -1
42 // CHECK: [[D_DEP_BASE_SIZE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[D_DEP_BASE]], i{{.+}} 0, i{{.+}} 0
43 // CHECK: [[SIZE1:%.+]] = load i64, i64* [[D_DEP_BASE_SIZE]],
44 // CHECK: [[SZ:%.+]] = load i64, i64* [[DEPOBJ_SIZE_ADDR]],
45 // CHECK: [[SIZE:%.+]] = add nuw i64 [[SZ]], [[SIZE1]]
46 // CHECK: store i64 [[SIZE]], i64* [[DEPOBJ_SIZE_ADDR]],
47 // CHECK: [[X:%.+]] = load i8*, i8** [[X_ADDR]],
48 // CHECK: [[X_DEP:%.+]] = bitcast i8* [[X]] to %struct.kmp_depend_info*
49 // CHECK: [[X_DEP_BASE:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[X_DEP]], i{{.+}} -1
50 // CHECK: [[X_DEP_BASE_SIZE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[X_DEP_BASE]], i{{.+}} 0, i{{.+}} 0
51 // CHECK: [[SIZE2:%.+]] = load i64, i64* [[X_DEP_BASE_SIZE]],
52 // CHECK: [[SZ:%.+]] = load i64, i64* [[DEPOBJ_SIZE_ADDR1]],
53 // CHECK: [[SIZE3:%.+]] = add nuw i64 [[SZ]], [[SIZE2]]
54 // CHECK: store i64 [[SIZE3]], i64* [[DEPOBJ_SIZE_ADDR1]],
55 // CHECK: [[SZ:%.+]] = load i64, i64* [[DEPOBJ_SIZE_ADDR]],
56 // CHECK: [[SZ1:%.+]] = load i64, i64* [[DEPOBJ_SIZE_ADDR1]],
57 // CHECK: [[SIZE1:%.+]] = add nuw i64 0, [[SZ]]
58 // CHECK: [[SIZE2:%.+]] = add nuw i64 [[SIZE1]], [[SZ1]]
59 // CHECK: [[SIZE:%.+]] = add nuw i64 [[SIZE2]], 2
60 // CHECK: [[SV:%.+]] = call i8* @llvm.stacksave()
61 // CHECK: store i8* [[SV]], i8** [[SV_ADDR:%.+]],
62 // CHECK: [[VLA:%.+]] = alloca %struct.kmp_depend_info, i64 [[SIZE]],
63 // CHECK: [[SIZE32:%.+]] = trunc i64 [[SIZE]] to i32
64 // CHECK: [[VLA0:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA]], i64 0
65 // CHECK: [[BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA0]], i{{.+}} 0, i{{.+}} 0
66 // CHECK: [[A_ADDR_CAST:%.+]] = ptrtoint i32* [[A_ADDR]] to i64
67 // CHECK: store i64 [[A_ADDR_CAST]], i64* [[BASE_ADDR]],
68 // CHECK: [[SIZE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA0]], i{{.+}} 0, i{{.+}} 1
69 // CHECK: store i64 4, i64* [[SIZE_ADDR]],
70 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA0]], i{{.+}} 0, i{{.+}} 2
71 // CHECK: store i8 1, i8* [[FLAGS_ADDR]],
72 // CHECK: [[A:%.+]] = load i32, i32* [[A_ADDR]],
73 // CHECK: [[A_CAST:%.+]] = sext i32 [[A]] to i64
74 // CHECK: [[SZ1:%.+]] = mul nuw i64 24, [[A_CAST]]
75 // CHECK: [[A:%.+]] = load i32, i32* [[A_ADDR]],
76 // CHECK: [[A_CAST:%.+]] = sext i32 [[A]] to i64
77 // CHECK: [[SZ:%.+]] = mul nuw i64 [[SZ1]], [[A_CAST]]
78 // CHECK: [[VLA1:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA]], i64 1
79 // CHECK: [[BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA1]], i{{.+}} 0, i{{.+}} 0
80 // CHECK: [[B_ADDR_CAST:%.+]] = ptrtoint i32** %{{.+}} to i64
81 // CHECK: store i64 [[B_ADDR_CAST]], i64* [[BASE_ADDR]],
82 // CHECK: [[SIZE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA1]], i{{.+}} 0, i{{.+}} 1
83 // CHECK: store i64 [[SZ]], i64* [[SIZE_ADDR]],
84 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA1]], i{{.+}} 0, i{{.+}} 2
85 // CHECK: store i8 1, i8* [[FLAGS_ADDR]],
86 // CHECK: store i64 2, i64* [[DEP_COUNTER_ADDR]],
87 // CHECK: [[D:%.+]] = load i8*, i8** [[D_ADDR]],
88 // CHECK: [[BC:%.+]] = bitcast i8* [[D]] to %struct.kmp_depend_info*
89 // CHECK: [[PREV:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[BC]], i64 -1
90 // CHECK: [[SIZE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[PREV]], i{{.+}} 0, i{{.+}} 0
91 // CHECK: [[SIZE:%.+]] = load i64, i64* [[SIZE_ADDR]],
92 // CHECK: [[BYTES:%.+]] = mul nuw i64 24, [[SIZE]]
93 // CHECK: [[POS:%.+]] = load i64, i64* [[DEP_COUNTER_ADDR]],
94 // CHECK: [[VLA_D:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA]], i64 [[POS]]
95 // CHECK: [[DEST:%.+]] = bitcast %struct.kmp_depend_info* [[VLA_D]] to i8*
96 // CHECK: [[SRC:%.+]] = bitcast %struct.kmp_depend_info* [[BC]] to i8*
97 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align {{.+}} [[DEST]], i8* align {{.+}} [[SRC]], i64 [[BYTES]], i1 false)
98 // CHECK: [[ADD:%.+]] = add nuw i64 [[POS]], [[SIZE]]
99 // CHECK: store i64 [[ADD]], i64* [[DEP_COUNTER_ADDR]],
100 // CHECK: [[X:%.+]] = load i8*, i8** [[X_ADDR]],
101 // CHECK: [[BC:%.+]] = bitcast i8* [[X]] to %struct.kmp_depend_info*
102 // CHECK: [[PREV:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[BC]], i64 -1
103 // CHECK: [[SIZE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[PREV]], i{{.+}} 0, i{{.+}} 0
104 // CHECK: [[SIZE:%.+]] = load i64, i64* [[SIZE_ADDR]],
105 // CHECK: [[BYTES:%.+]] = mul nuw i64 24, [[SIZE]]
106 // CHECK: [[POS:%.+]] = load i64, i64* [[DEP_COUNTER_ADDR]],
107 // CHECK: [[VLA_X:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA]], i64 [[POS]]
108 // CHECK: [[DEST:%.+]] = bitcast %struct.kmp_depend_info* [[VLA_X]] to i8*
109 // CHECK: [[SRC:%.+]] = bitcast %struct.kmp_depend_info* [[BC]] to i8*
110 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align {{.+}} [[DEST]], i8* align {{.+}} [[SRC]], i64 [[BYTES]], i1 false)
111 // CHECK: [[ADD:%.+]] = add nuw i64 [[POS]], [[SIZE]]
112 // CHECK: store i64 [[ADD]], i64* [[DEP_COUNTER_ADDR]],
113 // CHECK: [[BC:%.+]] = bitcast %struct.kmp_depend_info* [[VLA]] to i8*
114 // CHECK: call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[ALLOC]], i32 [[SIZE32]], i8* [[BC]], i32 0, i8* null)
115 // CHECK: [[SV:%.+]] = load i8*, i8** [[SV_ADDR]],
116 // CHECK: call void @llvm.stackrestore(i8* [[SV]])
117 #pragma omp task depend(in: a, ([3][a][a])&b) depend(depobj: d, x) detach(evt)
118 {
119 #pragma omp taskgroup
120 {
121 #pragma omp task
122 foo();
123 }
124 }
125 // CHECK: ret i32 0
126 return 0;
127 }
128 // CHECK: call void @__kmpc_taskgroup(
129 // CHECK: call i8* @__kmpc_omp_task_alloc(
130 // CHECK: call i32 @__kmpc_omp_task(
131 // CHECK: call void @__kmpc_end_taskgroup(
132
133 // CHECK-LINE: @bar
bar()134 void bar() {
135 int **a;
136 // CHECK: call void @__kmpc_for_static_init_4(
137 #pragma omp for
138 for (int i = 0; i < 10; ++i)
139 // CHECK: [[BUF:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 %{{.+}}, i32 1, i64 48,
140 // CHECK: [[BC_BUF:%.+]] = bitcast i8* [[BUF]] to [[TT_WITH_PRIVS:%.+]]*
141 // CHECK: [[PRIVS:%.+]] = getelementptr inbounds [[TT_WITH_PRIVS]], [[TT_WITH_PRIVS]]* [[BC_BUF]], i32 0, i32 1
142 // CHECK: [[I_PRIV:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}} [[PRIVS]], i32 0, i32 0
143 // CHECK: [[I:%.+]] = load i32, i32* [[I_ADDR:%.+]],
144 // CHECK: store i32 %{{.+}}, i32* [[I_PRIV]],
145
146 // NELEMS = 1 * ((i - 0 + 2 - 1) / 2);
147 // CHECK: [[END:%.+]] = load i32, i32* [[I_ADDR]],
148 // CHECK: [[EB_SUB:%.+]] = sub i32 [[END]], 0
149 // CHECK: [[EB_SUB_2_ADD:%.+]] = add i32 [[EB_SUB]], 2
150 // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
151 // CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 [[EB_SUB_2_ADD_1_SUB]], 2
152 // CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64
153 // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[ELEMS]]
154
155 // TOTAL_NUMBER_OF_ELEMENTS = NELEMS + 0;
156 // CHECK: [[TOTAL:%.+]] = add nuw i64 [[NELEMS]], 0
157
158 // %struct.kmp_depend_info DEPS[TOTAL];
159 // CHECK: [[DEPS:%.+]] = alloca %struct.kmp_depend_info, i64 [[TOTAL]],
160 // CHECK: [[NDEPS:%.+]] = trunc i64 [[TOTAL]] to i32
161
162 // i64 DEP_COUNTER = 0;
163 // CHECK: store i64 0, i64* [[DEP_COUNTER_ADDR:%.+]],
164
165 // NELEMS = ((i - 0 + 2 - 1) / 2);
166 // CHECK: [[END:%.+]] = load i32, i32* [[I_ADDR]],
167 // CHECK: [[EB_SUB:%.+]] = sub i32 [[END]], 0
168 // CHECK: [[EB_SUB_2_ADD:%.+]] = add i32 [[EB_SUB]], 2
169 // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
170 // CHECK: [[ELEMS:%.+]] = udiv i32 [[EB_SUB_2_ADD_1_SUB]], 2
171
172 // i32 COUNTER = 0;
173 // CHECK: store i32 0, i32* [[COUNTER_ADDR:%.+]],
174 // CHECK: br label %[[CONT:.+]]
175
176 // Loop.
177 // CHECK: [[CONT]]:
178 // CHECK: [[COUNTER:%.+]] = load i32, i32* [[COUNTER_ADDR]],
179 // CHECK: [[CMP:%.+]] = icmp ult i32 [[COUNTER]], [[ELEMS]]
180 // CHECK: br i1 [[CMP]], label %[[BODY:.+]], label %[[EXIT:.+]]
181
182 // CHECK: [[BODY]]:
183
184 // k = 0 + 2*COUNTER;
185 // CHECK: [[COUNTER:%.+]] = load i32, i32* [[COUNTER_ADDR]],
186 // CHECK: [[C2_MUL:%.+]] = mul i32 [[COUNTER]], 2
187 // CHECK: [[C2_MUL_0_ADD:%.+]] = add i32 0, [[C2_MUL]]
188 // CHECK: store i32 [[C2_MUL_0_ADD]], i32* [[K_ADDR:%.+]],
189
190 // &a[k][i]
191 // CHECK: [[A:%.+]] = load i32**, i32*** [[A_ADDR:%.+]],
192 // CHECK: [[K:%.+]] = load i32, i32* [[K_ADDR]],
193 // CHECK: [[IDX:%.+]] = zext i32 [[K]] to i64
194 // CHECK: [[AK_ADDR:%.+]] = getelementptr inbounds i32*, i32** [[A]], i64 [[IDX]]
195 // CHECK: [[AK:%.+]] = load i32*, i32** [[AK_ADDR]],
196 // CHECK: [[I:%.+]] = load i32, i32* [[I_ADDR]],
197 // CHECK: [[IDX:%.+]] = sext i32 [[I]] to i64
198 // CHECK: [[AKI_ADDR:%.+]] = getelementptr inbounds i32, i32* [[AK]], i64 [[IDX]]
199
200 // DEPS[DEP_COUNTER].base_addr = &a[k][i];
201 // CHECK: [[DEP_COUNTER:%.+]] = load i64, i64* [[DEP_COUNTER_ADDR]],
202 // CHECK: [[DEPS_DC:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEPS]], i64 [[DEP_COUNTER]]
203 // CHECK: [[DEPS_DC_BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEPS_DC]], i{{.+}} 0, i{{.+}} 0
204 // CHECK: [[AKI_INT:%.+]] = ptrtoint i32* [[AKI_ADDR]] to i64
205 // CHECK: store i64 [[AKI_INT]], i64* [[DEPS_DC_BASE_ADDR]],
206
207 // DEPS[DEP_COUNTER].size = sizeof(a[k][i]);
208 // CHECK: [[DEPS_DC_SIZE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEPS_DC]], i{{.+}} 0, i{{.+}} 1
209 // CHECK: store i64 4, i64* [[DEPS_DC_SIZE]],
210
211 // DEPS[DEP_COUNTER].flags = in;
212 // CHECK: [[DEPS_DC_FLAGS:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEPS_DC]], i{{.+}} 0, i{{.+}} 2
213 // CHECK: store i8 1, i8* [[DEPS_DC_FLAGS]],
214
215 // DEP_COUNTER = DEP_COUNTER + 1;
216 // CHECK: [[DEP_COUNTER:%.+]] = load i64, i64* [[DEP_COUNTER_ADDR]],
217 // CHECK: [[INC:%.+]] = add nuw i64 [[DEP_COUNTER]], 1
218 // CHECK: store i64 [[INC]], i64* [[DEP_COUNTER_ADDR]],
219
220 // COUNTER = COUNTER + 1;
221 // CHECK: [[COUNTER:%.+]] = load i32, i32* [[COUNTER_ADDR]],
222 // CHECK: [[INC:%.+]] = add i32 [[COUNTER]], 1
223 // CHECK: store i32 [[INC]], i32* [[COUNTER_ADDR]],
224 // CHECK: br label %[[CONT]]
225
226 // CHECK: [[EXIT]]:
227 // CHECK: [[DEP_BEGIN:%.+]] = bitcast %struct.kmp_depend_info* [[DEPS]] to i8*
228 // CHECK: = call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* @{{.+}}, i32 %{{.+}}, i8* [[BUF]], i32 [[NDEPS]], i8* [[DEP_BEGIN]], i32 0, i8* null)
229 #pragma omp task depend(iterator(unsigned k=0:i:2), in: a[k][i])
230 ++i;
231 }
232 #endif
233