Skip to content

Commit 7fe8e0a

Browse files
[Flang][OpenMP] NFC: Create versions of declare-target tests with HLFIR
These tests work with HLFIR without any change. declare-target-implicit-tarop-cap.f90 fails and hence not included here.
1 parent 599eade commit 7fe8e0a

File tree

3 files changed

+400
-0
lines changed

3 files changed

+400
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s
3+
4+
module test_0
5+
implicit none
6+
7+
!CHECK-DAG: fir.global @_QMtest_0Edata_int {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : i32
8+
INTEGER :: data_int = 10
9+
!$omp declare target link(data_int)
10+
11+
!CHECK-DAG: fir.global @_QMtest_0Earray_1d({{.*}}) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.array<3xi32>
12+
INTEGER :: array_1d(3) = (/1,2,3/)
13+
!$omp declare target link(array_1d)
14+
15+
!CHECK-DAG: fir.global @_QMtest_0Earray_2d({{.*}}) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.array<2x2xi32>
16+
INTEGER :: array_2d(2,2) = reshape((/1,2,3,4/), (/2,2/))
17+
!$omp declare target link(array_2d)
18+
19+
!CHECK-DAG: fir.global @_QMtest_0Ept1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.box<!fir.ptr<i32>>
20+
INTEGER, POINTER :: pt1
21+
!$omp declare target link(pt1)
22+
23+
!CHECK-DAG: fir.global @_QMtest_0Ept2_tar {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} target : i32
24+
INTEGER, TARGET :: pt2_tar = 5
25+
!$omp declare target link(pt2_tar)
26+
27+
!CHECK-DAG: fir.global @_QMtest_0Ept2 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.box<!fir.ptr<i32>>
28+
INTEGER, POINTER :: pt2 => pt2_tar
29+
!$omp declare target link(pt2)
30+
31+
!CHECK-DAG: fir.global @_QMtest_0Edata_int_to {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : i32
32+
INTEGER :: data_int_to = 5
33+
!$omp declare target to(data_int_to)
34+
35+
!CHECK-DAG: fir.global @_QMtest_0Edata_int_clauseless {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : i32
36+
INTEGER :: data_int_clauseless = 1
37+
!$omp declare target(data_int_clauseless)
38+
39+
!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : f32
40+
!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_2 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : f32
41+
REAL :: data_extended_to_1 = 2
42+
REAL :: data_extended_to_2 = 3
43+
!$omp declare target to(data_extended_to_1, data_extended_to_2)
44+
45+
!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : f32
46+
!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_2 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : f32
47+
REAL :: data_extended_link_1 = 2
48+
REAL :: data_extended_link_2 = 3
49+
!$omp declare target link(data_extended_link_1, data_extended_link_2)
50+
51+
contains
52+
end module test_0
53+
54+
PROGRAM commons
55+
!CHECK-DAG: fir.global @numbers_ {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : tuple<f32, f32> {
56+
REAL :: one = 1
57+
REAL :: two = 2
58+
COMMON /numbers/ one, two
59+
!$omp declare target(/numbers/)
60+
61+
!CHECK-DAG: fir.global @numbers_link_ {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : tuple<f32, f32> {
62+
REAL :: one_link = 1
63+
REAL :: two_link = 2
64+
COMMON /numbers_link/ one_link, two_link
65+
!$omp declare target link(/numbers_link/)
66+
67+
!CHECK-DAG: fir.global @numbers_to_ {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : tuple<f32, f32> {
68+
REAL :: one_to = 1
69+
REAL :: two_to = 2
70+
COMMON /numbers_to/ one_to, two_to
71+
!$omp declare target to(/numbers_to/)
72+
END
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes ALL,HOST
2+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefixes ALL,DEVICE
3+
4+
! Check specification valid forms of declare target with functions
5+
! utilising device_type and to clauses as well as the default
6+
! zero clause declare target
7+
8+
! DEVICE-LABEL: func.func @_QPfunc_t_device()
9+
! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
10+
FUNCTION FUNC_T_DEVICE() RESULT(I)
11+
!$omp declare target to(FUNC_T_DEVICE) device_type(nohost)
12+
INTEGER :: I
13+
I = 1
14+
END FUNCTION FUNC_T_DEVICE
15+
16+
! HOST-LABEL: func.func @_QPfunc_t_host()
17+
! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}
18+
FUNCTION FUNC_T_HOST() RESULT(I)
19+
!$omp declare target to(FUNC_T_HOST) device_type(host)
20+
INTEGER :: I
21+
I = 1
22+
END FUNCTION FUNC_T_HOST
23+
24+
! ALL-LABEL: func.func @_QPfunc_t_any()
25+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
26+
FUNCTION FUNC_T_ANY() RESULT(I)
27+
!$omp declare target to(FUNC_T_ANY) device_type(any)
28+
INTEGER :: I
29+
I = 1
30+
END FUNCTION FUNC_T_ANY
31+
32+
! ALL-LABEL: func.func @_QPfunc_default_t_any()
33+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
34+
FUNCTION FUNC_DEFAULT_T_ANY() RESULT(I)
35+
!$omp declare target to(FUNC_DEFAULT_T_ANY)
36+
INTEGER :: I
37+
I = 1
38+
END FUNCTION FUNC_DEFAULT_T_ANY
39+
40+
! ALL-LABEL: func.func @_QPfunc_default_any()
41+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
42+
FUNCTION FUNC_DEFAULT_ANY() RESULT(I)
43+
!$omp declare target
44+
INTEGER :: I
45+
I = 1
46+
END FUNCTION FUNC_DEFAULT_ANY
47+
48+
! ALL-LABEL: func.func @_QPfunc_default_extendedlist()
49+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
50+
FUNCTION FUNC_DEFAULT_EXTENDEDLIST() RESULT(I)
51+
!$omp declare target(FUNC_DEFAULT_EXTENDEDLIST)
52+
INTEGER :: I
53+
I = 1
54+
END FUNCTION FUNC_DEFAULT_EXTENDEDLIST
55+
56+
!! -----
57+
58+
! Check specification valid forms of declare target with subroutines
59+
! utilising device_type and to clauses as well as the default
60+
! zero clause declare target
61+
62+
! DEVICE-LABEL: func.func @_QPsubr_t_device()
63+
! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
64+
SUBROUTINE SUBR_T_DEVICE()
65+
!$omp declare target to(SUBR_T_DEVICE) device_type(nohost)
66+
END
67+
68+
! HOST-LABEL: func.func @_QPsubr_t_host()
69+
! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}
70+
SUBROUTINE SUBR_T_HOST()
71+
!$omp declare target to(SUBR_T_HOST) device_type(host)
72+
END
73+
74+
! ALL-LABEL: func.func @_QPsubr_t_any()
75+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
76+
SUBROUTINE SUBR_T_ANY()
77+
!$omp declare target to(SUBR_T_ANY) device_type(any)
78+
END
79+
80+
! ALL-LABEL: func.func @_QPsubr_default_t_any()
81+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
82+
SUBROUTINE SUBR_DEFAULT_T_ANY()
83+
!$omp declare target to(SUBR_DEFAULT_T_ANY)
84+
END
85+
86+
! ALL-LABEL: func.func @_QPsubr_default_any()
87+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
88+
SUBROUTINE SUBR_DEFAULT_ANY()
89+
!$omp declare target
90+
END
91+
92+
! ALL-LABEL: func.func @_QPsubr_default_extendedlist()
93+
! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
94+
SUBROUTINE SUBR_DEFAULT_EXTENDEDLIST()
95+
!$omp declare target(SUBR_DEFAULT_EXTENDEDLIST)
96+
END
97+
98+
!! -----
99+
100+
! DEVICE-LABEL: func.func @_QPrecursive_declare_target
101+
! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
102+
RECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET(INCREMENT) RESULT(K)
103+
!$omp declare target to(RECURSIVE_DECLARE_TARGET) device_type(nohost)
104+
INTEGER :: INCREMENT, K
105+
IF (INCREMENT == 10) THEN
106+
K = INCREMENT
107+
ELSE
108+
K = RECURSIVE_DECLARE_TARGET(INCREMENT + 1)
109+
END IF
110+
END FUNCTION RECURSIVE_DECLARE_TARGET

0 commit comments

Comments
 (0)