]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Add implicit declare target for nested procedures
authorTobias Burnus <tobias@codesourcery.com>
Wed, 30 Sep 2020 12:59:27 +0000 (14:59 +0200)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 18 Dec 2020 21:30:02 +0000 (13:30 -0800)
This is a backport from mainline of commit
8b0a63e47cd83f4e8534d0d201739bdd10f321a2.

gcc/ChangeLog:

* omp-offload.c (omp_discover_implicit_declare_target): Also
handled nested functions.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/declare-target-3.f90: New test.

gcc/ChangeLog.omp
gcc/omp-offload.c
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.fortran/declare-target-3.f90 [new file with mode: 0644]

index 9bc07f1425af598fc8255c8eecba477b136144ff..f333d3d24106c6b6b0478908b1218cdde7f728f5 100644 (file)
@@ -1,3 +1,11 @@
+2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-09-30  Tobias Burnus  <tobias@codesourcery.com>
+
+       * omp-offload.c (omp_discover_implicit_declare_target): Also
+       handled nested functions.
+
 2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
index 46e5d8f84a4f06b512c685f160e4cda5a720190f..f5ce34d3bdd8ac0f69f05236bd0d5ece76899f1e 100644 (file)
@@ -329,11 +329,18 @@ omp_discover_implicit_declare_target (void)
   FOR_EACH_DEFINED_FUNCTION (node)
     if (DECL_SAVED_TREE (node->decl))
       {
+       struct cgraph_node *cgn;
         if (omp_declare_target_fn_p (node->decl))
          worklist.safe_push (node->decl);
        else if (DECL_STRUCT_FUNCTION (node->decl)
                 && DECL_STRUCT_FUNCTION (node->decl)->has_omp_target)
          worklist.safe_push (node->decl);
+       for (cgn = node->nested; cgn; cgn = cgn->next_nested)
+         if (omp_declare_target_fn_p (cgn->decl))
+           worklist.safe_push (cgn->decl);
+         else if (DECL_STRUCT_FUNCTION (cgn->decl)
+                  && DECL_STRUCT_FUNCTION (cgn->decl)->has_omp_target)
+           worklist.safe_push (cgn->decl);
       }
   FOR_EACH_VARIABLE (vnode)
     if (lang_hooks.decls.omp_get_decl_init (vnode->decl)
index 1d3e37bc838fa2e56fa4df6fbd9051210ff3afe7..13b8339a248ac0451e1be6796043683333b64435 100644 (file)
@@ -1,3 +1,10 @@
+2020-12-18  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-09-30  Tobias Burnus  <tobias@codesourcery.com>
+
+       * testsuite/libgomp.fortran/declare-target-3.f90: New test.
+
 2020-11-19  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-3.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-3.f90
new file mode 100644 (file)
index 0000000..6e5301d
--- /dev/null
@@ -0,0 +1,45 @@
+! { dg-additional-options "-fdump-tree-omplower" }
+
+module m
+  implicit none (type, external)
+contains
+  subroutine mod_proc(x)
+    integer :: x(2)
+      x = x + 5
+    end subroutine
+end module m
+
+program main
+  use m
+  implicit none (type, external)
+  if (any (foo() /= [48, 49])) stop 1
+contains
+  integer function fourty_two(y)
+    integer :: y
+    fourty_two = y + 42
+  end function
+
+  integer function wrapper (x, y)
+    integer :: x, y(2)
+    call mod_proc(y)
+    wrapper = fourty_two(x) + 1
+  end function
+
+  function foo()
+    integer :: foo(2)
+    integer :: a(2)
+    integer :: b, summed(2)
+    a = [1, 2]
+    b = -1
+    !$omp target map (tofrom: a, b, summed)
+      summed = wrapper (b, a)
+    !$omp end target
+    if (b /= -1) stop 2            ! unchanged
+    if (any (summed /= 42)) stop 3 ! b + 42 + 1 = 42
+    if (any (a /= [6, 7])) stop 4  ! [1, 2] + 5
+    foo = summed + a               ! [48, 49]
+  end function
+end
+
+! 3 times: mod_proc, fourty_two and wrapper:
+! { dg-final { scan-tree-dump-times "__attribute__..omp declare target" 3 "omplower" } }