Page MenuHomePhabricator

[flang]Add Parser Support for OpenMP Allocate Directive
Needs ReviewPublic

Authored by Rin on Oct 16 2020, 9:56 AM.

Details

Summary

This patch adds the Allocate Directive to the parser definition.

The OpenMP standard specifies that that the allocate directive is a declarative directive if it is not associated with an allocation statement, in which case it is executable.

OpenMP 5.0 standard specification: Section 2.11.3 Allocate Directive https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Rin added a project: Restricted Project.Oct 16 2020, 10:00 AM
Rin added inline comments.Oct 16 2020, 10:03 AM
flang/include/flang/Parser/parse-tree.h
3623

The Allocate Directive can take the Allocator Clause as its only clause, but that clause doesn't seem to have been implemented yet. Should I add it myself before going forward with this patch or can this be done at a later time?

Harbormaster completed remote builds in B75323: Diff 298658.

Can you provide more information about the allocate directive in the summary/description of this patch?
-> Point to the section in the standard.
-> Explain that the standard specifies a declarative and executable version.

Also add tests for the executable version as well. Have both of them in the same test to show that the parser is not confused.
Add unparse tests for both versions.

flang/include/flang/Parser/parse-tree.h
3623

Yes, add that also.

Rin edited the summary of this revision. (Show Details)Oct 19 2020, 4:09 AM
Rin updated this revision to Diff 299364.Oct 20 2020, 8:22 AM

Add Allocator Clause, Additional Tests and make the OmpObjectList optional for the Executable Allocate Clause

Rin marked an inline comment as done.Oct 20 2020, 8:24 AM
clementval requested changes to this revision.Oct 23 2020, 7:55 AM
clementval added inline comments.
flang/include/flang/Parser/parse-tree.h
3626

You should use the OmpClauseList and let the semantic check do the work. Otherwise each directive will have there own parser for theirs associated directive and this duplicates the code a lot.

OMP.td is already good for this directive.

def OMP_Allocate : Directive<"allocate"> {
  let allowedClauses = [
    VersionedClause<OMPC_Allocator>
  ];
}
flang/lib/Parser/openmp-parsers.cpp
460

You should re-use OmpClause parser instead of duplicating the parsing. If it's not in the OmpClause parser, just add it there.

474

Same here for the parser.

This revision now requires changes to proceed.Oct 23 2020, 7:55 AM
Rin updated this revision to Diff 300983.Oct 27 2020, 7:23 AM

Address review comments

Rin marked 3 inline comments as done.Oct 27 2020, 7:24 AM
Rin added inline comments.
flang/include/flang/Parser/parse-tree.h
3626

Thanks for that. I'll make sure to do so.

clementval added inline comments.Oct 27 2020, 8:43 AM
flang/include/flang/Parser/dump-parse-tree.h
548

Any reason to keep this?

556

Any reason to keep this?

flang/test/Parser/omp-allocate-unparse.f90
45

Newline.

Rin marked an inline comment as done.Oct 27 2020, 8:46 AM
Rin added inline comments.
flang/include/flang/Parser/dump-parse-tree.h
548

None other than the fact that I didn't notice it when I was cleaning up the code. Really sorry about that. Will remove it straight away. Same for the other one.

Rin updated this revision to Diff 301028.Oct 27 2020, 9:14 AM

Remove unnecessary comment and add newline to test

Rin marked 3 inline comments as done.Oct 27 2020, 9:15 AM
Rin added a comment.Wed, Nov 11, 6:38 AM

Does this look okay @clementval ?

kiranchandramohan requested changes to this revision.Mon, Nov 16, 10:43 AM
kiranchandramohan added inline comments.
flang/lib/Parser/openmp-parsers.cpp
454

The standard supports a list of openmp allocates associated with a single fortran allocate. Can you extend this to include the list?

!$omp allocate[(list)] clause
[!$omp allocate[(list)] clause
[...]]

flang/test/Parser/omp-allocate-unparse.f90
27

This check is probably not sufficient. Can you check for all the openmp allocates and the fortran allocate statements?

This revision now requires changes to proceed.Mon, Nov 16, 10:43 AM
Rin updated this revision to Diff 306655.Fri, Nov 20, 4:07 AM

Add support for list of OMP allocates and add additional checks in tests.

Rin marked 2 inline comments as done.Fri, Nov 20, 4:08 AM
clementval added inline comments.Fri, Nov 20, 8:08 AM
flang/include/flang/Parser/parse-tree.h
3625

Is there a good reason to have separate nodes (OpenMPDeclarativeAllocate, OpenMPExecutableAllocateList)? Both node have the same content.

Rin added inline comments.Fri, Nov 20, 8:11 AM
flang/include/flang/Parser/parse-tree.h
3625

OpenMPDeclarativeAllocate is part of the Declarative construct, whereas OpenMPExecutableAllocateList is part of the Executable construct. I can't use OpenMPDeclarativeAllocate as an executable construct is expected.

Rin added inline comments.Fri, Nov 20, 8:13 AM
flang/include/flang/Parser/parse-tree.h
3625

I had the same idea to use the OpenMPDeclarativeAllocate, but failed to find a way to make it work unfortunately :/

clementval added inline comments.Tue, Nov 24, 8:34 AM
flang/include/flang/Parser/parse-tree.h
3625

You should be able to use the same node in the two variants. What kind of problem did you face?

Rin added inline comments.Tue, Nov 24, 8:48 AM
flang/include/flang/Parser/parse-tree.h
3625

My issue was that OpenMPDeclarativeAllocate is a Declarative construct and an Executable construct was expected. I could add OpenMPDeclarativeAllocate to the Executable construct variant and see if that works

Rin updated this revision to Diff 307892.Thu, Nov 26, 9:03 AM

Remove unnecessary node

clementval accepted this revision.Mon, Nov 30, 11:23 AM

Just have a small comment. Otherwise I think it looks good to me. Please wait for the approval of someone on the OpenMP side.

flang/lib/Semantics/check-omp-structure.h
146

Can you move this up. I think the enter clause function are listed by alphabetical order.

I can review it from start as I am now more familiar with the files in this patch.
Please give me a day or so to revert back.
If it's approved from someone else in OpenMP you can go ahead without waiting from my end.

Rin added inline comments.Tue, Dec 1, 2:37 AM
flang/lib/Semantics/check-omp-structure.h
146

Yeah, sure thing, I'll do so right away.

Rin updated this revision to Diff 308616.Tue, Dec 1, 4:22 AM

Order Enter clase function in alphabetical order

Rin marked an inline comment as done.Tue, Dec 1, 4:24 AM

Thanks for working on this, I have mostly a few queries and some suggestions.

flang/include/flang/Parser/parse-tree.h
3619

Are you missing OpenMPDeclarativeAllocate in comments?

3625

Correct me if my interpretation from standard is wrong.

!$omp allocate[(list)] clause
[!$omp allocate(list)clause[...]]
allocate statement

the
std::optional<OpenMPDeclarativeAllocate> seem to be a list mentioned by elipsis, or is it that the there should be a list of clauses?

Althought there are tests(omp-allocate-directive.f90 line 19-23) which have a list of OpenMPDeclarativeAllocate for an OpenMPExecutableAllocate test.

flang/lib/Parser/openmp-parsers.cpp
457

In case of OpenMPExecutableAllocate are the clauses mandatory as the standard doesn't seem to have square brackets around them?
Or that's wrongly mentioned in standard.

As OmpClauseList is a list it can be optional.

!$omp allocate[(list)] clause
[!$omp allocate[(list)] clause
[...]]

So a test case like

!$omp allocate(a, b)
   allocate ( darray(a, b) )

becomes invalid in that case.

474

Does a test with no newline and an allocateStmt fall under OpenMPDeclarativeAllocate as per current implementations?

!$omp allocate(x, y) allocator(omp_default_mem_alloc) allocate( darray(x,y) )
flang/lib/Parser/unparse.cpp
2296

Why is there no Walk for std::optional<OpenMPDeclarativeAllocate> as parse-tree.h shows

std::tuple<Verbatim, std::optional<OmpObjectList>, OmpClauseList,
    std::optional<OpenMPDeclarativeAllocate>, Statement<AllocateStmt>>
    t;
flang/lib/Semantics/check-omp-structure.h
107

The commit title mentions this to be a parser change, are these semantic checks necessary with this patch?

flang/test/Parser/omp-allocate-unparse.f90
7

I see whitespaces at the end.

18

whitespace

20

whitespace.

22

whitespace

28

whitespace

flang/test/Semantics/omp-allocate-directive.f90
8

whitespace at end.

14

whitespace at end.

16

Is a test allowed with multiple clauses or will it be handled in semantic phase?

!$omp allocate(x, y) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
17

whitespace at end.

23

whitespace at end.

sameeranjoshi added a project: Restricted Project.Thu, Dec 3, 5:06 AM
clementval added inline comments.Thu, Dec 3, 6:07 AM
flang/lib/Parser/openmp-parsers.cpp
457

If there are required clauses they are set in the TableGen file. OmpClauseList should be used in preference of a stricter parser.

474

I don't think the allocate statement in that case will be handle by the fortran parser. The whole line is considered as a "comment" so the Fortran parser will not try to infer what is inside of it.

Rin added inline comments.Thu, Dec 3, 6:13 AM
flang/include/flang/Parser/parse-tree.h
3625

I'm not sure if I'm understanding the question correctly, but if you're asking about the (list), that refers to list-items.
What I get from this:

!$omp allocate[(list)] clause
[!$omp allocate(list)clause[...]]
allocate statement

Particularly this part: [!$omp allocate(list)clause[...]]

Is that an OpenMPExecutableAllocate can be followed by an optional list of OpenMPDeclarativeAllocate.

flang/lib/Parser/openmp-parsers.cpp
457

Hmm, I'm not too sure about this one. You're right that there are no square brackets, but then there are restrictions such as this one:

allocate directives that appear in a target region must specify an allocator clause unless a requires directive with the dynamic_allocators clause is present in the same compilation unit.

Which specify when an allocator clause needs to be present on a directive. So maybe they are still optional? I can make them required if my assumption is wrong.

474

No, I think that would be a comment since the allocateStmt is a Fortran Statement rather than an OpenMP one, so the newline is required.

flang/lib/Parser/unparse.cpp
2296

Oh, the unparsing of OpenMPDeclarativeAllocate is done by the function which handles OpenMPDeclarativeAllocate.

flang/lib/Semantics/check-omp-structure.h
107

Yes, because the directive context needs to be pushed using the PushContextAndClauseSets() function, otherwise there is an error. So these semantic checks are necessary in this patch.

flang/test/Parser/omp-allocate-unparse.f90
7

I will take care of those in the next update. Sorry about that. Failed to notice this detail.

flang/test/Semantics/omp-allocate-directive.f90
16

This will be handled in the semantics patch. It's not allowed.

Rin added inline comments.Thu, Dec 3, 6:14 AM
flang/lib/Parser/openmp-parsers.cpp
457

Oh yeah, I forgot about that, you're right.