[gcc/devel/omp/gcc-9] trans.c (walk_nesting_tree): New static function.

Tobias Burnus burnus@gcc.gnu.org
Thu Mar 5 13:54:00 GMT 2020


https://gcc.gnu.org/g:56bf2cee023e78ac55963716108ca33d6a35e477

commit 56bf2cee023e78ac55963716108ca33d6a35e477
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Tue May 28 08:03:08 2019 +0000

    trans.c (walk_nesting_tree): New static function.
    
    	* gcc-interface/trans.c (walk_nesting_tree): New static function.
    	(finalize_nrv): Use it to walk the entire nesting tree.
    
    From-SVN: r271686

Diff:
---
 gcc/ada/ChangeLog               |  5 +++++
 gcc/ada/gcc-interface/trans.c   | 20 +++++++++++++++-----
 gcc/testsuite/ChangeLog         |  4 ++++
 gcc/testsuite/gnat.dg/opt79.adb | 28 ++++++++++++++++++++++++++++
 gcc/testsuite/gnat.dg/opt79.ads |  7 +++++++
 5 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index edf853a..bcbae749 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,5 +1,10 @@
 2019-05-28  Eric Botcazou  <ebotcazou@adacore.com>
 
+	* gcc-interface/trans.c (walk_nesting_tree): New static function.
+	(finalize_nrv): Use it to walk the entire nesting tree.
+
+2019-05-28  Eric Botcazou  <ebotcazou@adacore.com>
+
 	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Subtype>: Remove
 	obsolete test on Is_For_Access_Subtype.
 
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index d2dda4a..84e03a6 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -4279,6 +4279,20 @@ finalize_nrv_unc_r (tree *tp, int *walk_subtrees, void *data)
   return NULL_TREE;
 }
 
+/* Apply FUNC to all the sub-trees of nested functions in NODE.  FUNC is called
+   with the DATA and the address of each sub-tree.  If FUNC returns a non-NULL
+   value, the traversal is stopped.  */
+
+static void
+walk_nesting_tree (struct cgraph_node *node, walk_tree_fn func, void *data)
+{
+  for (node = node->nested; node; node = node->next_nested)
+    {
+      walk_tree_without_duplicates (&DECL_SAVED_TREE (node->decl), func, data);
+      walk_nesting_tree (node, func, data);
+    }
+}
+
 /* Finalize the Named Return Value optimization for FNDECL.  The NRV bitmap
    contains the candidates for Named Return Value and OTHER is a list of
    the other return values.  GNAT_RET is a representative return node.  */
@@ -4286,7 +4300,6 @@ finalize_nrv_unc_r (tree *tp, int *walk_subtrees, void *data)
 static void
 finalize_nrv (tree fndecl, bitmap nrv, vec<tree, va_gc> *other, Node_Id gnat_ret)
 {
-  struct cgraph_node *node;
   struct nrv_data data;
   walk_tree_fn func;
   unsigned int i;
@@ -4307,10 +4320,7 @@ finalize_nrv (tree fndecl, bitmap nrv, vec<tree, va_gc> *other, Node_Id gnat_ret
     return;
 
   /* Prune also the candidates that are referenced by nested functions.  */
-  node = cgraph_node::get_create (fndecl);
-  for (node = node->nested; node; node = node->next_nested)
-    walk_tree_without_duplicates (&DECL_SAVED_TREE (node->decl), prune_nrv_r,
-				  &data);
+  walk_nesting_tree (cgraph_node::get_create (fndecl), prune_nrv_r, &data);
   if (bitmap_empty_p (nrv))
     return;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 31b52c2..9552b06 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
 2019-05-28  Eric Botcazou  <ebotcazou@adacore.com>
 
+	* gnat.dg/opt79.ad[sb]: New test.
+
+2019-05-28  Eric Botcazou  <ebotcazou@adacore.com>
+
 	* gnat.dg/specs/discr5.ads: New test.
 
 2019-05-27  Eric Botcazou  <ebotcazou@adacore.com>
diff --git a/gcc/testsuite/gnat.dg/opt79.adb b/gcc/testsuite/gnat.dg/opt79.adb
new file mode 100644
index 0000000..f58e25b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt79.adb
@@ -0,0 +1,28 @@
+-- { dg-do compile }
+-- { dg-options "-O" }
+
+package body Opt79 is
+
+  function F (I : Integer) return Arr is
+    A : Arr;
+
+    procedure Nested is
+
+      procedure Inner is
+      begin
+        A (1) := 0;
+      end;
+
+    begin
+       Inner;
+    end;
+
+  begin
+    Nested;
+    for J in A'Range loop
+      A (J) := I;
+    end loop;
+    return A;
+  end;
+
+end Opt79;
diff --git a/gcc/testsuite/gnat.dg/opt79.ads b/gcc/testsuite/gnat.dg/opt79.ads
new file mode 100644
index 0000000..aa90c17
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt79.ads
@@ -0,0 +1,7 @@
+package Opt79 is
+
+  type Arr is array (1 .. 8) of Integer;
+
+  function F (I : Integer) return Arr;
+
+end Opt79;



More information about the Gcc-cvs mailing list