blob: 0acb1199152791c90924d826a71deefdc4f162bf [file] [log] [blame]
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +00001// Test device global memory data sharing codegen.
2///==========================================================================///
3
4// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
5// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CK1
6
7// expected-no-diagnostics
8
9#ifndef HEADER
10#define HEADER
11
12void test_ds(){
13 #pragma omp target
14 {
15 int a = 10;
16 #pragma omp parallel
17 {
18 a = 1000;
19 }
20 int b = 100;
Alexey Bataev63cc8e92018-03-20 14:45:59 +000021 int c = 1000;
22 #pragma omp parallel private(c)
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +000023 {
Alexey Bataev63cc8e92018-03-20 14:45:59 +000024 int *c1 = &c;
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +000025 b = a + 10000;
26 }
27 }
28}
29
Gheorghe-Teodor Bercea36cdfad2018-03-22 17:33:27 +000030/// ========= In the worker function ========= ///
31// CK1: {{.*}}define internal void @__omp_offloading{{.*}}test_ds{{.*}}_worker()
32// CK1: call void @llvm.nvvm.barrier0()
Gheorghe-Teodor Berceaad4e5792018-07-13 16:18:24 +000033// CK1-NOT: call void @__kmpc_data_sharing_init_stack
Gheorghe-Teodor Bercea36cdfad2018-03-22 17:33:27 +000034
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +000035/// ========= In the kernel function ========= ///
36
Alexey Bataev9a700172018-05-08 14:16:57 +000037// CK1: {{.*}}define weak void @__omp_offloading{{.*}}test_ds{{.*}}()
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +000038// CK1: [[SHAREDARGS1:%.+]] = alloca i8**
39// CK1: [[SHAREDARGS2:%.+]] = alloca i8**
40// CK1: call void @__kmpc_kernel_init
41// CK1: call void @__kmpc_data_sharing_init_stack
42// CK1: [[GLOBALSTACK:%.+]] = call i8* @__kmpc_data_sharing_push_stack(i64 8, i16 0)
43// CK1: [[GLOBALSTACK2:%.+]] = bitcast i8* [[GLOBALSTACK]] to %struct._globalized_locals_ty*
44// CK1: [[A:%.+]] = getelementptr inbounds %struct._globalized_locals_ty, %struct._globalized_locals_ty* [[GLOBALSTACK2]], i32 0, i32 0
45// CK1: [[B:%.+]] = getelementptr inbounds %struct._globalized_locals_ty, %struct._globalized_locals_ty* [[GLOBALSTACK2]], i32 0, i32 1
46// CK1: store i32 10, i32* [[A]]
47// CK1: call void @__kmpc_kernel_prepare_parallel({{.*}}, i16 1)
48// CK1: call void @__kmpc_begin_sharing_variables(i8*** [[SHAREDARGS1]], i64 1)
49// CK1: [[SHARGSTMP1:%.+]] = load i8**, i8*** [[SHAREDARGS1]]
50// CK1: [[SHARGSTMP2:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP1]], i64 0
51// CK1: [[SHAREDVAR:%.+]] = bitcast i32* [[A]] to i8*
52// CK1: store i8* [[SHAREDVAR]], i8** [[SHARGSTMP2]]
53// CK1: call void @llvm.nvvm.barrier0()
54// CK1: call void @llvm.nvvm.barrier0()
55// CK1: call void @__kmpc_end_sharing_variables()
56// CK1: store i32 100, i32* [[B]]
57// CK1: call void @__kmpc_kernel_prepare_parallel({{.*}}, i16 1)
58// CK1: call void @__kmpc_begin_sharing_variables(i8*** [[SHAREDARGS2]], i64 2)
59// CK1: [[SHARGSTMP3:%.+]] = load i8**, i8*** [[SHAREDARGS2]]
60// CK1: [[SHARGSTMP4:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP3]], i64 0
61// CK1: [[SHAREDVAR1:%.+]] = bitcast i32* [[B]] to i8*
62// CK1: store i8* [[SHAREDVAR1]], i8** [[SHARGSTMP4]]
63// CK1: [[SHARGSTMP12:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP3]], i64 1
64// CK1: [[SHAREDVAR2:%.+]] = bitcast i32* [[A]] to i8*
65// CK1: store i8* [[SHAREDVAR2]], i8** [[SHARGSTMP12]]
66// CK1: call void @llvm.nvvm.barrier0()
67// CK1: call void @llvm.nvvm.barrier0()
68// CK1: call void @__kmpc_end_sharing_variables()
69// CK1: call void @__kmpc_data_sharing_pop_stack(i8* [[GLOBALSTACK]])
70// CK1: call void @__kmpc_kernel_deinit(i16 1)
71
72/// ========= In the data sharing wrapper function ========= ///
73
74// CK1: {{.*}}define internal void @__omp_outlined{{.*}}wrapper({{.*}})
75// CK1: [[SHAREDARGS4:%.+]] = alloca i8**
76// CK1: call void @__kmpc_get_shared_variables(i8*** [[SHAREDARGS4]])
77// CK1: [[SHARGSTMP13:%.+]] = load i8**, i8*** [[SHAREDARGS4]]
78// CK1: [[SHARGSTMP14:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP13]], i64 0
79// CK1: [[SHARGSTMP15:%.+]] = bitcast i8** [[SHARGSTMP14]] to i32**
80// CK1: [[SHARGSTMP16:%.+]] = load i32*, i32** [[SHARGSTMP15]]
81// CK1: call void @__omp_outlined__{{.*}}({{.*}}, i32* [[SHARGSTMP16]])
82
Alexey Bataev63cc8e92018-03-20 14:45:59 +000083/// outlined function for the second parallel region ///
84
85// CK1: define internal void @{{.+}}(i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* dereferenceable{{.+}}, i32* dereferenceable{{.+}})
Alexey Bataevb99dcb52018-07-09 17:43:58 +000086// CK1-NOT: call i8* @__kmpc_data_sharing_push_stack(
87// CK1: [[C_ADDR:%.+]] = alloca i32,
Alexey Bataev63cc8e92018-03-20 14:45:59 +000088// CK1: store i32* [[C_ADDR]], i32** %
Alexey Bataevb99dcb52018-07-09 17:43:58 +000089// CK1i-NOT: call void @__kmpc_data_sharing_pop_stack(
Alexey Bataev63cc8e92018-03-20 14:45:59 +000090
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +000091/// ========= In the data sharing wrapper function ========= ///
92
93// CK1: {{.*}}define internal void @__omp_outlined{{.*}}wrapper({{.*}})
94// CK1: [[SHAREDARGS3:%.+]] = alloca i8**
95// CK1: call void @__kmpc_get_shared_variables(i8*** [[SHAREDARGS3]])
96// CK1: [[SHARGSTMP5:%.+]] = load i8**, i8*** [[SHAREDARGS3]]
97// CK1: [[SHARGSTMP6:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP5]], i64 0
98// CK1: [[SHARGSTMP7:%.+]] = bitcast i8** [[SHARGSTMP6]] to i32**
99// CK1: [[SHARGSTMP8:%.+]] = load i32*, i32** [[SHARGSTMP7]]
100// CK1: [[SHARGSTMP9:%.+]] = getelementptr inbounds i8*, i8** [[SHARGSTMP5]], i64 1
101// CK1: [[SHARGSTMP10:%.+]] = bitcast i8** [[SHARGSTMP9]] to i32**
102// CK1: [[SHARGSTMP11:%.+]] = load i32*, i32** [[SHARGSTMP10]]
103// CK1: call void @__omp_outlined__{{.*}}({{.*}}, i32* [[SHARGSTMP8]], i32* [[SHARGSTMP11]])
104
105#endif
106