Debian Codegraph @

libgomp/testsuite/libgomp.fortran/dispatch-3.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fdump-tree-gimple" }
3
4 ! Check that nested function calls in a dispatch region are handled correctly,
5 ! i.e. that the adjust_args clause is applied only to the outer call.
6
7 module m
8 use iso_c_binding
9 use omp_lib
10 implicit none(type,external)
11 contains
12 integer function f(x, y1, y2, z1, z2)
13 allocatable :: f
14 integer, value :: x
15 type(c_ptr), value :: y1, y2
16 type(c_ptr) :: z1, z2
17
18 if (x == 1) then ! HOST
19 block
20 integer, pointer :: iy1, iy2, iz1, iz2
21 call c_f_pointer (y1, iy1)
22 call c_f_pointer (y2, iy2)
23 call c_f_pointer (z1, iz1)
24 call c_f_pointer (z2, iz2)
25 f = (iy1 + iy2) + 10 * (iz1+iz2)
26 end block
27 else
28 allocate(f)
29 !$omp target is_device_ptr(y1, y2, z1, z2) map(tofrom: f)
30 block
31 integer, pointer :: iy1, iy2, iz1, iz2
32 call c_f_pointer (y1, iy1)
33 call c_f_pointer (y2, iy2)
34 call c_f_pointer (z1, iz1)
35 call c_f_pointer (z2, iz2)
36 f = -(iy1+iy2)*23 -127 * (iz1+iz2) - x * 3
37 end block
38 end if
39 end
40
41 integer function g(x, y1, y2, z1, z2)
42 !$omp declare variant(f) match(construct={dispatch}) adjust_args(need_device_ptr : y1, y2, z1, z2)
43 allocatable :: g
44 integer, value :: x
45 type(c_ptr), value :: y1, y2
46 type(c_ptr) :: z1, z2
47 g = x
48 stop 2 ! should not get called
49 end
50 end
51
52 program main
53 use m
54 implicit none (type, external)
55 integer, target :: v1, v2
56 integer :: res, ref
57 v1 = 5
58 v2 = 11
59
60 ref = 5*2 + 10 * 11*2
61 ref = -(5*2)*23 -127 * (11*2) - ref * 3
62
63 !$omp target data map(v1,v2)
64 res = func (c_loc(v1), c_loc(v1), c_loc(v2), c_loc(v2))
65 !$omp end target data
66
67 if (res /= ref) stop 1
68 contains
69 integer function func(x1, x2, x3, x4)
70 use m
71 implicit none(type,external)
72 type(c_ptr) :: x1, x2, x3, x4
73 value :: x1, x3
74
75 !$omp dispatch
76 func = g(g(1,x1,x2,x3,x4), x1,x2,x3,x4)
77 end
78 end
79
80 ! { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 4 "gimple" } }