1532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix HOST --check-prefix CHECK
2532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
3532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix DEVICE --check-prefix CHECK
4532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -emit-pch -o %t
5532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -o - | FileCheck %s --check-prefix DEVICE --check-prefix CHECK
692327c50SAlexey Bataev
7532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix SIMD-ONLY
8532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
9532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o -| FileCheck %s --check-prefix SIMD-ONLY
10532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -emit-pch -o %t
11532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify -o - | FileCheck %s --check-prefix SIMD-ONLY
1292327c50SAlexey Bataev
1392327c50SAlexey Bataev // expected-no-diagnostics
1492327c50SAlexey Bataev
1592327c50SAlexey Bataev // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
1692327c50SAlexey Bataev
1792327c50SAlexey Bataev #ifndef HEADER
1892327c50SAlexey Bataev #define HEADER
1992327c50SAlexey Bataev
20d01b7497SAlexey Bataev // HOST-DAG: @c = external global i32,
21625f59d1SGheorghe-Teodor Bercea // HOST-DAG: @c_decl_tgt_ref_ptr = weak global i32* @c
22625f59d1SGheorghe-Teodor Bercea // HOST-DAG: @[[D:.+]] = internal global i32 2
23625f59d1SGheorghe-Teodor Bercea // HOST-DAG: @[[D_PTR:.+]] = weak global i32* @[[D]]
2492327c50SAlexey Bataev // DEVICE-NOT: @c =
25625f59d1SGheorghe-Teodor Bercea // DEVICE: @c_decl_tgt_ref_ptr = weak global i32* null
26625f59d1SGheorghe-Teodor Bercea // HOST: [[SIZES:@.+]] = private unnamed_addr constant [3 x i64] [i64 4, i64 4, i64 4]
27625f59d1SGheorghe-Teodor Bercea // HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [3 x i64] [i64 35, i64 531, i64 531]
280034e84aSGheorghe-Teodor Bercea // HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00"
294b343fd8SSergey Dmitriev // HOST: @.omp_offloading.entry.c_decl_tgt_ref_ptr = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 8, i32 1, i32 0 }, section "omp_offloading_entries", align 1
30625f59d1SGheorghe-Teodor Bercea // DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_{{.*}}_decl_tgt_ref_ptr\00"
31625f59d1SGheorghe-Teodor Bercea // HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"_{{.*}}d_{{.*}}_decl_tgt_ref_ptr\00"
32625f59d1SGheorghe-Teodor Bercea // HOST: @.omp_offloading.entry.[[D_PTR]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @[[D_PTR]] to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name{{.*}}, i32 0, i32 0
3392327c50SAlexey Bataev
3492327c50SAlexey Bataev extern int c;
3592327c50SAlexey Bataev #pragma omp declare target link(c)
3692327c50SAlexey Bataev
37625f59d1SGheorghe-Teodor Bercea static int d = 2;
38625f59d1SGheorghe-Teodor Bercea #pragma omp declare target link(d)
39625f59d1SGheorghe-Teodor Bercea
maini1()4092327c50SAlexey Bataev int maini1() {
4192327c50SAlexey Bataev int a;
4292327c50SAlexey Bataev #pragma omp target map(tofrom : a)
4392327c50SAlexey Bataev {
4492327c50SAlexey Bataev a = c;
45625f59d1SGheorghe-Teodor Bercea d++;
4692327c50SAlexey Bataev }
47a495c640SAlexey Bataev #pragma omp target
48a495c640SAlexey Bataev #pragma omp teams
49a495c640SAlexey Bataev c = a;
5092327c50SAlexey Bataev return 0;
5192327c50SAlexey Bataev }
5292327c50SAlexey Bataev
53b9f67d44SJoseph Huber // DEVICE: define weak_odr void @__omp_offloading_{{.*}}_{{.*}}maini1{{.*}}_l42(i32* noundef nonnull align {{[0-9]+}} dereferenceable{{[^,]*}}
540034e84aSGheorghe-Teodor Bercea // DEVICE: [[C_REF:%.+]] = load i32*, i32** @c_decl_tgt_ref_ptr,
5592327c50SAlexey Bataev // DEVICE: [[C:%.+]] = load i32, i32* [[C_REF]],
5692327c50SAlexey Bataev // DEVICE: store i32 [[C]], i32* %
5792327c50SAlexey Bataev
5892327c50SAlexey Bataev // HOST: define {{.*}}i32 @{{.*}}maini1{{.*}}()
59625f59d1SGheorghe-Teodor Bercea // HOST: [[BASEPTRS:%.+]] = alloca [3 x i8*],
60625f59d1SGheorghe-Teodor Bercea // HOST: [[PTRS:%.+]] = alloca [3 x i8*],
61625f59d1SGheorghe-Teodor Bercea // HOST: getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASEPTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
62625f59d1SGheorghe-Teodor Bercea // HOST: getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
63625f59d1SGheorghe-Teodor Bercea
64625f59d1SGheorghe-Teodor Bercea // HOST: [[BP1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASEPTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
6592327c50SAlexey Bataev // HOST: [[BP1_CAST:%.+]] = bitcast i8** [[BP1]] to i32***
660034e84aSGheorghe-Teodor Bercea // HOST: store i32** @c_decl_tgt_ref_ptr, i32*** [[BP1_CAST]],
67625f59d1SGheorghe-Teodor Bercea // HOST: [[P1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
6892327c50SAlexey Bataev // HOST: [[P1_CAST:%.+]] = bitcast i8** [[P1]] to i32**
6992327c50SAlexey Bataev // HOST: store i32* @c, i32** [[P1_CAST]],
7092327c50SAlexey Bataev
71625f59d1SGheorghe-Teodor Bercea // HOST: [[BP2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASEPTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
72625f59d1SGheorghe-Teodor Bercea // HOST: [[BP2_CAST:%.+]] = bitcast i8** [[BP2]] to i32***
73625f59d1SGheorghe-Teodor Bercea // HOST: store i32** @[[D_PTR]], i32*** [[BP2_CAST]],
74625f59d1SGheorghe-Teodor Bercea // HOST: [[P2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
75625f59d1SGheorghe-Teodor Bercea // HOST: [[P2_CAST:%.+]] = bitcast i8** [[P2]] to i32**
76625f59d1SGheorghe-Teodor Bercea // HOST: store i32* @[[D]], i32** [[P2_CAST]],
77625f59d1SGheorghe-Teodor Bercea
78625f59d1SGheorghe-Teodor Bercea // HOST: [[BP0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASEPTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
79625f59d1SGheorghe-Teodor Bercea // HOST: [[P0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
80*1fff1166SJoseph Huber // HOST: call i32 @__tgt_target_kernel(%struct.ident_t* @{{.+}}, i64 -1, i32 -1, i32 0, i8* @.{{.+}}.region_id, %struct.__tgt_kernel_arguments* %{{.+}})
81625f59d1SGheorghe-Teodor Bercea // HOST: call void @__omp_offloading_{{.*}}_{{.*}}_{{.*}}maini1{{.*}}_l42(i32* %{{[^,]+}})
82*1fff1166SJoseph Huber // HOST: call i32 @__tgt_target_kernel(%struct.ident_t* @{{.+}}, i64 -1, i32 0, i32 0, i8* @.{{.+}}.region_id, %struct.__tgt_kernel_arguments* %{{.+}})
83625f59d1SGheorghe-Teodor Bercea
841b1c8d83Shyeongyu kim // HOST: define internal void @__omp_offloading_{{.*}}_{{.*}}maini1{{.*}}_l42(i32* noundef nonnull align {{[0-9]+}} dereferenceable{{.*}})
8592327c50SAlexey Bataev // HOST: [[C:%.*]] = load i32, i32* @c,
8692327c50SAlexey Bataev // HOST: store i32 [[C]], i32* %
8792327c50SAlexey Bataev
880034e84aSGheorghe-Teodor Bercea // CHECK: !{i32 1, !"c_decl_tgt_ref_ptr", i32 1, i32 {{[0-9]+}}}
8992327c50SAlexey Bataev #endif // HEADER
90