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.
33 SourceRange Range;
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:
98 return child_range(&AssociatedStmt, &AssociatedStmt + 1);
100 }
101
103 return const_cast<OpenACCAssociatedStmtConstruct *>(this)->children();
104 }
105};
106/// This class represents a compute construct, representing a 'Kind' of
107/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
108/// 'structured block', defined as:
109///
110/// in C or C++, an executable statement, possibly compound, with a single
111/// entry at the top and a single exit at the bottom
112///
113/// At the moment there is no real motivation to have a different AST node for
114/// those three, as they are semantically identical, and have only minor
115/// differences in the permitted list of clauses, which can be differentiated by
116/// the 'Kind'.
119 public llvm::TrailingObjects<OpenACCComputeConstruct,
120 const OpenACCClause *> {
121 friend class ASTStmtWriter;
122 friend class ASTStmtReader;
123 friend class ASTContext;
124 OpenACCComputeConstruct(unsigned NumClauses)
125 : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
128 /*AssociatedStmt=*/nullptr) {
129 // We cannot send the TrailingObjects storage to the base class (which holds
130 // a reference to the data) until it is constructed, so we have to set it
131 // separately here.
132 std::uninitialized_value_construct(
133 getTrailingObjects<const OpenACCClause *>(),
134 getTrailingObjects<const OpenACCClause *>() + NumClauses);
135 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
136 NumClauses));
137 }
138
140 SourceLocation End,
142 Stmt *StructuredBlock)
143 : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
144 End, StructuredBlock) {
145 assert((K == OpenACCDirectiveKind::Parallel ||
148 "Only parallel, serial, and kernels constructs should be "
149 "represented by this type");
150
151 // Initialize the trailing storage.
152 std::uninitialized_copy(Clauses.begin(), Clauses.end(),
153 getTrailingObjects<const OpenACCClause *>());
154
155 setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
156 Clauses.size()));
157 }
158
159 void setStructuredBlock(Stmt *S) { setAssociatedStmt(S); }
160
161public:
162 static bool classof(const Stmt *T) {
163 return T->getStmtClass() == OpenACCComputeConstructClass;
164 }
165
167 unsigned NumClauses);
171 Stmt *StructuredBlock);
172
174 const Stmt *getStructuredBlock() const {
175 return const_cast<OpenACCComputeConstruct *>(this)->getStructuredBlock();
176 }
177};
178} // namespace clang
179#endif // LLVM_CLANG_AST_STMTOPENACC_H
Defines some OpenACC-specific enums and functions.
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:102
const Stmt * getAssociatedStmt() const
Definition: StmtOpenACC.h:90
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Definition: StmtOpenACC.h:120
static OpenACCComputeConstruct * CreateEmpty(const ASTContext &C, unsigned NumClauses)
Definition: StmtOpenACC.cpp:18
static bool classof(const Stmt *T)
Definition: StmtOpenACC.h:162
const Stmt * getStructuredBlock() const
Definition: StmtOpenACC.h:174
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:1449
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1452
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1453
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
const FunctionProtoType * T