229 lines · cpp
1// Test host codegen.2// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-643// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s4// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-645// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-326// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s7// RUN: %clang_cc1 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-328 9// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s10// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s11// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s12// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s13// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s14// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s15// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}16 17// Test target codegen - host bc file has to be created first.18// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc19// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-6420// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s21// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-6422// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc23// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-3224// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s25// RUN: %clang_cc1 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-3226 27// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc28// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s29// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s30// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s31// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc32// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s33// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s34// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s35// SIMD-ONLY1-NOT: {{__kmpc|__tgt}}36 37// expected-no-diagnostics38#ifndef HEADER39#define HEADER40 41// CHECK-DAG: [[TT:%.+]] = type { i64, i8 }42// CHECK-DAG: [[ENTTY:%.+]] = type { i64, i16, i16, i32, ptr, ptr, i64, i64, ptr }43 44// TCHECK: [[ENTTY:%.+]] = type { i64, i16, i16, i32, ptr, ptr, i64, i64, ptr }45 46// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 4]47// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]48// CHECK-DAG: @{{.*}} = weak constant i8 049 50// TCHECK: @{{.+}} = weak constant [[ENTTY]]51// TCHECK: @{{.+}} = {{.*}}constant [[ENTTY]]52// TCHECK-NOT: @{{.+}} = weak constant [[ENTTY]]53 54template<typename tx, typename ty>55struct TT{56 tx X;57 ty Y;58};59 60int global;61extern int global;62 63// CHECK: define {{.*}}[[FOO:@.+]](64int foo(int n) {65 int a = 0;66 short aa = 0;67 float b[10];68 float bn[n];69 double c[5][10];70 double cn[5][n];71 TT<long long, char> d;72 static long *plocal;73 74 // CHECK: [[ADD:%.+]] = add nsw i3275 // CHECK: store i32 [[ADD]], ptr [[DEVICE_CAP:%.+]],76 // CHECK: [[GEP:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 077 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],78 // CHECK: store i32 [[DEV]], ptr [[GEP]],79 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[ID:@.+]], i32 [[GTID:%.+]], i32 1, i[[SZ:32|64]] {{20|40}}, i[[SZ]] 4, ptr [[TASK_ENTRY0:@.+]])80 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 081 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 182 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 283 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 384 // CHECK: call void @__kmpc_omp_taskwait_deps_51(ptr [[ID]], i32 [[GTID]], i32 4, ptr %{{.+}}, i32 0, ptr null, i32 0)85 // CHECK: call void @__kmpc_omp_task_begin_if0(ptr [[ID]], i32 [[GTID]], ptr [[TASK]])86 // CHECK: call i32 [[TASK_ENTRY0]](i32 [[GTID]], ptr [[TASK]])87 // CHECK: call void @__kmpc_omp_task_complete_if0(ptr [[ID]], i32 [[GTID]], ptr [[TASK]])88 #pragma omp target teams distribute device(global + a) depend(in: global) depend(out: a, b, cn[4])89 for (int i = 0; i < 10; ++i) {90 }91 92 // CHECK: [[ADD:%.+]] = add nsw i3293 // CHECK: store i32 [[ADD]], ptr [[DEVICE_CAP:%.+]],94 95 // CHECK: [[BOOL:%.+]] = icmp ne i32 %{{.+}}, 096 // CHECK: br i1 [[BOOL]], label %[[THEN:.+]], label %[[ELSE:.+]]97 // CHECK: [[THEN]]:98 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x ptr], ptr [[BP:%.+]], i32 0, i32 099 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x ptr], ptr [[P:%.+]], i32 0, i32 0100 // CHECK-DAG: store ptr [[BP0:%[^,]+]], ptr [[BPADDR0]]101 // CHECK-DAG: store ptr [[BP0]], ptr [[PADDR0]]102 103 // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x ptr], ptr [[BP]], i32 0, i32 1104 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x ptr], ptr [[P]], i32 0, i32 1105 // CHECK-DAG: store i[[SZ]] [[BP1:%[^,]+]], ptr [[BPADDR1]]106 // CHECK-DAG: store i[[SZ]] [[BP1]], ptr [[PADDR1]]107 // CHECK-DAG: getelementptr inbounds [2 x ptr], ptr [[BP]], i32 0, i32 0108 // CHECK-DAG: getelementptr inbounds [2 x ptr], ptr [[P]], i32 0, i32 0109 // CHECK: [[GEP:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2110 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],111 // CHECK: store i32 [[DEV]], ptr [[GEP]],112 // CHECK: [[DEV1:%.+]] = load i32, ptr [[DEVICE_CAP]],113 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64114 115 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_target_task_alloc(ptr [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{104|60}}, i[[SZ]] {{16|12}}, ptr [[TASK_ENTRY1_:@.+]], i64 [[DEV2]])116 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0117 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 1118 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 2119 // CHECK: call i32 @__kmpc_omp_task_with_deps(ptr [[ID]], i32 [[GTID]], ptr [[TASK]], i32 3, ptr %{{.+}}, i32 0, ptr null)120 // CHECK: br label %[[EXIT:.+]]121 122 // CHECK: [[ELSE]]:123 // CHECK-NOT: getelementptr inbounds [2 x ptr], ptr124 // CHECK: [[GEP:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2125 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],126 // CHECK: store i32 [[DEV]], ptr [[GEP]],127 // CHECK: [[DEV1:%.+]] = load i32, ptr [[DEVICE_CAP]],128 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64129 130 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_target_task_alloc(ptr [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, ptr [[TASK_ENTRY1__:@.+]], i64 [[DEV2]])131 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0132 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 1133 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 2134 // CHECK: call i32 @__kmpc_omp_task_with_deps(ptr [[ID]], i32 [[GTID]], ptr [[TASK]], i32 3, ptr %{{.+}}, i32 0, ptr null)135 // CHECK: br label %[[EXIT:.+]]136 // CHECK: [[EXIT]]:137 138 #pragma omp target teams distribute device(global + a) nowait depend(inout: global, a, bn) if(a)139 for (int i = 0; i < *plocal; ++i) {140 static int local1;141 *plocal = global;142 local1 = global;143 }144 145 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[ID]], i32 [[GTID]], i32 1, i[[SZ]] {{48|24}}, i[[SZ]] 4, ptr [[TASK_ENTRY2:@.+]])146 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0147 // CHECK: call void @__kmpc_omp_taskwait_deps_51(ptr [[ID]], i32 [[GTID]], i32 1, ptr %{{.+}}, i32 0, ptr null, i32 0)148 // CHECK: call void @__kmpc_omp_task_begin_if0(ptr [[ID]], i32 [[GTID]], ptr [[TASK]])149 // CHECK: call i32 [[TASK_ENTRY2]](i32 [[GTID]], ptr [[TASK]])150 // CHECK: call void @__kmpc_omp_task_complete_if0(ptr [[ID]], i32 [[GTID]], ptr [[TASK]])151 #pragma omp target teams distribute if(0) firstprivate(global) depend(out:global)152 for (int i = 0; i < global; ++i) {153 global += 1;154 }155 156 return a;157}158 159// Check that the offloading functions are emitted and that the arguments are160// correct and loaded correctly for the target regions in foo().161 162// CHECK: define internal void [[HVT0:@.+]]()163 164// CHECK: define internal{{.*}} i32 [[TASK_ENTRY0]](i32{{.*}}, ptr noalias noundef %1)165// CHECK: store ptr null, ptr %166// CHECK: [[DEVICE_CAP:%.+]] = load ptr,167// CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],168// CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64169// CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 0, i32 0, ptr @.{{.+}}.region_id, ptr %{{.+}})170// CHECK-NEXT: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0171// CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]172// CHECK: [[FAIL]]173// CHECK: call void [[HVT0]]()174// CHECK-NEXT: br label %[[END]]175// CHECK: [[END]]176// CHECK: ret i32 0177 178// CHECK: define internal void [[HVT1:@.+]](ptr noundef %{{.+}}, i[[SZ]] noundef %{{.+}})179 180// CHECK: define internal{{.*}} i32 [[TASK_ENTRY1_]](i32{{.*}}, ptr noalias noundef %1)181// CHECK: call void {{%.*}}(182// CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2183// CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],184// CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64185// CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 0, i32 0, ptr @.{{.+}}.region_id, ptr %{{.+}})186 187// CHECK: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0188// CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]189// CHECK: [[FAIL]]190// CHECK: [[BP0:%.+]] = load ptr, ptr %191// CHECK: [[BP1_I32:%.+]] = load i32, ptr @192// CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],193// CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],194// CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],195// CHECK: call void [[HVT1]](ptr [[BP0]], i[[SZ]] [[BP1]])196// CHECK-NEXT: br label %[[END]]197// CHECK: [[END]]198// CHECK: ret i32 0199 200// CHECK: define internal{{.*}} i32 [[TASK_ENTRY1__]](i32{{.*}}, ptr noalias noundef %1)201// CHECK: call void {{%.*}}(202// CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2203// CHECK: [[BP0:%.+]] = load ptr, ptr %204// CHECK: [[BP1_I32:%.+]] = load i32, ptr @205// CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],206// CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],207// CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],208// CHECK: call void [[HVT1]](ptr [[BP0]], i[[SZ]] [[BP1]])209// CHECK: ret i32 0210 211// CHECK: define internal void [[HVT2:@.+]](i[[SZ]] noundef %{{.+}})212// Create stack storage and store argument in there.213// CHECK: [[AA_ADDR:%.+]] = alloca i[[SZ]], align214// CHECK: store i[[SZ]] %{{.+}}, ptr [[AA_ADDR]], align215// CHECK-64: load i32, ptr [[AA_ADDR]], align216// CHECK-32: load i32, ptr [[AA_ADDR]], align217 218// CHECK: define internal{{.*}} i32 [[TASK_ENTRY2]](i32{{.*}}, ptr noalias noundef %1)219// CHECK: call void {{%.*}}(220// CHECK: [[BP1_I32:%.+]] = load i32, ptr %221// CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],222// CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],223// CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],224// CHECK: call void [[HVT2]](i[[SZ]] [[BP1]])225// CHECK: ret i32 0226 227 228#endif229