| 1 |
! { dg-do compile } |
| 2 |
! { dg-additional-options "-fdump-tree-gimple" } |
| 3 |
|
| 4 |
! Check that __builtin_omp_get_default_device and __builtin_omp_get_mapped_ptr |
| 5 |
! are called with the right arguments depending on is_device_ptr. By default, |
| 6 |
! Fortran passes arguments by reference, so it is important to check that: |
| 7 |
! (1) __builtin_omp_get_mapped_ptr arguments are the actual pointers; and |
| 8 |
! (2) f1 arguments are references to pointers. |
| 9 |
|
| 10 |
module main |
| 11 |
use iso_c_binding, only: c_ptr |
| 12 |
implicit none |
| 13 |
interface |
| 14 |
subroutine f1 (p, p2) |
| 15 |
import :: c_ptr |
| 16 |
type(c_ptr), intent(out) :: p |
| 17 |
type(c_ptr), intent(in) :: p2 |
| 18 |
end subroutine |
| 19 |
subroutine f2 (p, p2) |
| 20 |
import :: c_ptr |
| 21 |
type(c_ptr), intent(out) :: p |
| 22 |
type(c_ptr), intent(in) :: p2 |
| 23 |
!$omp declare variant (f1) match (construct={dispatch}) adjust_args (need_device_ptr: p, p2) |
| 24 |
end subroutine |
| 25 |
end interface |
| 26 |
contains |
| 27 |
|
| 28 |
subroutine test () |
| 29 |
type(c_ptr) :: p, p2 |
| 30 |
|
| 31 |
! Note there are multiple matches because every variable capturing matches in addition, |
| 32 |
! i.e. scan-tree-dump-times = 1 plus number of captures used for backward references. |
| 33 |
! |
| 34 |
! For the first scan-tree-dump, on some targets the __builtin_omp_get_mapped_ptr get |
| 35 |
! swapped. |
| 36 |
|
| 37 |
!$omp dispatch |
| 38 |
! { dg-final { scan-tree-dump-times "#pragma omp dispatch.*(D\.\[0-9]+) = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*(p2?\.\[0-9]) = p2?;\[ \t\n\r]*(D\.\[0-9]+) = __builtin_omp_get_mapped_ptr \\(\\2, \\1\\);\[ \t\n\r]*(D\.\[0-9]+) = \\3;\[ \t\n\r]*(p2?\.\[0-9]) = p2?;\[ \t\n\r]*(D\.\[0-9]+) = __builtin_omp_get_mapped_ptr \\(\\5, \\1\\);\[ \t\n\r]*(D\.\[0-9]+) = \\6;\[ \t\n\r]*f1 \\((?:&\\7, &\\4|&\\4, &\\7)\\);" 8 "gimple" } } |
| 39 |
call f2 (p, p2) |
| 40 |
!$omp dispatch is_device_ptr(p) |
| 41 |
! { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(p\\).*(D\.\[0-9]+) = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*(p2\.\[0-9]) = p2;\[ \t\n\r]*(D\.\[0-9]+) = __builtin_omp_get_mapped_ptr \\(\\2, \\1\\);\[ \t\n\r]*(D\.\[0-9]+) = \\3;\[ \t\n\r]*f1 \\(&p, &\\4\\);" 5 "gimple" } } |
| 42 |
call f2 (p, p2) |
| 43 |
!$omp dispatch is_device_ptr(p2) |
| 44 |
! { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(p2\\).*(D\.\[0-9]+) = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*(p\.\[0-9]) = p;\[ \t\n\r]*(D\.\[0-9]+) = __builtin_omp_get_mapped_ptr \\(\\2, \\1\\);\[ \t\n\r]*(D\.\[0-9]+) = \\3;\[ \t\n\r]*f1 \\(&\\4, &p2\\);" 5 "gimple" } } |
| 45 |
call f2 (p, p2) |
| 46 |
!$omp dispatch is_device_ptr(p, p2) |
| 47 |
! { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(p\\) is_device_ptr\\(p2\\)\[ \t\n\r\{]*p = {CLOBBER};\[ \t\n\r]*f1 \\(&p, &p2\\);" 1 "gimple" } } |
| 48 |
call f2 (p, p2) |
| 49 |
end subroutine |
| 50 |
end module |
| 51 |
|