public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, fortran <fortran@gcc.gnu.org>
Subject: Re: [Patch] OpenMP/Fortran: Add support for enter clause on declare target (was: [committed] openmp: Add support for enter clause on declare target)
Date: Fri, 27 May 2022 17:20:06 +0200	[thread overview]
Message-ID: <YpDsJpcjfSCXmWwd@tucnak> (raw)
In-Reply-To: <651ae4c2-9440-b8df-e8af-b14491d45937@codesourcery.com>

On Fri, May 27, 2022 at 04:52:17PM +0200, Tobias Burnus wrote:
> This patch adds the Fortran support to the just-committed C/C++ support for the 'enter' clause.
> 
> The 'TO'/'ENTER' usage is first stored in a linked list – and
> then as attribute to the symbol. I am not sure how to handle it best.
> I did went for adding an ENTER_LIST but kept only using the single attribute.
> 
> Result: In one diagnostic, I use 'TO or ENTER clause'  in the other,
> I can properly use 'TO' or 'ENTER' clause.
> 
> This could be kept as is, but to save memory it would be possible
> to drop the ENTER_LIST – or, to improve diagnostic, we could try harder
> (e.g. by re-walking the list or by another gfc_attribute). Preferences?
> If not, I would go for the attached middle way.
> 
> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

> OpenMP/Fortran: Add support for enter clause on declare target
> 
> Fortran version to C/C++ commit r13-797-g0ccba4ed8571c18c7015413441e971
> 
> gcc/fortran/ChangeLog:
> 
> 	* dump-parse-tree.cc (show_omp_clauses): Handle OMP_LIST_ENTER.
> 	* gfortran.h: Add OMP_LIST_ENTER.
> 	* openmp.cc (enum omp_mask2, OMP_DECLARE_TARGET_CLAUSES): Add
> 	OMP_CLAUSE_ENTER.
> 	(gfc_match_omp_clauses, gfc_match_omp_declare_target,
> 	resolve_omp_clauses): Handle 'enter' clause.
> 
> libgomp/ChangeLog:
> 
> 	* libgomp.texi (OpenMP 5.2): Mark 'enter' clause as supported.
> 	* testsuite/libgomp.fortran/declare-target-1.f90: Extend to test
> 	explicit 'to' and 'enter' clause.
> 	* testsuite/libgomp.fortran/declare-target-2.f90: Update accordingly.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gfortran.dg/gomp/declare-target-2.f90: Add 'enter' clause test.
> 	* gfortran.dg/gomp/declare-target-4.f90: Likewise.

Mostly good, but see below.

> -  for (list = OMP_LIST_TO; list != OMP_LIST_NUM;
> -       list = (list == OMP_LIST_TO ? OMP_LIST_LINK : OMP_LIST_NUM))
> +  for (list = OMP_LIST_ENTER; list != OMP_LIST_NUM;
> +       list = (list == OMP_LIST_ENTER
> +	       ? OMP_LIST_TO
> +	       : (list == OMP_LIST_TO ? OMP_LIST_LINK : OMP_LIST_NUM)))
>      for (n = c->lists[list]; n; n = n->next)
>        if (n->sym)
>  	{
> @@ -4564,14 +4584,14 @@ gfc_match_omp_declare_target (void)
>  		   && n->sym->attr.omp_declare_target_link
>  		   && list != OMP_LIST_LINK)
>  	    gfc_error_now ("OMP DECLARE TARGET variable at %L previously "
> -			   "mentioned in LINK clause and later in TO clause",
> -			   &n->where);
> +			   "mentioned in LINK clause and later in %s clause",
> +			   &n->where, list == OMP_LIST_TO ? "TO" : "ENTER");
>  	  else if (n->sym->attr.omp_declare_target
>  		   && !n->sym->attr.omp_declare_target_link
>  		   && list == OMP_LIST_LINK)
>  	    gfc_error_now ("OMP DECLARE TARGET variable at %L previously "
> -			   "mentioned in TO clause and later in LINK clause",
> -			   &n->where);
> +			   "mentioned in TO or ENTER clause and later in "
> +			   "LINK clause", &n->where);

The wording of the messages "previously mentioned in FOO and later in BAR clause"
makes not much sense to me, because we in the Fortran FE don't remember which
clause was specified earlier and which one was later.
The loop is walking first all enter clauses, then all to clauses, then all
link clauses.

Now, if we change the wording so that it complains that a variable is
"mentioned in both FOO and BAR clauses", we could avoid the TO or ENTER
stuff even without some O(n^2) complexity or extra bit somewhere simply
by walking the clauses in the order of TO, LINK, ENTER (or ENTER, LINK, TO)
clauses, wer could be exact.

Though, further thinking about it, this isn't just about the case
where it is on the same declare target, but also on multiple and in that
case previous/later makes sense.

As we don't remember if it was previously TO or ENTER, I'd just suggest:
1) simplify the 2 for cycles, with 3 lists it is too unreadable, so use
   something like:
  static const int to_enter_link_lists[]
    = { OMP_LIST_TO, OMP_LIST_ENTER, OMP_LIST_LINK };
  for (int listn = 0; listn < ARRAY_SIZE (to_enter_link_lists)
		      && (list = to_enter_link_lists[listn], true); ++listn)
2) move the
          else if (n->sym->mark)
            gfc_error_now ("Variable at %L mentioned multiple times in "
                           "clauses of the same OMP DECLARE TARGET directive",
                           &n->where);
  diagnostics earlier, above
          else if (n->sym->attr.omp_declare_target
                   && n->sym->attr.omp_declare_target_link
                   && list != OMP_LIST_LINK)
  and adjust testsuite if needed

Ok with those changes.

On the C/C++ FE side, I'll need to change %<to%> to %<to%> or %<enter%>.

	Jakub


  reply	other threads:[~2022-05-27 15:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <YpCt2rJGuydcFlA4@tucnak>
2022-05-27 14:52 ` Tobias Burnus
2022-05-27 15:20   ` Jakub Jelinek [this message]
2022-05-27 15:44     ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YpDsJpcjfSCXmWwd@tucnak \
    --to=jakub@redhat.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).