clang 20.0.0git
StmtOpenACC.h
Go to the documentation of this file.
1//===- StmtOpenACC.h - Classes for OpenACC directives ----------*- 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//===----------------------------------------------------------------------===//
8/// \file
9/// This file defines OpenACC AST classes for statement-level contructs.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_STMTOPENACC_H
14#define LLVM_CLANG_AST_STMTOPENACC_H
15
17#include "clang/AST/Stmt.h"
20#include <memory>
21
22namespace clang {
23/// This is the base class for an OpenACC statement-level construct, other
24/// construct types are expected to inherit from this.
25class OpenACCConstructStmt : public Stmt {
26 friend class ASTStmtWriter;
27 friend class ASTStmtReader;
28 /// The directive kind. Each implementation of this interface should handle
29 /// specific kinds.
31 /// The location of the directive statement, from the '#' to the last token of
32 /// the directive.
34 /// The location of the directive name.
35 SourceLocation DirectiveLoc;
36
37 /// The list of clauses. This is stored here as an ArrayRef, as this is the
38 /// most convienient place to access the list, however the list itself should
39 /// be stored in leaf nodes, likely in trailing-storage.
41
42protected:
44 SourceLocation Start, SourceLocation DirectiveLoc,
46 : Stmt(SC), Kind(K), Range(Start, End), DirectiveLoc(DirectiveLoc) {}
47
48 // Used only for initialization, the leaf class can initialize this to
49 // trailing storage.
51 assert(Clauses.empty() && "Cannot change clause list");
52 Clauses = NewClauses;
53 }
54
55public:
57
58 static bool classof(const Stmt *S) {
59 return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
60 S->getStmtClass() <= lastOpenACCConstructStmtConstant;
61 }
62
63 SourceLocation getBeginLoc() const { return Range.getBegin(); }
64 SourceLocation getEndLoc() const { return Range.getEnd(); }
65 SourceLocation getDirectiveLoc() const { return DirectiveLoc; }
66 ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
67
70 }
71
73 return const_cast<OpenACCConstructStmt *>(this)->children();
74 }
75};
76
77/// This is a base class for any OpenACC statement-level constructs that have an
78/// associated statement. This class is not intended to be instantiated, but is
79/// a convenient place to hold the associated statement.
81 friend class ASTStmtWriter;
82 friend class ASTStmtReader;
83 template <typename Derived> friend class RecursiveASTVisitor;
84 Stmt *AssociatedStmt = nullptr;
85
86protected:
88 SourceLocation Start,
89 SourceLocation DirectiveLoc,
90 SourceLocation End, Stmt *AssocStmt)
91 : OpenACCConstructStmt(SC, K, Start, DirectiveLoc, End),
92 AssociatedStmt(AssocStmt) {}
93
94 void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
95 Stmt *getAssociatedStmt() { return AssociatedStmt; }
96 const Stmt *getAssociatedStmt() const {
97 return const_cast<OpenACCAssociatedStmtConstruct *>(this)
99 }
100
101public:
102 static bool classof(const Stmt *T) {
103 return false;
104 }
105
107 if (getAssociatedStmt())
108 return child_range(&AssociatedStmt, &AssociatedStmt + 1);
110 }
111
113 return const_cast<OpenACCAssociatedStmtConstruct *>(this)->children();
114 }
115};
116
117class OpenACCLoopConstruct;
118/// This class represents a compute construct, representing a 'Kind' of
119/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
120/// 'structured block', defined as:
121///
122/// in C or C++, an executable statement, possibly compound, with a single
123/// entry at the top and a single exit at the bottom
124///
125/// At the moment there is no real motivation to have a different AST node for
126/// those three, as they are semantically identical, and have only minor
127/// differences in the permitted list of clauses, which can be differentiated by
128/// the 'Kind'.
131 public llvm::TrailingObjects<OpenACCComputeConstruct,
132 const OpenACCClause *> {
133 friend class ASTStmtWriter;
134 friend class ASTStmtReader;
135 friend class ASTContext;
136 OpenACCComputeConstruct(unsigned NumClauses)
138 OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
140 /*AssociatedStmt=*/nullptr) {
141 // We cannot send the TrailingObjects storage to the base class (which holds
142 // a reference to the data) until it is constructed, so we have to set it
143 // separately here.
144 std::uninitialized_value_construct(
145 getTrailingObjects<const OpenACCClause *>(),
146 getTrailingObjects<const OpenACCClause *>() + NumClauses);
147 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
148 NumClauses));
149 }
150
152 SourceLocation DirectiveLoc, SourceLocation End,
154 Stmt *StructuredBlock)
155 : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
156 DirectiveLoc, End, StructuredBlock) {
158 "Only parallel, serial, and kernels constructs should be "
159 "represented by this type");
160
161 // Initialize the trailing storage.
162 std::uninitialized_copy(Clauses.begin(), Clauses.end(),
163 getTrailingObjects<const OpenACCClause *>());
164
165 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
166 Clauses.size()));
167 }
168
169 void setStructuredBlock(Stmt *S) { setAssociatedStmt(S); }
170 // Serialization helper function that searches the structured block for 'loop'
171 // constructs that should be associated with this, and sets their parent
172 // compute construct to this one. This isn't necessary normally, since we have
173 // the ability to record the state during parsing.
174 void findAndSetChildLoops();
175
176public:
177 static bool classof(const Stmt *T) {
178 return T->getStmtClass() == OpenACCComputeConstructClass;
179 }
180
182 unsigned NumClauses);
185 SourceLocation DirectiveLoc, SourceLocation EndLoc,
186 ArrayRef<const OpenACCClause *> Clauses, Stmt *StructuredBlock,
187 ArrayRef<OpenACCLoopConstruct *> AssociatedLoopConstructs);
188
190 const Stmt *getStructuredBlock() const {
191 return const_cast<OpenACCComputeConstruct *>(this)->getStructuredBlock();
192 }
193};
194/// This class represents a 'loop' construct. The 'loop' construct applies to a
195/// 'for' loop (or range-for loop), and is optionally associated with a Compute
196/// Construct.
199 public llvm::TrailingObjects<OpenACCLoopConstruct,
200 const OpenACCClause *> {
201 // The compute construct this loop is associated with, or nullptr if this is
202 // an orphaned loop construct, or if it hasn't been set yet. Because we
203 // construct the directives at the end of their statement, the 'parent'
204 // construct is not yet available at the time of construction, so this needs
205 // to be set 'later'.
206 const OpenACCComputeConstruct *ParentComputeConstruct = nullptr;
207
208 friend class ASTStmtWriter;
209 friend class ASTStmtReader;
210 friend class ASTContext;
212
213 OpenACCLoopConstruct(unsigned NumClauses);
214
216 SourceLocation End,
218 void setLoop(Stmt *Loop);
219
220 void setParentComputeConstruct(OpenACCComputeConstruct *CC) {
221 assert(!ParentComputeConstruct && "Parent already set?");
222 ParentComputeConstruct = CC;
223 }
224
225public:
226 static bool classof(const Stmt *T) {
227 return T->getStmtClass() == OpenACCLoopConstructClass;
228 }
229
231 unsigned NumClauses);
232
233 static OpenACCLoopConstruct *
234 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation DirLoc,
236 Stmt *Loop);
237
239 const Stmt *getLoop() const {
240 return const_cast<OpenACCLoopConstruct *>(this)->getLoop();
241 }
242
243 /// OpenACC 3.3 2.9:
244 /// An orphaned loop construct is a loop construct that is not lexically
245 /// enclosed within a compute construct. The parent compute construct of a
246 /// loop construct is the nearest compute construct that lexically contains
247 /// the loop construct.
249 return ParentComputeConstruct == nullptr;
250 }
252 return ParentComputeConstruct;
253 }
254};
255} // namespace clang
256#endif // LLVM_CLANG_AST_STMTOPENACC_H
enum clang::sema::@1651::IndirectLocalPathEntry::EntryKind Kind
Defines some OpenACC-specific enums and functions.
SourceRange Range
Definition: SemaObjC.cpp:757
Defines the clang::SourceLocation class and associated facilities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:186
This is a base class for any OpenACC statement-level constructs that have an associated statement.
Definition: StmtOpenACC.h:80
const_child_range children() const
Definition: StmtOpenACC.h:112
const Stmt * getAssociatedStmt() const
Definition: StmtOpenACC.h:96
OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, Stmt *AssocStmt)
Definition: StmtOpenACC.h:87
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:102
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Definition: StmtOpenACC.h:132
static OpenACCComputeConstruct * CreateEmpty(const ASTContext &C, unsigned NumClauses)
Definition: StmtOpenACC.cpp:20
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:177
const Stmt * getStructuredBlock() const
Definition: StmtOpenACC.h:190
This is the base class for an OpenACC statement-level construct, other construct types are expected t...
Definition: StmtOpenACC.h:25
SourceLocation getEndLoc() const
Definition: StmtOpenACC.h:64
SourceLocation getBeginLoc() const
Definition: StmtOpenACC.h:63
OpenACCDirectiveKind getDirectiveKind() const
Definition: StmtOpenACC.h:56
void setClauseList(MutableArrayRef< const OpenACCClause * > NewClauses)
Definition: StmtOpenACC.h:50
ArrayRef< const OpenACCClause * > clauses() const
Definition: StmtOpenACC.h:66
const_child_range children() const
Definition: StmtOpenACC.h:72
SourceLocation getDirectiveLoc() const
Definition: StmtOpenACC.h:65
static bool classof(const Stmt *S)
Definition: StmtOpenACC.h:58
OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End)
Definition: StmtOpenACC.h:43
This class represents a 'loop' construct.
Definition: StmtOpenACC.h:200
static OpenACCLoopConstruct * CreateEmpty(const ASTContext &C, unsigned NumClauses)
const Stmt * getLoop() const
Definition: StmtOpenACC.h:239
bool isOrphanedLoopConstruct() const
OpenACC 3.3 2.9: An orphaned loop construct is a loop construct that is not lexically enclosed within...
Definition: StmtOpenACC.h:248
const OpenACCComputeConstruct * getParentComputeConstruct() const
Definition: StmtOpenACC.h:251
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:226
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
StmtClass
Definition: Stmt.h:86
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition: Stmt.h:1444
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1447
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1448
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K)
Definition: OpenACCKinds.h:149
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
const FunctionProtoType * T