FLANG
check-acc-structure.h
1//===-- lib/Semantics/check-acc-structure.h ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7// OpenACC 3.3 structure validity check list
8// 1. invalid clauses on directive
9// 2. invalid repeated clauses on directive
10// 3. invalid nesting of regions
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
15#define FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
16
17#include "check-directive-structure.h"
18#include "flang/Common/enum-set.h"
19#include "flang/Parser/parse-tree.h"
20#include "flang/Semantics/semantics.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/Frontend/OpenACC/ACC.h.inc"
23
24using AccDirectiveSet = Fortran::common::EnumSet<llvm::acc::Directive,
25 llvm::acc::Directive_enumSize>;
26
27using AccClauseSet =
29
30#define GEN_FLANG_DIRECTIVE_CLAUSE_SETS
31#include "llvm/Frontend/OpenACC/ACC.inc"
32
33namespace Fortran::semantics {
34
35class AccStructureChecker
36 : public DirectiveStructureChecker<llvm::acc::Directive, llvm::acc::Clause,
37 parser::AccClause, llvm::acc::Clause_enumSize> {
38public:
39 AccStructureChecker(SemanticsContext &context)
40 : DirectiveStructureChecker(context,
41#define GEN_FLANG_DIRECTIVE_CLAUSE_MAP
42#include "llvm/Frontend/OpenACC/ACC.inc"
43 ) {
44 }
45
46 // Construct and directives
47 void Enter(const parser::OpenACCBlockConstruct &);
48 void Leave(const parser::OpenACCBlockConstruct &);
49 void Enter(const parser::OpenACCCombinedConstruct &);
50 void Leave(const parser::OpenACCCombinedConstruct &);
51 void Enter(const parser::OpenACCLoopConstruct &);
52 void Leave(const parser::OpenACCLoopConstruct &);
53 void Enter(const parser::OpenACCRoutineConstruct &);
54 void Leave(const parser::OpenACCRoutineConstruct &);
55 void Enter(const parser::OpenACCStandaloneConstruct &);
56 void Leave(const parser::OpenACCStandaloneConstruct &);
59 void Enter(const parser::OpenACCWaitConstruct &);
60 void Leave(const parser::OpenACCWaitConstruct &);
61 void Enter(const parser::OpenACCAtomicConstruct &);
62 void Leave(const parser::OpenACCAtomicConstruct &);
63 void Enter(const parser::OpenACCCacheConstruct &);
64 void Leave(const parser::OpenACCCacheConstruct &);
65 void Enter(const parser::AccAtomicUpdate &);
66 void Enter(const parser::AccAtomicCapture &);
67 void Enter(const parser::AccAtomicWrite &);
68 void Enter(const parser::AccAtomicRead &);
69 void Enter(const parser::OpenACCEndConstruct &);
70
71 // Clauses
72 void Leave(const parser::AccClauseList &);
73 void Enter(const parser::AccClause &);
74
75 void Enter(const parser::Module &);
76 void Enter(const parser::SubroutineSubprogram &);
77 void Enter(const parser::FunctionSubprogram &);
78 void Enter(const parser::SeparateModuleSubprogram &);
79 void Enter(const parser::DoConstruct &);
80 void Leave(const parser::DoConstruct &);
81 void Enter(const parser::CallStmt &);
82
83#define GEN_FLANG_CLAUSE_CHECK_ENTER
84#include "llvm/Frontend/OpenACC/ACC.inc"
85
86private:
87 void CheckAtomicStmt(
88 const parser::AssignmentStmt &assign, const std::string &construct);
89 void CheckAtomicUpdateStmt(const parser::AssignmentStmt &assign,
90 const SomeExpr &updateVar, const SomeExpr *captureVar);
91 void CheckAtomicCaptureStmt(const parser::AssignmentStmt &assign,
92 const SomeExpr *updateVar, const SomeExpr &captureVar);
93 void CheckAtomicWriteStmt(const parser::AssignmentStmt &assign,
94 const SomeExpr &updateVar, const SomeExpr *captureVar);
95 void CheckAtomicUpdateVariable(
96 const parser::Variable &updateVar, const parser::Variable &captureVar);
97 void CheckAtomicCaptureVariable(
98 const parser::Variable &captureVar, const parser::Variable &updateVar);
99
100 bool CheckAllowedModifier(llvm::acc::Clause clause);
101 bool IsComputeConstruct(llvm::acc::Directive directive) const;
102 bool IsLoopConstruct(llvm::acc::Directive directive) const;
103 std::optional<llvm::acc::Directive> getParentComputeConstruct() const;
104 bool IsInsideComputeConstruct() const;
105 bool IsInsideKernelsConstruct() const;
106 void CheckNotInComputeConstruct();
107 std::optional<std::int64_t> getGangDimensionSize(
108 DirectiveContext &dirContext);
109 void CheckNotInSameOrSubLevelLoopConstruct();
110 void CheckMultipleOccurrenceInDeclare(
111 const parser::AccObjectList &, llvm::acc::Clause);
112 void CheckMultipleOccurrenceInDeclare(
113 const parser::AccObjectListWithModifier &, llvm::acc::Clause);
114 llvm::StringRef getClauseName(llvm::acc::Clause clause) override;
115 llvm::StringRef getDirectiveName(llvm::acc::Directive directive) override;
116
117 llvm::SmallDenseMap<Symbol *, llvm::acc::Clause> declareSymbols;
118 unsigned loopNestLevel = 0;
119};
120
121} // namespace Fortran::semantics
122
123#endif // FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
Definition enum-set.h:28
Definition semantics.h:67
Definition parse-tree.h:5679
Definition parse-tree.h:5655
Definition parse-tree.h:5671
Definition parse-tree.h:5663
Definition parse-tree.h:5611
Definition parse-tree.h:5596
Definition parse-tree.h:5527
Definition parse-tree.h:2003
Definition parse-tree.h:3264
Definition parse-tree.h:2323
Definition parse-tree.h:3284
Definition parse-tree.h:2962
Definition parse-tree.h:5686
Definition parse-tree.h:5693
Definition parse-tree.h:5622
Definition parse-tree.h:5715
Definition parse-tree.h:5743
Definition parse-tree.h:5734
Definition parse-tree.h:5616
Definition parse-tree.h:5628
Definition parse-tree.h:3310
Definition parse-tree.h:3294
Definition parse-tree.h:1853