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;
149#define GEN_FLANG_CLAUSE_CHECK_ENTER
150#include "llvm/Frontend/OpenMP/OMP.inc"
152 void Leave(
const parser::OmpClause::Fail &);
157 bool CheckAllowedClause(llvmOmpClause clause);
158 bool IsVariableListItem(
const Symbol &sym);
159 bool IsExtendedListItem(
const Symbol &sym);
160 bool IsCommonBlock(
const Symbol &sym);
162 void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
164 const std::string &clauseName);
165 void CheckMultListItems();
166 void CheckStructureComponent(
167 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
168 bool HasInvalidWorksharingNesting(
171 void HasInvalidTeamsNesting(
176 void CheckAllowedMapTypes(
const parser::OmpMapType::Value &,
177 const std::list<parser::OmpMapType::Value> &);
178 llvm::StringRef getClauseName(llvm::omp::Clause clause)
override;
179 llvm::StringRef getDirectiveName(llvm::omp::Directive directive)
override;
182 typename LessTy,
typename RangeTy,
183 typename IterTy =
decltype(std::declval<RangeTy>().begin())>
184 std::optional<IterTy> FindDuplicate(RangeTy &&);
187 std::optional<parser::CharBlock> GetObjectSource(
190 void CheckDependArraySection(
195 const parser::OmpObjectList &objList, llvm::StringRef clause =
"");
196 void CheckThreadprivateOrDeclareTargetVar(
197 const parser::OmpObjectList &objList);
198 void CheckSymbolNames(
200 void CheckIntentInPointer(SymbolSourceMap &,
const llvm::omp::Clause);
201 void CheckProcedurePointer(SymbolSourceMap &,
const llvm::omp::Clause);
202 void CheckCrayPointee(
const parser::OmpObjectList &objectList,
203 llvm::StringRef clause,
bool suggestToUseCrayPointer =
true);
204 void GetSymbolsInObjectList(
const parser::OmpObjectList &, SymbolSourceMap &);
205 void CheckDefinableObjects(SymbolSourceMap &,
const llvm::omp::Clause);
206 void CheckCopyingPolymorphicAllocatable(
207 SymbolSourceMap &,
const llvm::omp::Clause);
208 void CheckPrivateSymbolsInOuterCxt(
209 SymbolSourceMap &, DirectivesClauseTriple &,
const llvm::omp::Clause);
212 void CheckIsLoopIvPartOfClause(
213 llvmOmpClause clause,
const parser::OmpObjectList &ompObjectList);
214 bool CheckTargetBlockOnlyTeams(
const parser::Block &);
222 template <
typename T,
typename D>
bool IsOperatorValid(
const T &,
const D &);
223 void CheckAtomicMemoryOrderClause(
234 void CheckTargetUpdate();
235 void CheckDependenceType(
const parser::OmpDependenceType::Value &x);
236 void CheckTaskDependenceType(
const parser::OmpTaskDependenceType::Value &x);
237 void CheckCancellationNest(
240 void CheckReductionObjects(
241 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
244 void CheckReductionObjectTypes(
const parser::OmpObjectList &objects,
248 void ChecksOnOrderedAsBlock();
251 void ChecksOnOrderedAsStandalone();
252 void CheckOrderedDependClause(std::optional<std::int64_t> orderedValue);
253 void CheckReductionArraySection(
254 const parser::OmpObjectList &ompObjectList, llvm::omp::Clause clauseId);
256 const parser::Name &name,
const llvm::omp::Clause clause);
257 void CheckSharedBindingInOuterContext(
258 const parser::OmpObjectList &ompObjectList);
263 const parser::OmpObjectList &ompObjectList);
264 void CheckPredefinedAllocatorRestriction(
266 bool isPredefinedAllocator{
false};
268 void CheckAllowedRequiresClause(llvmOmpClause clause);
269 bool deviceConstructFound_{
false};
273 void EnterDirectiveNest(
const int index) { directiveNest_[index]++; }
274 void ExitDirectiveNest(
const int index) { directiveNest_[index]--; }
275 int GetDirectiveNest(
const int index) {
return directiveNest_[index]; }
276 template <
typename D>
void CheckHintClause(D *, D *);
278 inline void ErrIfLHSAndRHSSymbolsMatch(
280 inline void ErrIfNonScalarAssignmentStmt(
282 enum directiveNestType :
int {
284 TargetBlockOnlyTeams,
287 LastType = DeclarativeNest,
289 int directiveNest_[LastType + 1] = {0};
291 SymbolSourceMap deferredNonVariables_;
295 std::vector<LoopConstruct> loopStack_;
296 bool isFailClause{
false};
301template <
typename LessTy,
typename RangeTy,
typename IterTy>
302std::optional<IterTy> OmpStructureChecker::FindDuplicate(RangeTy &&range) {
306 std::set<IterTy, LessTy> uniq;
307 for (
auto it{range.begin()}, end{range.end()}; it != end; ++it) {
308 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:4754
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:4760
Definition: parse-tree.h:4748
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:4766
Definition: parse-tree.h:4669
Definition: parse-tree.h:4662
Definition: parse-tree.h:4781
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:4705
Definition: parse-tree.h:4524
Definition: parse-tree.h:4714
Definition: parse-tree.h:4772
Definition: parse-tree.h:4474
Definition: parse-tree.h:4397
Definition: parse-tree.h:4727
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