[PATCH] D108904: [flang][OpenMP] Added semantic checks for sections and simd constructs

Nimish Mishra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 29 22:18:45 PDT 2021


NimishMishra created this revision.
NimishMishra added a reviewer: kiranktp.
NimishMishra created this object with edit policy "Administrators".
NimishMishra added projects: LLVM, Flang, OpenMP.
Herald added subscribers: jdoerfert, guansong, yaxunl.
Herald added a reviewer: sscalpone.
NimishMishra requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1.

According to OpenMP 5.0 spec document, the following semantic restrictions have been dealt with in this patch.

1. [sections] **Orphaned section directives are prohibited. That is, the section directives must appear within the sections construct and must not be encountered elsewhere in the sections region.**

  Semantic checks for the following are not necessary, since use of orphaned section construct (i.e. without an enclosing sections directive) throws parser errors and control flow never reaches the semantic checking phase.

Added a test case for the same in //llvm-project/flang/test/Parser/omp-sections01.f90//

2. [simd] **Must be a structured block / A program that branches in or out of a function with declare simd is non conforming**

Uses the already existing branching out of OpenMP structured block logic as well as changes introduced in point 3 below to semantically validate the restriction. Test case added to //llvm-project/flang/test/Semantics/omp-simd01.f90 //

3. [sections] **Must be a structured block**

Added test case as //llvm-project/flang/test/Semantics/omp-sections02.f90// and made changes to branching logic in //llvm-project/flang/lib/Semantics/check-directive-structure.h // as follows:

- //NoBranchingEnforce// is used within a //parser::Walk// called from //CheckNoBranching// (in //check-directive-structure.h// itself). //CheckNoBranching// is invoked from a lot of places, but of our interest in this particular context is  //void OmpStructureChecker::Enter(const parser::OpenMPSectionsConstruct &x)// (defined within //llvm-project/flang/lib/Semantics/check-omp-structure.cpp//)



- **[addition]** //NoBranchingEnforce// lacked tracking context earlier (precisely once control flow entered a OpenMP directive, constructs were no longer being recorded on the //ConstructStack//). Relevant //Pre //and //Post// functions added for the same



- **[addition]** A //EmitBranchOutError// on encountering a //CALL// in a structured block



- **[changes]** Although //NoBranchingEnforce// was handling labelled //EXIT//s and //CYCLE//s well, there were no semantic checks for unlabelled //CYCLE//s and //EXIT//s. Support added for them as well. For unlabeled cycles and exits, there's a need to efficiently differentiate the //ConstructNode// added to the stack **before** the concerned OpenMP directive was encountered and the nodes added **after **the directive was encountered. The same is done through a simple private unsigned counter within //NoBranchingEnforce// itself

- **[addition]** Addition of //EmitUnlabelledBranchOutError// is due to lack of an error message that gave proper context to the programmer. Existing error messages are either named error messages (which aren't valid for unlabeled cycles and exits) or a simple **CYCLE/EXIT statement not allowed within SECTIONS construct** which is more generic than the reality.




Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108904

Files:
  flang/lib/Semantics/check-directive-structure.h
  flang/test/Parser/omp-sections01.f90
  flang/test/Semantics/omp-sections02.f90
  flang/test/Semantics/omp-simd01.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108904.369368.patch
Type: text/x-patch
Size: 12447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210830/b49f7f87/attachment.bin>


More information about the llvm-commits mailing list