14#ifndef FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
15#define FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
17#include "check-directive-structure.h"
18#include "flang/Common/enum-set.h"
19#include "flang/Parser/parse-tree.h"
20#include "flang/Semantics/openmp-directive-sets.h"
21#include "flang/Semantics/semantics.h"
22#include "llvm/Frontend/OpenMP/OMPConstants.h"
27#define GEN_FLANG_DIRECTIVE_CLAUSE_SETS
28#include "llvm/Frontend/OpenMP/OMP.inc"
33 Clause::OMPC_private, Clause::OMPC_firstprivate, Clause::OMPC_lastprivate};
42 Directive::OMPD_do_simd,
43 Directive::OMPD_sections,
44 Directive::OMPD_single,
45 Directive::OMPD_workshare,
50namespace Fortran::semantics {
54using SymbolSourceMap = std::multimap<const Symbol *, parser::CharBlock>;
56using DirectivesClauseTriple = std::multimap<llvm::omp::Directive,
57 std::pair<llvm::omp::Directive, const OmpClauseSet>>;
61 parser::OmpClause, llvm::omp::Clause_enumSize> {
68#define GEN_FLANG_DIRECTIVE_CLAUSE_MAP
69#include
"llvm/Frontend/OpenMP/OMP.inc"
72 using llvmOmpClause =
const llvm::omp::Clause;
147#define GEN_FLANG_CLAUSE_CHECK_ENTER
148#include "llvm/Frontend/OpenMP/OMP.inc"
150 void Leave(
const parser::OmpClause::Fail &);
155 bool CheckAllowedClause(llvmOmpClause clause);
156 bool IsVariableListItem(
const Symbol &sym);
157 bool IsExtendedListItem(
const Symbol &sym);
158 bool IsCommonBlock(
const Symbol &sym);
160 void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
162 const std::string &clauseName);
163 void CheckMultListItems();
164 void CheckStructureComponent(
165 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
166 bool HasInvalidWorksharingNesting(
169 void HasInvalidTeamsNesting(
174 void CheckAllowedMapTypes(
const parser::OmpMapType::Value &,
175 const std::list<parser::OmpMapType::Value> &);
176 llvm::StringRef getClauseName(llvm::omp::Clause clause)
override;
177 llvm::StringRef getDirectiveName(llvm::omp::Directive directive)
override;
180 typename LessTy,
typename RangeTy,
181 typename IterTy =
decltype(std::declval<RangeTy>().begin())>
182 std::optional<IterTy> FindDuplicate(RangeTy &&);
185 std::optional<parser::CharBlock> GetObjectSource(
188 void CheckDependArraySection(
193 const parser::OmpObjectList &objList, llvm::StringRef clause =
"");
194 void CheckThreadprivateOrDeclareTargetVar(
195 const parser::OmpObjectList &objList);
196 void CheckSymbolNames(
198 void CheckIntentInPointer(SymbolSourceMap &,
const llvm::omp::Clause);
199 void CheckProcedurePointer(SymbolSourceMap &,
const llvm::omp::Clause);
200 void GetSymbolsInObjectList(
const parser::OmpObjectList &, SymbolSourceMap &);
201 void CheckDefinableObjects(SymbolSourceMap &,
const llvm::omp::Clause);
202 void CheckCopyingPolymorphicAllocatable(
203 SymbolSourceMap &,
const llvm::omp::Clause);
204 void CheckPrivateSymbolsInOuterCxt(
205 SymbolSourceMap &, DirectivesClauseTriple &,
const llvm::omp::Clause);
208 void CheckIsLoopIvPartOfClause(
209 llvmOmpClause clause,
const parser::OmpObjectList &ompObjectList);
210 bool CheckTargetBlockOnlyTeams(
const parser::Block &);
218 template <
typename T,
typename D>
bool IsOperatorValid(
const T &,
const D &);
219 void CheckAtomicMemoryOrderClause(
230 void CheckTargetUpdate();
231 void CheckDependenceType(
const parser::OmpDependenceType::Value &x);
232 void CheckTaskDependenceType(
const parser::OmpTaskDependenceType::Value &x);
233 void CheckCancellationNest(
236 void CheckReductionObjects(
237 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
240 void CheckReductionObjectTypes(
const parser::OmpObjectList &objects,
244 void ChecksOnOrderedAsBlock();
247 void ChecksOnOrderedAsStandalone();
248 void CheckOrderedDependClause(std::optional<std::int64_t> orderedValue);
249 void CheckReductionArraySection(
250 const parser::OmpObjectList &ompObjectList, llvm::omp::Clause clauseId);
252 const parser::Name &name,
const llvm::omp::Clause clause);
253 void CheckSharedBindingInOuterContext(
254 const parser::OmpObjectList &ompObjectList);
259 const parser::OmpObjectList &ompObjectList);
260 void CheckPredefinedAllocatorRestriction(
262 bool isPredefinedAllocator{
false};
264 void CheckAllowedRequiresClause(llvmOmpClause clause);
265 bool deviceConstructFound_{
false};
269 void EnterDirectiveNest(
const int index) { directiveNest_[index]++; }
270 void ExitDirectiveNest(
const int index) { directiveNest_[index]--; }
271 int GetDirectiveNest(
const int index) {
return directiveNest_[index]; }
272 template <
typename D>
void CheckHintClause(D *, D *);
274 inline void ErrIfLHSAndRHSSymbolsMatch(
276 inline void ErrIfNonScalarAssignmentStmt(
278 enum directiveNestType :
int {
280 TargetBlockOnlyTeams,
283 LastType = DeclarativeNest,
285 int directiveNest_[LastType + 1] = {0};
287 SymbolSourceMap deferredNonVariables_;
291 std::vector<LoopConstruct> loopStack_;
292 bool isFailClause{
false};
297template <
typename LessTy,
typename RangeTy,
typename IterTy>
298std::optional<IterTy> OmpStructureChecker::FindDuplicate(RangeTy &&range) {
302 std::set<IterTy, LessTy> uniq;
303 for (
auto it{range.begin()}, end{range.end()}; it != end; ++it) {
304 if (!uniq.insert(it).second) {
Definition: enum-set.h:28
Definition: indirection.h:31
Definition: char-block.h:28
Definition: check-directive-structure.h:181
Definition: check-omp-structure.h:61
Definition: semantics.h:67
Definition: parse-tree.h:1911
Definition: parse-tree.h:2016
Definition: parse-tree.h:1818
Definition: parse-tree.h:2338
Definition: parse-tree.h:1700
Definition: parse-tree.h:580
Definition: parse-tree.h:4604
Definition: parse-tree.h:4568
Definition: parse-tree.h:4620
Definition: parse-tree.h:4577
Definition: parse-tree.h:4595
Definition: parse-tree.h:4586
Definition: parse-tree.h:4629
Definition: parse-tree.h:4729
Definition: parse-tree.h:4333
Definition: parse-tree.h:4317
Definition: parse-tree.h:4418
Definition: parse-tree.h:4413
Definition: parse-tree.h:4033
Definition: parse-tree.h:4735
Definition: parse-tree.h:4723
Definition: parse-tree.h:4376
Definition: parse-tree.h:4352
Definition: parse-tree.h:4106
Definition: parse-tree.h:3463
Definition: parse-tree.h:4539
Definition: parse-tree.h:4641
Definition: parse-tree.h:4741
Definition: parse-tree.h:4669
Definition: parse-tree.h:4662
Definition: parse-tree.h:4756
Definition: parse-tree.h:4515
Definition: parse-tree.h:4488
Definition: parse-tree.h:4494
Definition: parse-tree.h:4441
Definition: parse-tree.h:4467
Definition: parse-tree.h:4428
Definition: parse-tree.h:4682
Definition: parse-tree.h:4524
Definition: parse-tree.h:4689
Definition: parse-tree.h:4747
Definition: parse-tree.h:4474
Definition: parse-tree.h:4397
Definition: parse-tree.h:4702
Definition: parse-tree.h:4481
Definition: parse-tree.h:1865
Definition: parse-tree.h:3681
Definition: parse-tree.h:3753
Definition: parse-tree.h:3843
Definition: parse-tree.h:3852