Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_device_codegen.cpp
blobe2d3759aa9668206f04be2ec40fde06551c1963e
1 // Test host codegen.
2 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
4 // RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
6 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
8 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=99 -DOMP99 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,REV
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=99 -DOMP99 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=99 -DOMP99 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,REV
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=99 -DOMP99 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=SIMD-ONLY0
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=99 -DOMP99 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=99 -DOMP99 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=SIMD-ONLY0
18 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
20 // expected-no-diagnostics
21 #ifndef HEADER
22 #define HEADER
24 #ifdef OMP99
25 #pragma omp requires reverse_offload
26 #endif
28 void foo(int n) {
30 // CHECK: [[N:%.+]] = load i32, ptr [[N_ADDR:%.+]],
31 // CHECK: store i32 [[N]], ptr [[DEVICE_CAP:%.+]],
32 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
33 // CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
34 // CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 -1, i32 0, ptr @.[[TGT_REGION:.+]].region_id, ptr %[[KERNEL_ARGS:.+]])
35 // CHECK-NEXT: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
36 // CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
37 // CHECK: [[FAIL]]
38 // CHECK: call void [[HVT0:@.+]]()
39 // CHECK-NEXT: br label %[[END]]
40 // CHECK: [[END]]
41 #pragma omp target device(n)
43 // CHECK: [[N:%.+]] = load i32, ptr [[N_ADDR]],
44 // CHECK: store i32 [[N]], ptr [[DEVICE_CAP:%.+]],
45 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
46 // CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
47 // CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 -1, i32 0, ptr @.[[TGT_REGION:.+]].region_id, ptr %[[KERNEL_ARGS:.+]])
48 // CHECK-NEXT: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
49 // CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
50 // CHECK: [[FAIL]]
51 // CHECK: call void [[HVT0:@.+]]()
52 // CHECK-NEXT: br label %[[END]]
53 // CHECK: [[END]]
54 #pragma omp target device(device_num \
55 : n)
58 #ifdef OMP99
59 // REV-NOT: call i32 @__tgt_target_kernel(ptr @{{.+}},
60 // REV: call void @__omp_offloading_{{.+}}_l62()
61 // REV-NOT: call i32 @__tgt_target_kernel(ptr @{{.+}},
62 #pragma omp target device(ancestor \
63 : n)
65 #endif
68 #endif