* [Patch] OpenMP: detach - fix firstprivate handling
@ 2021-05-11 21:54 Tobias Burnus
2021-05-12 14:55 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2021-05-11 21:54 UTC (permalink / raw)
To: gcc-patches, Jakub Jelinek
[-- Attachment #1: Type: text/plain, Size: 487 bytes --]
The sfield / firstprivate lookup used the wrong var decl
for the lookup – hence it failed.
I used an extra long diff to make it easier to follow why
'c' and not 'detach_clause' has the proper clause for the
decl to be used as key.
Testsuite run ongoing.
OK for mainline, when it passes?
Tobias
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
[-- Attachment #2: detach.diff --]
[-- Type: text/x-patch, Size: 3034 bytes --]
OpenMP: detach - fix firstprivate handling
gcc/ChangeLog:
* omp-low.c (finish_taskreg_scan): Use the proper detach decl.
libgomp/ChangeLog:
* testsuite/libgomp.fortran/detach-1.f90: New test.
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index c0ce1a4990e..cadca7e201f 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2436,55 +2436,55 @@ finish_taskreg_scan (omp_context *ctx)
/* Look for a firstprivate clause with the detach event handle. */
for (c = gimple_omp_taskreg_clauses (ctx->stmt);
c; c = OMP_CLAUSE_CHAIN (c))
{
if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
continue;
if (maybe_lookup_decl_in_outer_ctx (OMP_CLAUSE_DECL (c), ctx)
== OMP_CLAUSE_DECL (detach_clause))
break;
}
gcc_assert (c);
field = lookup_field (OMP_CLAUSE_DECL (c), ctx);
/* Move field corresponding to the detach clause first.
This is filled by GOMP_task and needs to be in a
specific position. */
p = &TYPE_FIELDS (ctx->record_type);
while (*p)
if (*p == field)
*p = DECL_CHAIN (*p);
else
p = &DECL_CHAIN (*p);
DECL_CHAIN (field) = TYPE_FIELDS (ctx->record_type);
TYPE_FIELDS (ctx->record_type) = field;
if (ctx->srecord_type)
{
- field = lookup_sfield (OMP_CLAUSE_DECL (detach_clause), ctx);
+ field = lookup_sfield (OMP_CLAUSE_DECL (c), ctx);
p = &TYPE_FIELDS (ctx->srecord_type);
while (*p)
if (*p == field)
*p = DECL_CHAIN (*p);
else
p = &DECL_CHAIN (*p);
DECL_CHAIN (field) = TYPE_FIELDS (ctx->srecord_type);
TYPE_FIELDS (ctx->srecord_type) = field;
}
}
layout_type (ctx->record_type);
fixup_child_record_type (ctx);
if (ctx->srecord_type)
layout_type (ctx->srecord_type);
tree t = fold_convert_loc (loc, long_integer_type_node,
TYPE_SIZE_UNIT (ctx->record_type));
if (TREE_CODE (t) != INTEGER_CST)
{
t = unshare_expr (t);
walk_tree (&t, finish_taskreg_remap, ctx, NULL);
}
gimple_omp_task_set_arg_size (ctx->stmt, t);
t = build_int_cst (long_integer_type_node,
TYPE_ALIGN_UNIT (ctx->record_type));
gimple_omp_task_set_arg_align (ctx->stmt, t);
}
}
diff --git a/libgomp/testsuite/libgomp.fortran/detach-1.f90 b/libgomp/testsuite/libgomp.fortran/detach-1.f90
new file mode 100644
index 00000000000..88546fe473b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/detach-1.f90
@@ -0,0 +1,22 @@
+program test
+ use omp_lib
+ implicit none
+ integer(omp_event_handle_kind) :: oevent, ievent
+ integer :: i
+ integer, allocatable :: temp(:)
+ ALLOCATE(temp(5))
+
+ !$omp parallel num_threads(3)
+ !$omp single
+ DO i=1,5
+ !$omp task firstprivate(i) firstprivate(temp) detach(oevent)
+ temp(:) = 0;
+ temp(1) = -1;
+ !print *,temp
+ call omp_fulfill_event(oevent)
+ !$omp end task
+ ENDDO
+ !$omp taskwait
+ !$omp end single
+ !$omp end parallel
+end program
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch] OpenMP: detach - fix firstprivate handling
2021-05-11 21:54 [Patch] OpenMP: detach - fix firstprivate handling Tobias Burnus
@ 2021-05-12 14:55 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2021-05-12 14:55 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches
On Tue, May 11, 2021 at 11:54:58PM +0200, Tobias Burnus wrote:
> The sfield / firstprivate lookup used the wrong var decl
> for the lookup – hence it failed.
> I used an extra long diff to make it easier to follow why
> 'c' and not 'detach_clause' has the proper clause for the
> decl to be used as key.
>
> Testsuite run ongoing.
> OK for mainline, when it passes?
>
> Tobias
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
> OpenMP: detach - fix firstprivate handling
> gcc/ChangeLog:
>
> * omp-low.c (finish_taskreg_scan): Use the proper detach decl.
>
> libgomp/ChangeLog:
>
> * testsuite/libgomp.fortran/detach-1.f90: New test.
LGTM, but please add also a libgomp.c-c++-common/task-detach-12.c testcase
like:
/* { dg-do run } */
/* { dg-options "-fopenmp" } */
#include <omp.h>
int
main ()
{
struct S { int a[7]; } s = { { 1, 2, 3, 4, 5, 6, 7 } };
omp_event_handle_t x;
#pragma omp parallel master
#pragma omp task firstprivate (s) detach (x)
{
if (s.a[3] != 4)
__builtin_abort ();
omp_fulfill_event (x);
}
return 0;
}
Also, please backport to 11 after a while.
Thanks.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-12 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 21:54 [Patch] OpenMP: detach - fix firstprivate handling Tobias Burnus
2021-05-12 14:55 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).