diff mbox series

OpenMP: Add implicit declare target for nested procedures

Message ID b3f824b0-7b87-9a9c-5a1d-50ceb4e02880@codesourcery.com
State New
Headers show
Series OpenMP: Add implicit declare target for nested procedures | expand

Commit Message

Tobias Burnus Sept. 30, 2020, 11:37 a.m. UTC
We missed to handle nested procedures.

OK for the trunk?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Comments

Jakub Jelinek Sept. 30, 2020, 11:39 a.m. UTC | #1
On Wed, Sep 30, 2020 at 01:37:46PM +0200, Tobias Burnus wrote:
> We missed to handle nested procedures.
> 
> OK for the trunk?

Yes, thanks.

	Jakub
diff mbox series

Patch

OpenMP: Add implicit declare target for nested procedures

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/omp-offload.c                                  |  7 ++++
 .../testsuite/libgomp.fortran/declare-target-3.f90 | 45 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index a89275b3a7a..7fb3a72ec55 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -327,11 +327,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_STATIC_INITIALIZER (vnode)
     if (omp_declare_target_var_p (vnode->decl))
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-3.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-3.f90
new file mode 100644
index 00000000000..6e5301de0a9
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/declare-target-3.f90
@@ -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" } }