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 4 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 10 11 #ifndef HEADER 12 #define HEADER 13 14 // CHECK-DAG: [[MAIN_A:@.+]] = internal global i8* null, 15 // CHECK-DAG: [[TMAIN_A:@.+]] = linkonce_odr global i8* null, 16 17 typedef void *omp_depend_t; 18 19 void foo() {} 20 21 template <class T> 22 T tmain(T argc) { 23 static T a; 24 int *argv; 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) 28 return argc; 29 } 30 31 int main(int argc, char **argv) { 32 static omp_depend_t a; 33 omp_depend_t b; 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); 39 return 0; 40 } 41 42 // CHECK-LABEL: @main 43 // CHECK: [[B_ADDR:%.+]] = alloca i8*, 44 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num( 45 // CHECK: [[DEP_ADDR_VOID:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 72, i8* null) 46 // CHECK: [[DEP_ADDR:%.+]] = bitcast i8* [[DEP_ADDR_VOID]] to %struct.kmp_depend_info* 47 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 0, i{{.+}} 0 48 // CHECK: store i64 2, i64* [[SZ_BASE]], 49 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 1 50 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0 51 // CHECK: store i64 %{{.+}}, i64* [[ADDR]], 52 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1 53 // CHECK: store i64 4, i64* [[SZ_ADDR]], 54 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2 55 // CHECK: store i8 3, i8* [[FLAGS_ADDR]], 56 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 2 57 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0 58 // CHECK: store i64 %{{.+}}, i64* [[ADDR]], 59 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1 60 // CHECK: store i64 8, i64* [[SZ_ADDR]], 61 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2 62 // CHECK: store i8 3, i8* [[FLAGS_ADDR]], 63 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 1 64 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[BASE_ADDR]] to i8* 65 // CHECK: store i8* [[DEP]], i8** [[MAIN_A]], 66 // CHECK: [[B:%.+]] = load i8*, i8** [[B_ADDR]], 67 // CHECK: [[B_BASE:%.+]] = bitcast i8* [[B]] to %struct.kmp_depend_info* 68 // CHECK: [[B_REF:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[B_BASE]], i{{.+}} -1 69 // CHECK: [[B:%.+]] = bitcast %struct.kmp_depend_info* [[B_REF]] to i8* 70 // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[B]], i8* null) 71 // CHECK: [[B:%.+]] = load i8*, i8** [[B_ADDR]], 72 // CHECK: [[B_BASE:%.+]] = bitcast i8* [[B]] to %struct.kmp_depend_info* 73 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[B_BASE]], i64 -1 74 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0 75 // CHECK: [[NUMDEPS:%.+]] = load i64, i64* [[NUMDEPS_ADDR]], 76 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[B_BASE]], i64 [[NUMDEPS]] 77 // CHECK: br label %[[BODY:.+]] 78 // CHECK: [[BODY]]: 79 // CHECK: [[EL:%.+]] = phi %struct.kmp_depend_info* [ [[B_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ] 80 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[EL]], i{{.+}} 0, i{{.+}} 2 81 // CHECK: store i8 4, i8* [[FLAG_BASE]], 82 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[EL]], i{{.+}} 1 83 // CHECK: [[IS_DONE:%.+]] = icmp eq %struct.kmp_depend_info* [[EL_NEXT]], [[END]] 84 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]] 85 // CHECK: [[DONE]]: 86 87 // Claculate toal number of elements. 88 // (argv[argc]-argv[0]-(-1)-1) / -(-1); 89 // CHECK: [[ARGV:%.+]] = load i8**, i8*** [[ARGV_ADDR:%.+]], 90 // CHECK: [[ARGC:%.+]] = load i32, i32* [[ARGC_ADDR:%.+]], 91 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64 92 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds i8*, i8** [[ARGV]], i64 [[IDX]] 93 // CHECK: [[BEGIN:%.+]] = load i8*, i8** [[BEGIN_ADDR]], 94 // CHECK: [[ARGV:%.+]] = load i8**, i8*** [[ARGV_ADDR]], 95 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds i8*, i8** [[ARGV]], i64 0 96 // CHECK: [[END:%.+]] = load i8*, i8** [[END_ADDR]], 97 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint i8* [[BEGIN]] to i64 98 // CHECK: [[END_INT:%.+]] = ptrtoint i8* [[END]] to i64 99 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]] 100 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1 101 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1 102 // CHECK: [[BE_SUB_ST_SUB_1_SUB_1_DIV:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1 103 // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[BE_SUB_ST_SUB_1_SUB_1_DIV]] 104 105 // Allocate size is (NELEMS + 1) * sizeof(%struct.kmp_depend_info). 106 // sizeof(%struct.kmp_depend_info) == 24; 107 // CHECK: [[EXTRA_SZ:%.+]] = add nuw i64 1, [[NELEMS]] 108 // CHECK: [[SIZE:%.+]] = mul nuw i64 [[EXTRA_SZ]], 24 109 110 // Allocate memory 111 // kmp_depend_info* dep = (kmp_depend_info*)kmpc_alloc(SIZE); 112 // CHECK: [[DEP_ADDR_VOID:%.+]] = call i8* @__kmpc_alloc(i32 %{{.+}}, i64 [[SIZE]], i8* null) 113 // CHECK: [[DEP_ADDR:%.+]] = bitcast i8* [[DEP_ADDR_VOID]] to %struct.kmp_depend_info* 114 115 // dep[0].base_addr = NELEMS. 116 // CHECK: [[BASE_ADDR_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 0, i{{.+}} 0 117 // CHECK: store i64 [[NELEMS]], i64* [[BASE_ADDR_ADDR]], 118 119 // iterator_counter = 1; 120 // CHECK: store i64 1, i64* [[ITERATOR_COUNTER_ADDR:%.+]], 121 122 // NITER = (argv[argc]-argv[0]-(-1)-1) / -(-1); 123 // CHECK: [[ARGV:%.+]] = load i8**, i8*** [[ARGV_ADDR]], 124 // CHECK: [[ARGC:%.+]] = load i32, i32* [[ARGC_ADDR]], 125 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64 126 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds i8*, i8** [[ARGV]], i64 [[IDX]] 127 // CHECK: [[BEGIN:%.+]] = load i8*, i8** [[BEGIN_ADDR]], 128 // CHECK: [[ARGV:%.+]] = load i8**, i8*** [[ARGV_ADDR]], 129 // CHECK: [[END_ADDR:%.+]] = getelementptr inbounds i8*, i8** [[ARGV]], i64 0 130 // CHECK: [[END:%.+]] = load i8*, i8** [[END_ADDR]], 131 // CHECK: [[BEGIN_INT:%.+]] = ptrtoint i8* [[BEGIN]] to i64 132 // CHECK: [[END_INT:%.+]] = ptrtoint i8* [[END]] to i64 133 // CHECK: [[BE_SUB:%.+]] = sub i64 [[BEGIN_INT]], [[END_INT]] 134 // CHECK: [[BE_SUB_ST_SUB:%.+]] = add nsw i64 [[BE_SUB]], 1 135 // CHECK: [[BE_SUB_ST_SUB_1_SUB:%.+]] = sub nsw i64 [[BE_SUB_ST_SUB]], 1 136 // CHECK: [[NITER:%.+]] = sdiv i64 [[BE_SUB_ST_SUB_1_SUB]], 1 137 138 // Loop. 139 // CHECK: store i64 0, i64* [[COUNTER_ADDR:%.+]], 140 // CHECK: br label %[[CONT:.+]] 141 142 // CHECK: [[CONT]]: 143 // CHECK: [[COUNTER:%.+]] = load i64, i64* [[COUNTER_ADDR]], 144 // CHECK: [[CMP:%.+]] = icmp slt i64 [[COUNTER]], [[NITER]] 145 // CHECK: br i1 [[CMP]], label %[[BODY:.+]], label %[[EXIT:.+]] 146 147 // CHECK: [[BODY]]: 148 149 // p = BEGIN + COUNTER * STEP; 150 // CHECK: [[ARGV:%.+]] = load i8**, i8*** [[ARGV_ADDR]], 151 // CHECK: [[ARGC:%.+]] = load i32, i32* [[ARGC_ADDR]], 152 // CHECK: [[IDX:%.+]] = sext i32 [[ARGC]] to i64 153 // CHECK: [[BEGIN_ADDR:%.+]] = getelementptr inbounds i8*, i8** [[ARGV]], i64 [[IDX]] 154 // CHECK: [[BEGIN:%.+]] = load i8*, i8** [[BEGIN_ADDR]], 155 // CHECK: [[COUNTER:%.+]] = load i64, i64* [[COUNTER_ADDR]], 156 // CHECK: [[CS_MUL:%.+]] = mul nsw i64 [[COUNTER]], -1 157 // CHECK: [[CS_MUL_BEGIN_ADD:%.+]] = getelementptr inbounds i8, i8* [[BEGIN]], i64 [[CS_MUL]] 158 // CHECK: store i8* [[CS_MUL_BEGIN_ADD]], i8** [[P_ADDR:%.+]], 159 160 // &p[0] 161 // CHECK: [[P:%.+]] = load i8*, i8** [[P_ADDR]], 162 // CHECK: [[P0:%.+]] = getelementptr inbounds i8, i8* [[P]], i64 0 163 164 // dep[ITERATOR_COUNTER].base_addr = &p[0]; 165 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, i64* [[ITERATOR_COUNTER_ADDR]], 166 // CHECK: [[DEP_IC:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i64 [[ITERATOR_COUNTER]] 167 // CHECK: [[DEP_IC_BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_IC]], i{{.+}} 0, i{{.+}} 0 168 // CHECK: [[P0_ADDR:%.+]] = ptrtoint i8* [[P0]] to i64 169 // CHECK: store i64 [[P0_ADDR]], i64* [[DEP_IC_BASE_ADDR]], 170 171 // dep[ITERATOR_COUNTER].size = sizeof(p[0]); 172 // CHECK: [[DEP_IC_SIZE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_IC]], i{{.+}} 0, i{{.+}} 1 173 // CHECK: store i64 1, i64* [[DEP_IC_SIZE]], 174 // dep[ITERATOR_COUNTER].flags = in_out; 175 // CHECK: [[DEP_IC_FLAGS:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_IC]], i{{.+}} 0, i{{.+}} 2 176 // CHECK: store i8 3, i8* [[DEP_IC_FLAGS]], 177 178 // ITERATOR_COUNTER = ITERATOR_COUNTER + 1; 179 // CHECK: [[ITERATOR_COUNTER:%.+]] = load i64, i64* [[ITERATOR_COUNTER_ADDR]], 180 // CHECK: [[INC:%.+]] = add nuw i64 [[ITERATOR_COUNTER]], 1 181 // CHECK: store i64 [[INC]], i64* [[ITERATOR_COUNTER_ADDR]], 182 183 // COUNTER = COUNTER + 1; 184 // CHECK: [[COUNTER:%.+]] = load i64, i64* [[COUNTER_ADDR]], 185 // CHECK: [[INC:%.+]] = add nsw i64 [[COUNTER]], 1 186 // CHECK: store i64 [[INC]], i64* [[COUNTER_ADDR]], 187 // CHECK: br label %[[CONT]] 188 189 // CHECK: [[EXIT]]: 190 191 // a = &dep[1]; 192 // CHECK: [[DEP_BEGIN:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i64 1 193 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[DEP_BEGIN]] to i8* 194 // CHECK: store i8* [[DEP]], i8** [[MAIN_A]], 195 196 // CHECK-LABEL: tmain 197 // CHECK: [[ARGC_ADDR:%.+]] = alloca i8*, 198 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num( 199 // CHECK: [[DEP_ADDR_VOID:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 72, i8* null) 200 // CHECK: [[DEP_ADDR:%.+]] = bitcast i8* [[DEP_ADDR_VOID]] to %struct.kmp_depend_info* 201 // CHECK: [[SZ_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 0, i{{.+}} 0 202 // CHECK: store i64 2, i64* [[SZ_BASE]], 203 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 1 204 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0 205 // CHECK: store i64 %{{.+}}, i64* [[ADDR]], 206 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1 207 // CHECK: store i64 8, i64* [[SZ_ADDR]], 208 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2 209 // CHECK: store i8 1, i8* [[FLAGS_ADDR]], 210 // CHECK: [[SHAPE_ADDR:%.+]] = load i32*, i32** [[ARGV_ADDR:%.+]], 211 // CHECK: [[SZ1:%.+]] = mul nuw i64 12, %{{.+}} 212 // CHECK: [[SZ:%.+]] = mul nuw i64 [[SZ1]], 4 213 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 2 214 // CHECK: [[ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 0 215 // CHECK: [[SHAPE:%.+]] = ptrtoint i32* [[SHAPE_ADDR]] to i64 216 // CHECK: store i64 [[SHAPE]], i64* [[ADDR]], 217 // CHECK: [[SZ_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 1 218 // CHECK: store i64 [[SZ]], i64* [[SZ_ADDR]], 219 // CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[BASE_ADDR]], i{{.+}} 0, i{{.+}} 2 220 // CHECK: store i8 1, i8* [[FLAGS_ADDR]], 221 // CHECK: [[BASE_ADDR:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[DEP_ADDR]], i{{.+}} 1 222 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[BASE_ADDR]] to i8* 223 // CHECK: store i8* [[DEP]], i8** [[TMAIN_A]], 224 // CHECK: [[ARGC:%.+]] = load i8*, i8** [[ARGC_ADDR]], 225 // CHECK: [[ARGC_BASE:%.+]] = bitcast i8* [[ARGC]] to %struct.kmp_depend_info* 226 // CHECK: [[ARGC_REF:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[ARGC_BASE]], i{{.+}} -1 227 // CHECK: [[ARGC:%.+]] = bitcast %struct.kmp_depend_info* [[ARGC_REF]] to i8* 228 // CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[ARGC]], i8* null) 229 // CHECK: [[ARGC:%.+]] = load i8*, i8** [[ARGC_ADDR]], 230 // CHECK: [[ARGC_BASE:%.+]] = bitcast i8* [[ARGC]] to %struct.kmp_depend_info* 231 // CHECK: [[NUMDEPS_BASE:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[ARGC_BASE]], i64 -1 232 // CHECK: [[NUMDEPS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[NUMDEPS_BASE]], i{{.+}} 0, i{{.+}} 0 233 // CHECK: [[NUMDEPS:%.+]] = load i64, i64* [[NUMDEPS_ADDR]], 234 // CHECK: [[END:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[ARGC_BASE]], i64 [[NUMDEPS]] 235 // CHECK: br label %[[BODY:.+]] 236 // CHECK: [[BODY]]: 237 // CHECK: [[EL:%.+]] = phi %struct.kmp_depend_info* [ [[ARGC_BASE]], %{{.+}} ], [ [[EL_NEXT:%.+]], %[[BODY]] ] 238 // CHECK: [[FLAG_BASE:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[EL]], i{{.+}} 0, i{{.+}} 2 239 // CHECK: store i8 3, i8* [[FLAG_BASE]], 240 // CHECK: [[EL_NEXT]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[EL]], i{{.+}} 1 241 // CHECK: [[IS_DONE:%.+]] = icmp eq %struct.kmp_depend_info* [[EL_NEXT]], [[END]] 242 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[BODY]] 243 // CHECK: [[DONE]]: 244 245 #endif 246