This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
ClosedPublic

Authored by skatrak on Aug 15 2023, 7:25 AM.

Details

Summary

This patch adds support for storing OpenMP REQUIRES information in the semantics symbols for programs/subprograms and modules/submodules, and populates them during directive resolution. A pass is added to name resolution that makes sure this information is also propagated across top-level programs, functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow supporting the propagation of this information across Fortran modules. This will come as a separate patch.

The bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x) method is removed since it resulted in specification parts being visited twice.

This is patch 3/5 of a series splitting D149337 to simplify review.

Diff Detail

Event Timeline

skatrak created this revision.Aug 15 2023, 7:25 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
skatrak requested review of this revision.Aug 15 2023, 7:25 AM

Adding @klausler since the patch touches code outside the OpenMP semantics/parsing files.

klausler added inline comments.Aug 21 2023, 7:59 AM
flang/include/flang/Semantics/symbol.h
17

Why do you need parse-tree.h?

50

flang/include/flang/Common/enum-set.h is what we use in the f18 frontend for sets of attributes, such as Semantics/attr.h.

flang/test/Semantics/OpenMP/requires09.f90
2

What about module procedures? Do you need to emit these directives to module files?

skatrak updated this revision to Diff 552312.Aug 22 2023, 4:28 AM
skatrak marked 2 inline comments as done.

Address review comments.

flang/include/flang/Semantics/symbol.h
17

That's because it's got the definition of OmpAtomicDefaultMemOrderClause::Type, which is needed by WithOmpDeclarative.

50

Thank you for pointing this out, I didn't realize this. It's been addressed now.

flang/test/Semantics/OpenMP/requires09.f90
2

Yes, that's correct, but it comes as a separate dependent patch: D158168.

Ping for review! I'd appreciate it if @klausler or someone else could give this patch another look, since there are a few other patches that depend on it. Thank you!

klausler requested changes to this revision.Sep 1 2023, 8:52 AM
klausler added inline comments.
flang/include/flang/Semantics/symbol.h
17

That ENUM_CLASS (and others) could be moved elsewhere, such as to Common/Fortran.h, and then we wouldn't have to pull the gigantic parse-tree.h header file into every single compilation of semantics C++ files (and much of lowering).

18

Is BitMaskEnum.h still required?

18

Where is this used?

flang/lib/Semantics/resolve-directives.cpp
387

const auto

680

Use a reference, not a pointer, when indirecting to an object that must exist.

2157

If you're not going to use the pointer result of std::get_if, use std::holds_alternative instead.

2178

You're unconditionally dereferencing the pointer "symbol" in this code. Make it a reference instead.

This revision now requires changes to proceed.Sep 1 2023, 8:52 AM
skatrak updated this revision to Diff 555847.Sep 5 2023, 3:57 AM
skatrak marked 7 inline comments as done.

Address review comments.

Thank you for the feedback. I've addressed all but one of your comments, which I believe it would be best to do as a separate patch. Let me know.

flang/include/flang/Semantics/symbol.h
17

That makes sense, but my feeling is that this refactoring should come as a separate patch, since it would move several unrelated enums to a different file and it would be noisy here. I'll work on a PR to do that and then update this patch after that one lands. Is that a reasonable approach?

18

It's used at the bottom of the file. A comment says "Define required info so that SymbolRef can be used inside llvm::DenseMap".

18

It's not required, thanks for noticing.

skatrak updated this revision to Diff 555882.Sep 5 2023, 9:33 AM
skatrak marked an inline comment as done.

Move enumeration into common header to avoid pulling all parse tree definitions into symbol.h.

klausler added inline comments.Sep 8 2023, 12:33 PM
flang/lib/Parser/unparse.cpp
2310 ↗(On Diff #555882)

This switch() could be better implemented using x.EnumToString().

klausler accepted this revision.Sep 8 2023, 12:34 PM
This revision is now accepted and ready to land.Sep 8 2023, 12:34 PM
skatrak updated this revision to Diff 556408.Sep 11 2023, 3:29 AM
skatrak marked an inline comment as done.

Use EnumToString() in place of switch statement.

This revision was landed with ongoing or failed builds.Sep 11 2023, 3:48 AM
This revision was automatically updated to reflect the committed changes.