This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP][Semantics] Add semantics checks to requires directive
AbandonedPublic

Authored by skatrak on Apr 27 2023, 5:32 AM.

Details

Summary

This patch adds semantics checks to make sure that compilation units containing
more than one requires directive are correct, as well as making sure that
they do not come after other constructs that are affected by this directive. It
also handles the atomic_default_mem_order clause by setting it in a rewrite
step as an explicit memory order associated to all atomic operations that don't
already specify it.

The directive resolution step and the symbol details for function- and module-
like PFT nodes are extended to accomodate the addition and propagation of
information about 'requires' directives contained inside. This enables
exporting 'requires' clauses to .mod files and accessing them through 'use'
Fortran statements.

Additionally, an issue parsing this directive is fixed, which makes sure that
the source location of the requires clauses is available at the time of
performing semantic checks for the purpose of error reporting.

Diff Detail

Event Timeline

skatrak created this revision.Apr 27 2023, 5:32 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
skatrak requested review of this revision.Apr 27 2023, 5:32 AM
skatrak updated this revision to Diff 520314.May 8 2023, 3:12 AM

Implement atomic_default_mem_order clause support as semantic check, as
recommended in reviewer feedback for D147219.

Looks mostly fine.

We will probably want to store the information about the requires directive in modules. At the moment, I think, we only handle threadprivate directives in modules.

module moda
  !$omp requires atomic_default_mem_order(seq_cst)
end module moda

subroutine s
  use moda
  !$omp requires atomic_default_mem_order(relaxed)
end subroutine s
flang/lib/Semantics/check-omp-structure.cpp
1130

Frontend initialization (here and elsewhere in the file) should be with braces.

skatrak updated this revision to Diff 530015.Jun 9 2023, 10:27 AM

The directive resolution step and the symbol details for function- and module-
like PFT nodes are extended to accomodate the addition and propagation of
information about 'requires' directives contained inside. This enables
exporting 'requires' clauses to .mod files and accessing them through 'use'
Fortran statements.

skatrak updated this revision to Diff 531709.Jun 15 2023, 5:29 AM

Rebase to fix build error.

skatrak updated this revision to Diff 533970.Jun 23 2023, 8:07 AM

Re-implement atomic_default_mem_order support to after name resolution, so that 'requires' information from modules is used. Create a new rewrite-directives pass to be executed after name resolution and before structure checks to do this.

skatrak edited the summary of this revision. (Show Details)Jun 29 2023, 5:47 AM

Ping for review!

The patch has grown a bit since the last time I had a look. Would it be possible to split this into three for ease of review? 1 for the semantics without modules, 2 for the module changes, 3 for the pass.

This will help (1, 3) to go in fairly soon and to get review from others for (2).

The patch has grown a bit since the last time I had a look. Would it be possible to split this into three for ease of review? 1 for the semantics without modules, 2 for the module changes, 3 for the pass.

This will help (1, 3) to go in fairly soon and to get review from others for (2).

Thank you for the feedback. I'm now in the process of splitting this patch in a way that each patch makes sense on its own. I anticipate there will be 5 patches I'll create over the next few days:

  1. Fix to the parser.
  2. Semantics checks for REQUIRES constructs appearing after device constructs / atomic operations without mem_order.
  3. Storing REQUIRES information in top-level symbols (prerequisite for the following patches).
  4. Rewrite pass to set atomic_default_mem_order as the mem_order for atomic operations without it set.
  5. Module support: Output into .mod files, updates to semantic checks and top-level symbols to extract/store REQUIRES information from USE statements.

I'll mark this patch as abandoned after those are created and the dependencies for child patches of this one are updated.

skatrak abandoned this revision.Aug 17 2023, 8:02 AM

Patch split into: D157710, D157722, D157983, D158096, D158168.