[gomp] Fix -fopenmp -fprofile-generate
Jakub Jelinek
jakub@redhat.com
Mon May 15 19:23:00 GMT 2006
Hi!
With -fopenmp -fprofile-generate, .OMP_DATA_I = &.OMP_DATA_O statement
might not be the first statement as expand_omp_parallel asserts, profile
counter update might preceede it:
<bb 3>:
PROF.5 = *.LPBX1[1];
PROF.6 = PROF.5 + 1;
*.LPBX1[1] = PROF.6;
.omp_data_i = &.omp_data_o.2;
This patch relaxes the search for this statement a little bit.
Tested on x86_64-linux, also with
make -j3 -k check RUNTESTFLAGS="gomp.exp --target_board=unix/-fprofile-generate"
make -C ../x86_64*/libgomp -k check RUNTESTFLAGS=--target_board=unix/-fprofile-generate
Ok for trunk?
2006-05-15 Jakub Jelinek <jakub@redhat.com>
PR middle-end/27573
* omp-low.c (expand_omp_parallel): Don't assert
.OMP_DATA_I = &.OMP_DATA_O is the first statement in the block,
instead search for it.
* gcc.dg/gomp/pr27573.c: New test.
* gfortran.dg/gomp/pr27573.f90: New test.
--- gcc/omp-low.c.jj 2006-05-12 16:11:52.000000000 +0200
+++ gcc/omp-low.c 2006-05-15 18:20:49.000000000 +0200
@@ -2456,7 +2456,8 @@ expand_omp_parallel (struct omp_region *
else
{
/* If the parallel region needs data sent from the parent
- function, then the very first statement of the parallel body
+ function, then the very first statement (except possible
+ tree profile counter updates) of the parallel body
is a copy assignment .OMP_DATA_I = &.OMP_DATA_O. Since
&.OMP_DATA_O is passed as an argument to the child function,
we need to replace it with the argument as seen by the child
@@ -2470,21 +2471,26 @@ expand_omp_parallel (struct omp_region *
if (OMP_PARALLEL_DATA_ARG (entry_stmt))
{
basic_block entry_succ_bb = single_succ (entry_bb);
- block_stmt_iterator si = bsi_start (entry_succ_bb);
- tree stmt;
+ block_stmt_iterator si;
- gcc_assert (!bsi_end_p (si));
+ for (si = bsi_start (entry_succ_bb); ; bsi_next (&si))
+ {
+ tree stmt;
- stmt = bsi_stmt (si);
- gcc_assert (TREE_CODE (stmt) == MODIFY_EXPR
- && TREE_CODE (TREE_OPERAND (stmt, 1)) == ADDR_EXPR
- && TREE_OPERAND (TREE_OPERAND (stmt, 1), 0)
- == OMP_PARALLEL_DATA_ARG (entry_stmt));
-
- if (TREE_OPERAND (stmt, 0) == DECL_ARGUMENTS (child_fn))
- bsi_remove (&si, true);
- else
- TREE_OPERAND (stmt, 1) = DECL_ARGUMENTS (child_fn);
+ gcc_assert (!bsi_end_p (si));
+ stmt = bsi_stmt (si);
+ if (TREE_CODE (stmt) == MODIFY_EXPR
+ && TREE_CODE (TREE_OPERAND (stmt, 1)) == ADDR_EXPR
+ && TREE_OPERAND (TREE_OPERAND (stmt, 1), 0)
+ == OMP_PARALLEL_DATA_ARG (entry_stmt))
+ {
+ if (TREE_OPERAND (stmt, 0) == DECL_ARGUMENTS (child_fn))
+ bsi_remove (&si, true);
+ else
+ TREE_OPERAND (stmt, 1) = DECL_ARGUMENTS (child_fn);
+ break;
+ }
+ }
}
/* Declare local variables needed in CHILD_CFUN. */
--- gcc/testsuite/gcc.dg/gomp/pr27573.c.jj 2006-05-15 18:55:55.000000000 +0200
+++ gcc/testsuite/gcc.dg/gomp/pr27573.c 2006-05-15 18:55:04.000000000 +0200
@@ -0,0 +1,20 @@
+/* PR middle-end/27573 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp -fprofile-generate" } */
+
+extern int puts (const char *);
+
+int
+main (void)
+{
+ int i, j = 8;
+#pragma omp parallel
+ {
+ puts ("foo");
+ for (i = 1; i < j - 1; i++)
+ ;
+ }
+ return 0;
+}
+
+/* { dg-final { cleanup-coverage-files } } */
--- gcc/testsuite/gfortran.dg/gomp/pr27573.f90.jj 2006-05-15 18:56:19.000000000 +0200
+++ gcc/testsuite/gfortran.dg/gomp/pr27573.f90 2006-05-15 18:55:30.000000000 +0200
@@ -0,0 +1,15 @@
+! PR middle-end/27573
+! { dg-do compile }
+! { dg-options "-O2 -fopenmp -fprofile-generate" }
+
+program pr27573
+ integer i,j
+ j = 8
+ !$omp parallel
+ print *, "foo"
+ do i = 1, j - 1
+ end do
+ !$omp end parallel
+end
+
+! { dg-final { cleanup-coverage-files } }
Jakub
More information about the Gcc-patches
mailing list