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
82#define GEN_FLANG_CLAUSE_CHECK_ENTER
83#include "llvm/Frontend/OpenACC/ACC.inc"
84
85private:
86 void CheckAtomicStmt(
87 const parser::AssignmentStmt &assign, const std::string &construct);
88 void CheckAtomicUpdateStmt(const parser::AssignmentStmt &assign,
89 const SomeExpr &updateVar, const SomeExpr *captureVar);
90 void CheckAtomicCaptureStmt(const parser::AssignmentStmt &assign,
91 const SomeExpr *updateVar, const SomeExpr &captureVar);
92 void CheckAtomicWriteStmt(const parser::AssignmentStmt &assign,
93 const SomeExpr &updateVar, const SomeExpr *captureVar);
94 void CheckAtomicUpdateVariable(
95 const parser::Variable &updateVar, const parser::Variable &captureVar);
96 void CheckAtomicCaptureVariable(
97 const parser::Variable &captureVar, const parser::Variable &updateVar);
98
99 bool CheckAllowedModifier(llvm::acc::Clause clause);
100 bool IsComputeConstruct(llvm::acc::Directive directive) const;
101 bool IsLoopConstruct(llvm::acc::Directive directive) const;
102 std::optional<llvm::acc::Directive> getParentComputeConstruct() const;
103 bool IsInsideComputeConstruct() const;
104 bool IsInsideKernelsConstruct() const;
105 void CheckNotInComputeConstruct();
106 std::optional<std::int64_t> getGangDimensionSize(
107 DirectiveContext &dirContext);
108 void CheckNotInSameOrSubLevelLoopConstruct();
109 void CheckMultipleOccurrenceInDeclare(
110 const parser::AccObjectList &, llvm::acc::Clause);
111 void CheckMultipleOccurrenceInDeclare(
112 const parser::AccObjectListWithModifier &, llvm::acc::Clause);
113 llvm::StringRef getClauseName(llvm::acc::Clause clause) override;
114 llvm::StringRef getDirectiveName(llvm::acc::Directive directive) override;
115
116 llvm::SmallDenseMap<Symbol *, llvm::acc::Clause> declareSymbols;
117 unsigned loopNestLevel = 0;
118};
119
120} // namespace Fortran::semantics
121
122#endif // FORTRAN_SEMANTICS_CHECK_ACC_STRUCTURE_H_
Definition enum-set.h:28
Definition semantics.h:67
Definition parse-tree.h:5417
Definition parse-tree.h:5393
Definition parse-tree.h:5409
Definition parse-tree.h:5401
Definition parse-tree.h:5349
Definition parse-tree.h:5334
Definition parse-tree.h:5265
Definition parse-tree.h:2017
Definition parse-tree.h:2339
Definition parse-tree.h:3299
Definition parse-tree.h:2972
Definition parse-tree.h:5424
Definition parse-tree.h:5431
Definition parse-tree.h:5360
Definition parse-tree.h:5453
Definition parse-tree.h:5481
Definition parse-tree.h:5472
Definition parse-tree.h:5354
Definition parse-tree.h:5366
Definition parse-tree.h:3325
Definition parse-tree.h:3309
Definition parse-tree.h:1866