clang 19.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
35 /// The list of clauses. This is stored here as an ArrayRef, as this is the
36 /// most convienient place to access the list, however the list itself should
37 /// be stored in leaf nodes, likely in trailing-storage.
39
40protected:
43 : Stmt(SC), Kind(K), Range(Start, End) {}
44
45 // Used only for initialization, the leaf class can initialize this to
46 // trailing storage.
48 assert(Clauses.empty() && "Cannot change clause list");
49 Clauses = NewClauses;
50 }
51
52public:
53 OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
54
55 static bool classof(const Stmt *S) {
56 return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
57 S->getStmtClass() <= lastOpenACCConstructStmtConstant;
58 }
59
60 SourceLocation getBeginLoc() const { return Range.getBegin(); }
61 SourceLocation getEndLoc() const { return Range.getEnd(); }
62 ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
63
66 }
67
69 return const_cast<OpenACCConstructStmt *>(this)->children();
70 }
71};
72
73/// This is a base class for any OpenACC statement-level constructs that have an
74/// associated statement. This class is not intended to be instantiated, but is
75/// a convenient place to hold the associated statement.
77 friend class ASTStmtWriter;
78 friend class ASTStmtReader;
79 template <typename Derived> friend class RecursiveASTVisitor;
80 Stmt *AssociatedStmt = nullptr;
81
82protected:
85 Stmt *AssocStmt)
86 : OpenACCConstructStmt(SC, K, Start, End), AssociatedStmt(AssocStmt) {}
87
88 void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
89 Stmt *getAssociatedStmt() { return AssociatedStmt; }
90 const Stmt *getAssociatedStmt() const {
91 return const_cast<OpenACCAssociatedStmtConstruct *>(this)
93 }
94
95public:
96 static bool classof(const Stmt *T) {
97 return false;
98 }
99
101 if (getAssociatedStmt())
102 return child_range(&AssociatedStmt, &AssociatedStmt + 1);
104 }
105
107 return const_cast<OpenACCAssociatedStmtConstruct *>(this)->children();
108 }
109};
110/// This class represents a compute construct, representing a 'Kind' of
111/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
112/// 'structured block', defined as:
113///
114/// in C or C++, an executable statement, possibly compound, with a single
115/// entry at the top and a single exit at the bottom
116///
117/// At the moment there is no real motivation to have a different AST node for
118/// those three, as they are semantically identical, and have only minor
119/// differences in the permitted list of clauses, which can be differentiated by
120/// the 'Kind'.
123 public llvm::TrailingObjects<OpenACCComputeConstruct,
124 const OpenACCClause *> {
125 friend class ASTStmtWriter;
126 friend class ASTStmtReader;
127 friend class ASTContext;
128 OpenACCComputeConstruct(unsigned NumClauses)
129 : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
132 /*AssociatedStmt=*/nullptr) {
133 // We cannot send the TrailingObjects storage to the base class (which holds
134 // a reference to the data) until it is constructed, so we have to set it
135 // separately here.
136 std::uninitialized_value_construct(
137 getTrailingObjects<const OpenACCClause *>(),
138 getTrailingObjects<const OpenACCClause *>() + NumClauses);
139 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
140 NumClauses));
141 }
142
144 SourceLocation End,
146 Stmt *StructuredBlock)
147 : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
148 End, StructuredBlock) {
150 "Only parallel, serial, and kernels constructs should be "
151 "represented by this type");
152
153 // Initialize the trailing storage.
154 std::uninitialized_copy(Clauses.begin(), Clauses.end(),
155 getTrailingObjects<const OpenACCClause *>());
156
157 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
158 Clauses.size()));
159 }
160
161 void setStructuredBlock(Stmt *S) { setAssociatedStmt(S); }
162
163public:
164 static bool classof(const Stmt *T) {
165 return T->getStmtClass() == OpenACCComputeConstructClass;
166 }
167
169 unsigned NumClauses);
173 Stmt *StructuredBlock);
174
176 const Stmt *getStructuredBlock() const {
177 return const_cast<OpenACCComputeConstruct *>(this)->getStructuredBlock();
178 }
179};
180} // namespace clang
181#endif // LLVM_CLANG_AST_STMTOPENACC_H
Defines some OpenACC-specific enums and functions.
SourceRange Range
Definition: SemaObjC.cpp:754
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:182
This is a base class for any OpenACC statement-level constructs that have an associated statement.
Definition: StmtOpenACC.h:76
OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation End, Stmt *AssocStmt)
Definition: StmtOpenACC.h:83
const_child_range children() const
Definition: StmtOpenACC.h:106
const Stmt * getAssociatedStmt() const
Definition: StmtOpenACC.h:90
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:96
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Definition: StmtOpenACC.h:124
static OpenACCComputeConstruct * CreateEmpty(const ASTContext &C, unsigned NumClauses)
Definition: StmtOpenACC.cpp:18
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:164
const Stmt * getStructuredBlock() const
Definition: StmtOpenACC.h:176
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:61
SourceLocation getBeginLoc() const
Definition: StmtOpenACC.h:60
OpenACCDirectiveKind getDirectiveKind() const
Definition: StmtOpenACC.h:53
void setClauseList(MutableArrayRef< const OpenACCClause * > NewClauses)
Definition: StmtOpenACC.h:47
ArrayRef< const OpenACCClause * > clauses() const
Definition: StmtOpenACC.h:62
const_child_range children() const
Definition: StmtOpenACC.h:68
static bool classof(const Stmt *S)
Definition: StmtOpenACC.h:55
OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation End)
Definition: StmtOpenACC.h:41
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