From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1820) id 5992B385840B; Thu, 10 Mar 2022 18:31:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5992B385840B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Hafiz Abid Qadeer To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] Gimplify allocate directive (OpenMP 5.0). X-Act-Checkin: gcc X-Git-Author: Hafiz Abid Qadeer X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: d245b65b82267ee1f3958730dc1ede240c1f0426 X-Git-Newrev: 001f75fdc51c2f075468c57f580ba4cde76d0c66 Message-Id: <20220310183122.5992B385840B@sourceware.org> Date: Thu, 10 Mar 2022 18:31:22 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2022 18:31:22 -0000 https://gcc.gnu.org/g:001f75fdc51c2f075468c57f580ba4cde76d0c66 commit 001f75fdc51c2f075468c57f580ba4cde76d0c66 Author: Hafiz Abid Qadeer Date: Wed Mar 9 13:42:35 2022 +0000 Gimplify allocate directive (OpenMP 5.0). Backport of a patch posted at https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588371.html gcc/ChangeLog: * doc/gimple.texi: Describe GIMPLE_OMP_ALLOCATE. * gimple-pretty-print.c (dump_gimple_omp_allocate): New function. (pp_gimple_stmt_1): Call it. * gimple.c (gimple_build_omp_allocate): New function. * gimple.def (GIMPLE_OMP_ALLOCATE): New node. * gimple.h (enum gf_mask): Add GF_OMP_ALLOCATE_KIND_MASK, GF_OMP_ALLOCATE_KIND_ALLOCATE and GF_OMP_ALLOCATE_KIND_FREE. (struct gomp_allocate): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (gimple_build_omp_allocate): Declare. (gimple_omp_subcode): Replace GIMPLE_OMP_TEAMS with GIMPLE_OMP_ALLOCATE. (gimple_omp_allocate_set_clauses): New. (gimple_omp_allocate_set_kind): Likewise. (gimple_omp_allocate_clauses): Likewise. (gimple_omp_allocate_kind): Likewise. (CASE_GIMPLE_OMP): Add GIMPLE_OMP_ALLOCATE. * gimplify.c (gimplify_omp_allocate): New. (gimplify_expr): Call it. * gsstruct.def (GSS_OMP_ALLOCATE): Define. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-6.f90: Add tests. Diff: --- gcc/ChangeLog.omp | 27 ++++++++++++ gcc/doc/gimple.texi | 38 ++++++++++++++++- gcc/gimple-pretty-print.c | 37 +++++++++++++++++ gcc/gimple.c | 10 +++++ gcc/gimple.def | 6 +++ gcc/gimple.h | 60 ++++++++++++++++++++++++++- gcc/gimplify.c | 19 +++++++++ gcc/gsstruct.def | 1 + gcc/testsuite/ChangeLog.omp | 7 ++++ gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 | 4 +- 10 files changed, 205 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index f5d59fbec6f..8390f83f072 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,30 @@ +2022-03-09 Abid Qadeer + + Backport of a patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588371.html + + * doc/gimple.texi: Describe GIMPLE_OMP_ALLOCATE. + * gimple-pretty-print.c (dump_gimple_omp_allocate): New function. + (pp_gimple_stmt_1): Call it. + * gimple.c (gimple_build_omp_allocate): New function. + * gimple.def (GIMPLE_OMP_ALLOCATE): New node. + * gimple.h (enum gf_mask): Add GF_OMP_ALLOCATE_KIND_MASK, + GF_OMP_ALLOCATE_KIND_ALLOCATE and GF_OMP_ALLOCATE_KIND_FREE. + (struct gomp_allocate): New. + (is_a_helper ::test): New. + (is_a_helper ::test): New. + (gimple_build_omp_allocate): Declare. + (gimple_omp_subcode): Replace GIMPLE_OMP_TEAMS with + GIMPLE_OMP_ALLOCATE. + (gimple_omp_allocate_set_clauses): New. + (gimple_omp_allocate_set_kind): Likewise. + (gimple_omp_allocate_clauses): Likewise. + (gimple_omp_allocate_kind): Likewise. + (CASE_GIMPLE_OMP): Add GIMPLE_OMP_ALLOCATE. + * gimplify.c (gimplify_omp_allocate): New. + (gimplify_expr): Call it. + * gsstruct.def (GSS_OMP_ALLOCATE): Define. + 2022-03-09 Abid Qadeer Backport of a patch posted at diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi index a83e17f71a4..f58272a35a9 100644 --- a/gcc/doc/gimple.texi +++ b/gcc/doc/gimple.texi @@ -420,6 +420,9 @@ kinds, along with their relationships to @code{GSS_} values (layouts) and + gomp_continue | layout: GSS_OMP_CONTINUE, code: GIMPLE_OMP_CONTINUE | + + gomp_allocate + | layout: GSS_OMP_ALLOCATE, code: GIMPLE_OMP_ALLOCATE + | + gomp_atomic_load | layout: GSS_OMP_ATOMIC_LOAD, code: GIMPLE_OMP_ATOMIC_LOAD | @@ -454,6 +457,7 @@ The following table briefly describes the GIMPLE instruction set. @item @code{GIMPLE_GOTO} @tab x @tab x @item @code{GIMPLE_LABEL} @tab x @tab x @item @code{GIMPLE_NOP} @tab x @tab x +@item @code{GIMPLE_OMP_ALLOCATE} @tab x @tab x @item @code{GIMPLE_OMP_ATOMIC_LOAD} @tab x @tab x @item @code{GIMPLE_OMP_ATOMIC_STORE} @tab x @tab x @item @code{GIMPLE_OMP_CONTINUE} @tab x @tab x @@ -1037,6 +1041,7 @@ Return a deep copy of statement @code{STMT}. * @code{GIMPLE_LABEL}:: * @code{GIMPLE_GOTO}:: * @code{GIMPLE_NOP}:: +* @code{GIMPLE_OMP_ALLOCATE}:: * @code{GIMPLE_OMP_ATOMIC_LOAD}:: * @code{GIMPLE_OMP_ATOMIC_STORE}:: * @code{GIMPLE_OMP_CONTINUE}:: @@ -1737,6 +1742,38 @@ Build a @code{GIMPLE_NOP} statement. Returns @code{TRUE} if statement @code{G} is a @code{GIMPLE_NOP}. @end deftypefn +@node @code{GIMPLE_OMP_ALLOCATE} +@subsection @code{GIMPLE_OMP_ALLOCATE} +@cindex @code{GIMPLE_OMP_ALLOCATE} + +@deftypefn {GIMPLE function} gomp_allocate *gimple_build_omp_allocate ( @ +tree clauses, int kind) +Build a @code{GIMPLE_OMP_ALLOCATE} statement. @code{CLAUSES} is the clauses +associated with this node. @code{KIND} is the enumeration value +@code{GF_OMP_ALLOCATE_KIND_ALLOCATE} if this directive allocates memory +or @code{GF_OMP_ALLOCATE_KIND_FREE} if it de-allocates. +@end deftypefn + +@deftypefn {GIMPLE function} void gimple_omp_allocate_set_clauses ( @ +gomp_allocate *g, tree clauses) +Set the @code{CLAUSES} for a @code{GIMPLE_OMP_ALLOCATE}. +@end deftypefn + +@deftypefn {GIMPLE function} tree gimple_omp_aallocate_clauses ( @ +const gomp_allocate *g) +Get the @code{CLAUSES} of a @code{GIMPLE_OMP_ALLOCATE}. +@end deftypefn + +@deftypefn {GIMPLE function} void gimple_omp_allocate_set_kind ( @ +gomp_allocate *g, int kind) +Set the @code{KIND} for a @code{GIMPLE_OMP_ALLOCATE}. +@end deftypefn + +@deftypefn {GIMPLE function} tree gimple_omp_allocate_kind ( @ +const gomp_atomic_load *g) +Get the @code{KIND} of a @code{GIMPLE_OMP_ALLOCATE}. +@end deftypefn + @node @code{GIMPLE_OMP_ATOMIC_LOAD} @subsection @code{GIMPLE_OMP_ATOMIC_LOAD} @cindex @code{GIMPLE_OMP_ATOMIC_LOAD} @@ -1768,7 +1805,6 @@ const gomp_atomic_load *g) Get the @code{RHS} of an atomic set. @end deftypefn - @node @code{GIMPLE_OMP_ATOMIC_STORE} @subsection @code{GIMPLE_OMP_ATOMIC_STORE} @cindex @code{GIMPLE_OMP_ATOMIC_STORE} diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index f302c7e7a76..2240c864767 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -1955,6 +1955,38 @@ dump_gimple_omp_critical (pretty_printer *buffer, const gomp_critical *gs, } } +static void +dump_gimple_omp_allocate (pretty_printer *buffer, const gomp_allocate *gs, + int spc, dump_flags_t flags) +{ + if (flags & TDF_RAW) + { + const char *kind=""; + switch (gimple_omp_allocate_kind (gs)) + { + case GF_OMP_ALLOCATE_KIND_ALLOCATE: + kind = "allocate"; + break; + case GF_OMP_ALLOCATE_KIND_FREE: + kind = "free"; + break; + } + dump_gimple_fmt (buffer, spc, flags, "%G >"); + } + else + { + pp_string (buffer, "#pragma omp allocate "); + if (gimple_omp_allocate_kind (gs) == GF_OMP_ALLOCATE_KIND_ALLOCATE) + pp_string (buffer, "(kind=allocate) "); + else if (gimple_omp_allocate_kind (gs) == GF_OMP_ALLOCATE_KIND_FREE) + pp_string (buffer, "(kind=free) "); + + dump_omp_clauses (buffer, gimple_omp_allocate_clauses (gs), spc, flags); + } +} + /* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER. */ static void @@ -2865,6 +2897,11 @@ pp_gimple_stmt_1 (pretty_printer *buffer, const gimple *gs, int spc, spc, flags); break; + case GIMPLE_OMP_ALLOCATE: + dump_gimple_omp_allocate (buffer, as_a (gs), spc, + flags); + break; + case GIMPLE_CATCH: dump_gimple_catch (buffer, as_a (gs), spc, flags); break; diff --git a/gcc/gimple.c b/gcc/gimple.c index e62a6fe6f00..75853ffb914 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1302,6 +1302,16 @@ gimple_build_omp_metadirective_variant (gimple_seq body) return variant; } +gomp_allocate * +gimple_build_omp_allocate (tree clauses, int kind) +{ + gomp_allocate *p + = as_a (gimple_alloc (GIMPLE_OMP_ALLOCATE, 0)); + gimple_omp_allocate_set_clauses (p, clauses); + gimple_omp_allocate_set_kind (p, kind); + return p; +} + /* Build a GIMPLE_TRANSACTION statement. */ gtransaction * diff --git a/gcc/gimple.def b/gcc/gimple.def index 55ff9883193..94887efee58 100644 --- a/gcc/gimple.def +++ b/gcc/gimple.def @@ -388,6 +388,12 @@ DEFGSCODE(GIMPLE_OMP_TARGET, "gimple_omp_target", GSS_OMP_PARALLEL_LAYOUT) CHILD_FN and DATA_ARG like for GIMPLE_OMP_PARALLEL. */ DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_PARALLEL_LAYOUT) +/* GIMPLE_OMP_ALLOCATE represents + #pragma omp allocate + CLAUSES is an OMP_CLAUSE chain holding the associated clauses which hold + variables to be allocated. */ +DEFGSCODE(GIMPLE_OMP_ALLOCATE, "gimple_omp_allocate", GSS_OMP_ALLOCATE) + /* GIMPLE_OMP_ORDERED represents #pragma omp ordered. BODY is the sequence of statements to execute in the ordered section. CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */ diff --git a/gcc/gimple.h b/gcc/gimple.h index f98fdfac4bf..321c467b4c5 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -150,6 +150,9 @@ enum gf_mask { GF_CALL_BY_DESCRIPTOR = 1 << 10, GF_CALL_NOCF_CHECK = 1 << 11, GF_CALL_FROM_NEW_OR_DELETE = 1 << 12, + GF_OMP_ALLOCATE_KIND_MASK = (1 << 2) - 1, + GF_OMP_ALLOCATE_KIND_ALLOCATE = 1, + GF_OMP_ALLOCATE_KIND_FREE = 2, GF_OMP_PARALLEL_COMBINED = 1 << 0, GF_OMP_TASK_TASKLOOP = 1 << 0, GF_OMP_TASK_TASKWAIT = 1 << 1, @@ -798,6 +801,17 @@ struct GTY((tag("GSS_OMP_ATOMIC_LOAD"))) tree rhs, lhs; }; +/* GSS_OMP_ALLOCATE. */ + +struct GTY((tag("GSS_OMP_ALLOCATE"))) + gomp_allocate : public gimple +{ + /* [ WORD 1-6 ] : base class */ + + /* [ WORD 7 ] */ + tree clauses; +}; + /* GIMPLE_OMP_ATOMIC_STORE. See note on GIMPLE_OMP_ATOMIC_LOAD. */ @@ -1155,6 +1169,14 @@ is_a_helper ::test (gimple *gs) return gs->code == GIMPLE_OMP_ATOMIC_STORE; } +template <> +template <> +inline bool +is_a_helper ::test (gimple *gs) +{ + return gs->code == GIMPLE_OMP_ALLOCATE; +} + template <> template <> inline bool @@ -1413,6 +1435,14 @@ is_a_helper ::test (const gimple *gs) return gs->code == GIMPLE_OMP_ATOMIC_STORE; } +template <> +template <> +inline bool +is_a_helper ::test (const gimple *gs) +{ + return gs->code == GIMPLE_OMP_ALLOCATE; +} + template <> template <> inline bool @@ -1630,6 +1660,7 @@ gomp_sections *gimple_build_omp_sections (gimple_seq, tree); gimple *gimple_build_omp_sections_switch (void); gomp_single *gimple_build_omp_single (gimple_seq, tree); gomp_target *gimple_build_omp_target (gimple_seq, int, tree); +gomp_allocate *gimple_build_omp_allocate (tree, int); gomp_teams *gimple_build_omp_teams (gimple_seq, tree); gomp_atomic_load *gimple_build_omp_atomic_load (tree, tree, enum omp_memory_order); @@ -2351,7 +2382,7 @@ static inline unsigned gimple_omp_subcode (const gimple *s) { gcc_gimple_checking_assert (gimple_code (s) >= GIMPLE_OMP_ATOMIC_LOAD - && gimple_code (s) <= GIMPLE_OMP_TEAMS); + && gimple_code (s) <= GIMPLE_OMP_ALLOCATE); return s->subcode; } @@ -6357,6 +6388,30 @@ gimple_omp_sections_set_control (gimple *gs, tree control) omp_sections_stmt->control = control; } +static inline void +gimple_omp_allocate_set_clauses (gomp_allocate *gs, tree c) +{ + gs->clauses = c; +} + +static inline void +gimple_omp_allocate_set_kind (gomp_allocate *gs, int kind) +{ + gs->subcode = (gs->subcode & ~GF_OMP_ALLOCATE_KIND_MASK) + | (kind & GF_OMP_ALLOCATE_KIND_MASK); +} + +static inline tree +gimple_omp_allocate_clauses (const gomp_allocate *gs) +{ + return gs->clauses; +} + +static inline int +gimple_omp_allocate_kind (const gomp_allocate *gs) +{ + return (gimple_omp_subcode (gs) & GF_OMP_ALLOCATE_KIND_MASK); +} /* Set the value being stored in an atomic store. */ @@ -6677,7 +6732,8 @@ gimple_return_set_retval (greturn *gs, tree retval) case GIMPLE_OMP_ATOMIC_LOAD: \ case GIMPLE_OMP_ATOMIC_STORE: \ case GIMPLE_OMP_METADIRECTIVE: \ - case GIMPLE_OMP_CONTINUE + case GIMPLE_OMP_CONTINUE: \ + case GIMPLE_OMP_ALLOCATE static inline bool is_gimple_omp (const gimple *stmt) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index bafa3f1312f..6fc6a375b11 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -14644,6 +14644,21 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p) *expr_p = NULL_TREE; } +static void +gimplify_omp_allocate (tree *expr_p, gimple_seq *pre_p) +{ + tree expr = *expr_p; + int kind; + if (OMP_ALLOCATE_KIND_ALLOCATE (expr)) + kind = GF_OMP_ALLOCATE_KIND_ALLOCATE; + else + kind = GF_OMP_ALLOCATE_KIND_FREE; + gimple *stmt = gimple_build_omp_allocate (OMP_ALLOCATE_CLAUSES (expr), + kind); + gimplify_seq_add_stmt (pre_p, stmt); + *expr_p = NULL_TREE; +} + /* Gimplify the gross structure of OpenACC enter/exit data, update, and OpenMP target update constructs. */ @@ -16205,6 +16220,10 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, gimplify_omp_target_update (expr_p, pre_p); ret = GS_ALL_DONE; break; + case OMP_ALLOCATE: + gimplify_omp_allocate (expr_p, pre_p); + ret = GS_ALL_DONE; + break; case OMP_SECTION: case OMP_MASTER: diff --git a/gcc/gsstruct.def b/gcc/gsstruct.def index ff10605baec..22d6d37babd 100644 --- a/gcc/gsstruct.def +++ b/gcc/gsstruct.def @@ -52,4 +52,5 @@ DEFGSSTRUCT(GSS_OMP_ATOMIC_LOAD, gomp_atomic_load, false) DEFGSSTRUCT(GSS_OMP_ATOMIC_STORE_LAYOUT, gomp_atomic_store, false) DEFGSSTRUCT(GSS_OMP_METADIRECTIVE, gomp_metadirective, true) DEFGSSTRUCT(GSS_OMP_METADIRECTIVE_VARIANT, gomp_metadirective_variant, false) +DEFGSSTRUCT(GSS_OMP_ALLOCATE, gomp_allocate, false) DEFGSSTRUCT(GSS_TRANSACTION, gtransaction, false) diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 3894b61b378..ab42f1db389 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,10 @@ +2022-03-09 Abid Qadeer + + Backport of a patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588371.html + + * gfortran.dg/gomp/allocate-6.f90: Add tests. + 2022-03-09 Abid Qadeer Backport of a patch posted at diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 b/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 index 0eb35178e03..6957bc55da0 100644 --- a/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 @@ -1,5 +1,5 @@ ! { dg-do compile } -! { dg-additional-options "-fdump-tree-original" } +! { dg-additional-options "-fdump-tree-original -fdump-tree-gimple" } module omp_lib_kinds use iso_c_binding, only: c_int, c_intptr_t @@ -71,3 +71,5 @@ end subroutine ! { dg-final { scan-tree-dump-times "#pragma omp allocate \\(kind=allocate\\)" 6 "original" } } ! { dg-final { scan-tree-dump "#pragma omp allocate \\(kind=free\\)" "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp allocate \\(kind=allocate\\)" 6 "gimple" } } +! { dg-final { scan-tree-dump "#pragma omp allocate \\(kind=free\\)" "gimple" } }