clang 19.0.0git
OpenACCClause.h
Go to the documentation of this file.
1//===- OpenACCClause.h - Classes for OpenACC clauses ------------*- 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//
9// \file
10// This file defines OpenACC AST classes for clauses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
15#define LLVM_CLANG_AST_OPENACCCLAUSE_H
19
20namespace clang {
21/// This is the base type for all OpenACC Clauses.
24 SourceRange Location;
25
26protected:
28 SourceLocation EndLoc)
29 : Kind(K), Location(BeginLoc, EndLoc) {}
30
31public:
32 OpenACCClauseKind getClauseKind() const { return Kind; }
33 SourceLocation getBeginLoc() const { return Location.getBegin(); }
34 SourceLocation getEndLoc() const { return Location.getEnd(); }
35
36 static bool classof(const OpenACCClause *) { return true; }
37
40 using child_range = llvm::iterator_range<child_iterator>;
41 using const_child_range = llvm::iterator_range<const_child_iterator>;
42
45 auto Children = const_cast<OpenACCClause *>(this)->children();
46 return const_child_range(Children.begin(), Children.end());
47 }
48
49 virtual ~OpenACCClause() = default;
50};
51
52/// Represents a clause that has a list of parameters.
54 /// Location of the '('.
55 SourceLocation LParenLoc;
56
57protected:
59 SourceLocation LParenLoc, SourceLocation EndLoc)
60 : OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
61
62public:
63 SourceLocation getLParenLoc() const { return LParenLoc; }
64
67 }
70 }
71};
72
73/// A 'default' clause, has the optional 'none' or 'present' argument.
75 friend class ASTReaderStmt;
76 friend class ASTWriterStmt;
77
78 OpenACCDefaultClauseKind DefaultClauseKind;
79
80protected:
82 SourceLocation LParenLoc, SourceLocation EndLoc)
84 EndLoc),
85 DefaultClauseKind(K) {
86 assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
87 DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
88 "Invalid Clause Kind");
89 }
90
91public:
93 return DefaultClauseKind;
94 }
95
98 SourceLocation BeginLoc,
99 SourceLocation LParenLoc,
100 SourceLocation EndLoc);
101};
102
103/// Represents one of the handful of classes that has an optional/required
104/// 'condition' expression as an argument.
106 Expr *ConditionExpr = nullptr;
107
108protected:
110 SourceLocation LParenLoc, Expr *ConditionExpr,
111 SourceLocation EndLoc)
112 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
113 ConditionExpr(ConditionExpr) {}
114
115public:
116 bool hasConditionExpr() const { return ConditionExpr; }
117 const Expr *getConditionExpr() const { return ConditionExpr; }
118 Expr *getConditionExpr() { return ConditionExpr; }
119
121 if (ConditionExpr)
122 return child_range(reinterpret_cast<Stmt **>(&ConditionExpr),
123 reinterpret_cast<Stmt **>(&ConditionExpr + 1));
125 }
126
128 if (ConditionExpr)
129 return const_child_range(
130 reinterpret_cast<Stmt *const *>(&ConditionExpr),
131 reinterpret_cast<Stmt *const *>(&ConditionExpr + 1));
133 }
134};
135
136/// An 'if' clause, which has a required condition expression.
138protected:
140 Expr *ConditionExpr, SourceLocation EndLoc);
141
142public:
143 static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
144 SourceLocation LParenLoc, Expr *ConditionExpr,
145 SourceLocation EndLoc);
146};
147
148/// A 'self' clause, which has an optional condition expression.
151 Expr *ConditionExpr, SourceLocation EndLoc);
152
153public:
154 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
155 SourceLocation LParenLoc,
156 Expr *ConditionExpr, SourceLocation EndLoc);
157};
158
159/// Represents a clause that has one or more IntExprs. It does not own the
160/// IntExprs, but provides 'children' and other accessors.
163
164protected:
166 SourceLocation LParenLoc, SourceLocation EndLoc)
167 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}
168
169 /// Used only for initialization, the leaf class can initialize this to
170 /// trailing storage.
172 assert(IntExprs.empty() && "Cannot change IntExprs list");
173 IntExprs = NewIntExprs;
174 }
175
176 /// Gets the entire list of integer expressions, but leave it to the
177 /// individual clauses to expose this how they'd like.
178 llvm::ArrayRef<Expr *> getIntExprs() const { return IntExprs; }
179
180public:
182 return child_range(reinterpret_cast<Stmt **>(IntExprs.begin()),
183 reinterpret_cast<Stmt **>(IntExprs.end()));
184 }
185
187 child_range Children =
188 const_cast<OpenACCClauseWithIntExprs *>(this)->children();
189 return const_child_range(Children.begin(), Children.end());
190 }
191};
192
195 public llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {
196
198 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
200 LParenLoc, EndLoc) {
201 std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
202 getTrailingObjects<Expr *>());
203 setIntExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
204 }
205
206public:
207 static OpenACCNumGangsClause *
208 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
209 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
210
213 }
214
217 }
218};
219
220/// Represents one of a handful of clauses that have a single integer
221/// expression.
223 Expr *IntExpr;
224
225protected:
227 SourceLocation LParenLoc, Expr *IntExpr,
228 SourceLocation EndLoc)
229 : OpenACCClauseWithIntExprs(K, BeginLoc, LParenLoc, EndLoc),
230 IntExpr(IntExpr) {
231 setIntExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
232 }
233
234public:
235 bool hasIntExpr() const { return !getIntExprs().empty(); }
236 const Expr *getIntExpr() const {
237 return hasIntExpr() ? getIntExprs()[0] : nullptr;
238 }
239
240 Expr *getIntExpr() { return hasIntExpr() ? getIntExprs()[0] : nullptr; };
241};
242
245 Expr *IntExpr, SourceLocation EndLoc);
246
247public:
249 SourceLocation BeginLoc,
250 SourceLocation LParenLoc,
251 Expr *IntExpr, SourceLocation EndLoc);
252};
253
256 Expr *IntExpr, SourceLocation EndLoc);
257
258public:
260 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
261 Expr *IntExpr, SourceLocation EndLoc);
262};
263
264template <class Impl> class OpenACCClauseVisitor {
265 Impl &getDerived() { return static_cast<Impl &>(*this); }
266
267public:
269 for (const OpenACCClause *Clause : List)
270 Visit(Clause);
271 }
272
273 void Visit(const OpenACCClause *C) {
274 if (!C)
275 return;
276
277 switch (C->getClauseKind()) {
278#define VISIT_CLAUSE(CLAUSE_NAME) \
279 case OpenACCClauseKind::CLAUSE_NAME: \
280 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
281 return;
282#include "clang/Basic/OpenACCClauses.def"
283
284 default:
285 llvm_unreachable("Clause visitor not yet implemented");
286 }
287 llvm_unreachable("Invalid Clause kind");
288 }
289
290#define VISIT_CLAUSE(CLAUSE_NAME) \
291 void Visit##CLAUSE_NAME##Clause( \
292 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
293 return getDerived().Visit##CLAUSE_NAME##Clause(Clause); \
294 }
295
296#include "clang/Basic/OpenACCClauses.def"
297};
298
300 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
301 raw_ostream &OS;
302
303public:
305 for (const OpenACCClause *Clause : List) {
306 Visit(Clause);
307
308 if (Clause != List.back())
309 OS << ' ';
310 }
311 }
312 OpenACCClausePrinter(raw_ostream &OS) : OS(OS) {}
313
314#define VISIT_CLAUSE(CLAUSE_NAME) \
315 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
316#include "clang/Basic/OpenACCClauses.def"
317};
318
319} // namespace clang
320
321#endif // LLVM_CLANG_AST_OPENACCCLAUSE_H
Defines the clang::ASTContext interface.
Defines some OpenACC-specific enums and functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
This represents one expression.
Definition: Expr.h:110
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
OpenACCClausePrinter(raw_ostream &OS)
void Visit(const OpenACCClause *C)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
Represents one of the handful of classes that has an optional/required 'condition' expression as an a...
const Expr * getConditionExpr() const
OpenACCClauseWithCondition(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
const_child_range children() const
Represents a clause that has one or more IntExprs.
void setIntExprs(MutableArrayRef< Expr * > NewIntExprs)
Used only for initialization, the leaf class can initialize this to trailing storage.
const_child_range children() const
llvm::ArrayRef< Expr * > getIntExprs() const
Gets the entire list of integer expressions, but leave it to the individual clauses to expose this ho...
OpenACCClauseWithIntExprs(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Represents a clause that has a list of parameters.
Definition: OpenACCClause.h:53
SourceLocation getLParenLoc() const
Definition: OpenACCClause.h:63
OpenACCClauseWithParams(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:58
const_child_range children() const
Definition: OpenACCClause.h:68
Represents one of a handful of clauses that have a single integer expression.
OpenACCClauseWithSingleIntExpr(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:22
child_range children()
StmtIterator child_iterator
Definition: OpenACCClause.h:38
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:32
SourceLocation getBeginLoc() const
Definition: OpenACCClause.h:33
const_child_range children() const
Definition: OpenACCClause.h:44
static bool classof(const OpenACCClause *)
Definition: OpenACCClause.h:36
llvm::iterator_range< child_iterator > child_range
Definition: OpenACCClause.h:40
ConstStmtIterator const_child_iterator
Definition: OpenACCClause.h:39
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:27
virtual ~OpenACCClause()=default
llvm::iterator_range< const_child_iterator > const_child_range
Definition: OpenACCClause.h:41
SourceLocation getEndLoc() const
Definition: OpenACCClause.h:34
A 'default' clause, has the optional 'none' or 'present' argument.
Definition: OpenACCClause.h:74
OpenACCDefaultClause(OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:81
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: OpenACCClause.h:92
An 'if' clause, which has a required condition expression.
llvm::ArrayRef< Expr * > getIntExprs() const
llvm::ArrayRef< Expr * > getIntExprs()
A 'self' clause, which has an optional condition expression.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:164
@ Create
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ NumGangs
'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs.
OpenACCDefaultClauseKind
Definition: OpenACCKinds.h:419