1 // RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -std=c++98 | FileCheck %s 2 3 // RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -std=c++98 | FileCheck --check-prefix SIMD-ONLY0 %s 4 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}} 5 // expected-no-diagnostics 6 7 // CHECK: [[RED_SIZE1:@reduction_size[.].+]] = common thread_local global i64 0 8 // CHECK: [[RED1:@reduction[.].+]] = common thread_local global i8* null 9 // CHECK: [[RED_SIZE2:@reduction_size[.].+]] = common thread_local global i64 0 10 11 struct S { 12 float a; 13 S() : a(0.0f) {} 14 ~S() {} 15 }; 16 17 #pragma omp declare reduction(+:S:omp_out.a += omp_in.a) initializer(omp_priv = omp_orig) 18 19 float g; 20 21 int a; 22 #pragma omp threadprivate(a) 23 int main (int argc, char *argv[]) 24 { 25 int i, n; 26 float a[100], b[100], sum, e[argc + 100]; 27 S c[100]; 28 float &d = g; 29 30 /* Some initializations */ 31 n = 100; 32 for (i=0; i < n; i++) 33 a[i] = b[i] = i * 1.0; 34 sum = 0.0; 35 36 #pragma omp taskloop reduction(+:sum, c[:n], d, e) 37 for (i=0; i < n; i++) { 38 sum = sum + (a[i] * b[i]); 39 c[i].a = i*i; 40 d += i*i; 41 e[i] = i; 42 } 43 44 } 45 46 // CHECK-LABEL: @main( 47 // CHECK: [[RETVAL:%.*]] = alloca i32, 48 // CHECK: [[ARGC_ADDR:%.*]] = alloca i32, 49 // CHECK: [[ARGV_ADDR:%.*]] = alloca i8**, 50 // CHECK: [[I:%.*]] = alloca i32, 51 // CHECK: [[N:%.*]] = alloca i32, 52 // CHECK: [[A:%.*]] = alloca [100 x float], 53 // CHECK: [[B:%.*]] = alloca [100 x float], 54 // CHECK: [[SUM:%.*]] = alloca float, 55 // CHECK: [[SAVED_STACK:%.*]] = alloca i8*, 56 // CHECK: [[C:%.*]] = alloca [100 x %struct.S], 57 // CHECK: [[D:%.*]] = alloca float*, 58 // CHECK: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], 59 // CHECK: [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_task_red_input_t], 60 // CHECK: alloca i32, 61 // CHECK: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32, 62 // CHECK: [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32, 63 // CHECK: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* 64 // CHECK: store i32 0, i32* [[RETVAL]], 65 // CHECK: store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]], 66 // CHECK: store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]], 67 // CHECK: [[TMP1:%.*]] = load i32, i32* [[ARGC_ADDR]], 68 // CHECK: [[ADD:%.*]] = add nsw i32 [[TMP1]], 100 69 // CHECK: [[TMP2:%.*]] = zext i32 [[ADD]] to i64 70 // CHECK: [[VLA:%.+]] = alloca float, i64 % 71 72 // CHECK: call void @__kmpc_taskgroup(%struct.ident_t* 73 // CHECK-DAG: [[TMP21:%.*]] = bitcast float* [[SUM]] to i8* 74 // CHECK-DAG: store i8* [[TMP21]], i8** [[TMP20:%[^,]+]], 75 // CHECK-DAG: [[TMP20]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T:%.+]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_:%.+]], i32 0, i32 0 76 // CHECK-DAG: [[TMP22:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 1 77 // CHECK-DAG: store i64 4, i64* [[TMP22]], 78 // CHECK-DAG: [[TMP23:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 2 79 // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT1:.+]] to i8*), i8** [[TMP23]], 80 // CHECK-DAG: [[TMP24:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 3 81 // CHECK-DAG: store i8* null, i8** [[TMP24]], 82 // CHECK-DAG: [[TMP25:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 4 83 // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB1:.+]] to i8*), i8** [[TMP25]], 84 // CHECK-DAG: [[TMP26:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 5 85 // CHECK-DAG: [[TMP27:%.*]] = bitcast i32* [[TMP26]] to i8* 86 // CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP27]], i8 0, i64 4, i1 false) 87 // CHECK-DAG: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 0 88 // CHECK-DAG: [[LB_ADD_LEN:%.*]] = add nsw i64 -1, % 89 // CHECK-DAG: [[ARRAYIDX6:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 [[LB_ADD_LEN]] 90 // CHECK-DAG: [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8* 91 // CHECK-DAG: store i8* [[TMP31]], i8** [[TMP28:%[^,]+]], 92 // CHECK-DAG: [[TMP28]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4:%.+]], i32 0, i32 0 93 // CHECK-DAG: [[TMP32:%.*]] = ptrtoint %struct.S* [[ARRAYIDX6]] to i64 94 // CHECK-DAG: [[TMP33:%.*]] = ptrtoint %struct.S* [[ARRAYIDX5]] to i64 95 // CHECK-DAG: [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]] 96 // CHECK-DAG: [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64) 97 // CHECK-DAG: [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1 98 // CHECK-DAG: [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64) 99 // CHECK-DAG: store i64 [[TMP37]], i64* [[TMP38:%[^,]+]], 100 // CHECK-DAG: [[TMP38]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 1 101 // CHECK-DAG: [[TMP39:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 2 102 // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT2:.+]] to i8*), i8** [[TMP39]], 103 // CHECK-DAG: [[TMP40:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 3 104 // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_FINI2:.+]] to i8*), i8** [[TMP40]], 105 // CHECK-DAG: [[TMP41:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 4 106 // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB2:.+]] to i8*), i8** [[TMP41]], 107 // CHECK-DAG: [[TMP42:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 5 108 // CHECK-DAG: store i32 1, i32* [[TMP42]], 109 // CHECK-DAG: [[TMP44:%.*]] = load float*, float** [[D]], 110 // CHECK-DAG: [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8* 111 // CHECK-DAG: store i8* [[TMP45]], i8** [[TMP43:%[^,]+]], 112 // CHECK-DAG: [[TMP43]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7:%.+]], i32 0, i32 0 113 // CHECK-DAG: [[TMP46:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 1 114 // CHECK-DAG: store i64 4, i64* [[TMP46]], 115 // CHECK-DAG: [[TMP47:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 2 116 // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT3:.+]] to i8*), i8** [[TMP47]], 117 // CHECK-DAG: [[TMP48:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 3 118 // CHECK-DAG: store i8* null, i8** [[TMP48]], 119 // CHECK-DAG: [[TMP49:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 4 120 // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB3:.+]] to i8*), i8** [[TMP49]], 121 // CHECK-DAG: [[TMP50:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 5 122 // CHECK-DAG: [[TMP51:%.*]] = bitcast i32* [[TMP50]] to i8* 123 // CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP51]], i8 0, i64 4, i1 false) 124 // CHECK-DAG: [[TMP53:%.*]] = bitcast float* [[VLA]] to i8* 125 // CHECK-DAG: store i8* [[TMP53]], i8** [[TMP52:%[^,]+]], 126 // CHECK-DAG: [[TMP52]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8:%.+]], i32 0, i32 0 127 // CHECK-DAG: [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4 128 // CHECK-DAG: [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64) 129 // CHECK-DAG: store i64 [[TMP54]], i64* [[TMP56:%[^,]+]], 130 // CHECK-DAG: [[TMP56]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 1 131 // CHECK-DAG: [[TMP57:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 2 132 // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT4:.+]] to i8*), i8** [[TMP57]], 133 // CHECK-DAG: [[TMP58:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 3 134 // CHECK-DAG: store i8* null, i8** [[TMP58]], 135 // CHECK-DAG: [[TMP59:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 4 136 // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB4:.+]] to i8*), i8** [[TMP59]], 137 // CHECK-DAG: [[TMP60:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 5 138 // CHECK-DAG: store i32 1, i32* [[TMP60]], 139 // CHECK-DAG: [[DOTRD_INPUT_GEP_]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64 140 // CHECK-DAG: [[DOTRD_INPUT_GEP_4]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64 141 // CHECK-DAG: [[DOTRD_INPUT_GEP_7]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64 142 // CHECK-DAG: [[DOTRD_INPUT_GEP_8]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64 143 // CHECK: [[TMP61:%.*]] = bitcast [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]] to i8* 144 // CHECK: [[TMP62:%.*]] = call i8* @__kmpc_task_reduction_init(i32 [[TMP0]], i32 4, i8* [[TMP61]]) 145 // CHECK: [[TMP63:%.*]] = load i32, i32* [[N]], 146 // CHECK: store i32 [[TMP63]], i32* [[DOTCAPTURE_EXPR_]], 147 // CHECK: [[TMP64:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_]], 148 // CHECK: [[SUB:%.*]] = sub nsw i32 [[TMP64]], 0 149 // CHECK: [[SUB10:%.*]] = sub nsw i32 [[SUB]], 1 150 // CHECK: [[ADD11:%.*]] = add nsw i32 [[SUB10]], 1 151 // CHECK: [[DIV:%.*]] = sdiv i32 [[ADD11]], 1 152 // CHECK: [[SUB12:%.*]] = sub nsw i32 [[DIV]], 1 153 // CHECK: store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]], 154 // CHECK: [[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* %{{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 40, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* @[[TASK:.+]] to i32 (i32, i8*)*)) 155 // CHECK: call void @__kmpc_taskloop(%struct.ident_t* %{{.+}}, i32 [[TMP0]], i8* [[TMP65]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* null) 156 // CHECK: call void @__kmpc_end_taskgroup(%struct.ident_t* 157 158 // CHECK: ret i32 159 160 // CHECK: define internal void @[[RED_INIT1]](i8* %0) 161 // CHECK: store float 0.000000e+00, float* % 162 // CHECK: ret void 163 164 // CHECK: define internal void @[[RED_COMB1]](i8* %0, i8* %1) 165 // CHECK: fadd float % 166 // CHECK: store float %{{.+}}, float* % 167 // CHECK: ret void 168 169 // CHECK: define internal void @[[RED_INIT2]](i8* %0) 170 // CHECK: load i8*, i8** [[RED1]], 171 // CHECK: call void [[OMP_INIT1:@.+]]( 172 // CHECK: ret void 173 174 // CHECK: define internal void [[OMP_COMB1:@.+]](%struct.S* noalias %0, %struct.S* noalias %1) 175 // CHECK: fadd float % 176 177 // CHECK: define internal void [[OMP_INIT1]](%struct.S* noalias %0, %struct.S* noalias %1) 178 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64( 179 180 // CHECK: define internal void @[[RED_FINI2]](i8* %0) 181 // CHECK: load i64, i64* [[RED_SIZE1]] 182 // CHECK: call void @ 183 // CHECK: ret void 184 185 // CHECK: define internal void @[[RED_COMB2]](i8* %0, i8* %1) 186 // CHECK: load i64, i64* [[RED_SIZE1]] 187 // CHECK: call void [[OMP_COMB1]]( 188 // CHECK: ret void 189 190 // CHECK: define internal void @[[RED_INIT3]](i8* %0) 191 // CHECK: store float 0.000000e+00, float* % 192 // CHECK: ret void 193 194 // CHECK: define internal void @[[RED_COMB3]](i8* %0, i8* %1) 195 // CHECK: fadd float % 196 // CHECK: store float %{{.+}}, float* % 197 // CHECK: ret void 198 199 // CHECK: define internal void @[[RED_INIT4]](i8* %0) 200 // CHECK: load i64, i64* [[RED_SIZE2]] 201 // CHECK: store float 0.000000e+00, float* % 202 // CHECK: ret void 203 204 // CHECK: define internal void @[[RED_COMB4]](i8* %0, i8* %1) 205 // CHECK: load i64, i64* [[RED_SIZE2]] 206 // CHECK: fadd float % 207 // CHECK: store float %{{.+}}, float* % 208 // CHECK: ret void 209 210 // CHECK: call i8* @__kmpc_task_reduction_get_th_data( 211 // CHECK: call i8* @__kmpc_task_reduction_get_th_data( 212 // CHECK: call i8* @__kmpc_task_reduction_get_th_data( 213 // CHECK: call i8* @__kmpc_task_reduction_get_th_data( 214 215 // CHECK-DAG: distinct !DISubprogram(linkageName: "[[TASK]]", scope: ! 216 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]" 217 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]" 218 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]" 219 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]" 220 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]" 221 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]" 222 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]" 223 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]" 224 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]" 225