This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] Expand empty parallel directives into empty statements


Avoids going through the hassle of creating new functions and emitting 
calls to the runtime library when the body of the parallel directive is 
empty at the time of expansion.

Right now this only happens on silly input.  In the future, it may happen 
because of earlier optimization.


	* tree.c (empty_body_p): New.
	* tree.h (empty_body_p): Declare.
	* omp-low.c (scan_omp_parallel): Replace empty parallel
	directives with an empty statement.

testsuite/

	* gcc.dg/gomp/empty.c: New test.

Index: tree.c
===================================================================
--- tree.c	(revision 106332)
+++ tree.c	(working copy)
@@ -7385,4 +7385,30 @@ walk_tree_without_duplicates (tree *tp, 
   return result;
 }
 
+
+/* Return true if STMT is an empty statement or contains nothing but
+   empty statements.  */
+
+bool
+empty_body_p (tree stmt)
+{
+  tree_stmt_iterator i;
+  tree body;
+
+  if (IS_EMPTY_STMT (stmt))
+    return true;
+  else if (TREE_CODE (stmt) == BIND_EXPR)
+    body = BIND_EXPR_BODY (stmt);
+  else if (TREE_CODE (stmt) == STATEMENT_LIST)
+    body = stmt;
+  else
+    return false;
+
+  for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
+    if (!empty_body_p (tsi_stmt (i)))
+      return false;
+
+  return true;
+}
+
 #include "gt-tree.h"
Index: tree.h
===================================================================
--- tree.h	(revision 106332)
+++ tree.h	(working copy)
@@ -3858,6 +3858,7 @@ extern bool commutative_tree_code (enum 
 extern tree upper_bound_in_type (tree, tree);
 extern tree lower_bound_in_type (tree, tree);
 extern int operand_equal_for_phi_arg_p (tree, tree);
+extern bool empty_body_p (tree);
 
 /* In stmt.c */
 
Index: omp-low.c
===================================================================
--- omp-low.c	(revision 106332)
+++ omp-low.c	(working copy)
@@ -821,6 +821,13 @@ scan_omp_parallel (tree *stmt_p, omp_con
   omp_context *ctx;
   tree name;
 
+  /* Ignore parallel directives with empty bodies.  */
+  if (empty_body_p (OMP_PARALLEL_BODY (*stmt_p)))
+    {
+      *stmt_p = build_empty_stmt ();
+      return;
+    }
+
   ctx = new_omp_context (*stmt_p, outer_ctx);
   ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
   ctx->parallel_type = determine_parallel_type (*stmt_p);
Index: testsuite/gcc.dg/gomp/empty.c
===================================================================
--- testsuite/gcc.dg/gomp/empty.c	(revision 0)
+++ testsuite/gcc.dg/gomp/empty.c	(revision 0)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -fdump-tree-omplower" } */
+
+main()
+{
+#pragma omp parallel
+    {;}
+}
+
+/* There should not be a GOMP_parallel_start call.  */
+/* { dg-final { scan-tree-dump-times "GOMP_parallel_start" 0 "omplower"} } 
*/
+/* { dg-final { cleanup-tree-dump "omplower" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]