clang 19.0.0git
OpenACCClause.cpp
Go to the documentation of this file.
1//===---- OpenACCClause.cpp - Classes for OpenACC Clauses ----------------===//
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// This file implements the subclasses of the OpenACCClause class declared in
10// OpenACCClause.h
11//
12//===----------------------------------------------------------------------===//
13
16#include "clang/AST/Expr.h"
17
18using namespace clang;
19
22 SourceLocation BeginLoc,
23 SourceLocation LParenLoc,
24 SourceLocation EndLoc) {
25 void *Mem =
26 C.Allocate(sizeof(OpenACCDefaultClause), alignof(OpenACCDefaultClause));
27
28 return new (Mem) OpenACCDefaultClause(K, BeginLoc, LParenLoc, EndLoc);
29}
30
32 SourceLocation BeginLoc,
33 SourceLocation LParenLoc,
34 Expr *ConditionExpr,
35 SourceLocation EndLoc) {
36 void *Mem = C.Allocate(sizeof(OpenACCIfClause), alignof(OpenACCIfClause));
37 return new (Mem) OpenACCIfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
38}
39
41 SourceLocation LParenLoc, Expr *ConditionExpr,
42 SourceLocation EndLoc)
43 : OpenACCClauseWithCondition(OpenACCClauseKind::If, BeginLoc, LParenLoc,
44 ConditionExpr, EndLoc) {
45 assert(ConditionExpr && "if clause requires condition expr");
46 assert((ConditionExpr->isInstantiationDependent() ||
47 ConditionExpr->getType()->isScalarType()) &&
48 "Condition expression type not scalar/dependent");
49}
50
52 SourceLocation BeginLoc,
53 SourceLocation LParenLoc,
54 Expr *ConditionExpr,
55 SourceLocation EndLoc) {
56 void *Mem = C.Allocate(sizeof(OpenACCIfClause), alignof(OpenACCIfClause));
57 return new (Mem)
58 OpenACCSelfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
59}
60
61OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
62 SourceLocation LParenLoc,
63 Expr *ConditionExpr, SourceLocation EndLoc)
65 ConditionExpr, EndLoc) {
66 assert((!ConditionExpr || ConditionExpr->isInstantiationDependent() ||
67 ConditionExpr->getType()->isScalarType()) &&
68 "Condition expression type not scalar/dependent");
69}
70
72 switch (getClauseKind()) {
73 default:
74 assert(false && "Clause children function not implemented");
75 break;
76#define VISIT_CLAUSE(CLAUSE_NAME) \
77 case OpenACCClauseKind::CLAUSE_NAME: \
78 return cast<OpenACC##CLAUSE_NAME##Clause>(this)->children();
79
80#include "clang/Basic/OpenACCClauses.def"
81 }
83}
84
85OpenACCNumWorkersClause::OpenACCNumWorkersClause(SourceLocation BeginLoc,
86 SourceLocation LParenLoc,
87 Expr *IntExpr,
88 SourceLocation EndLoc)
90 LParenLoc, IntExpr, EndLoc) {
91 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
92 IntExpr->getType()->isIntegerType()) &&
93 "Condition expression type not scalar/dependent");
94}
95
98 SourceLocation LParenLoc, Expr *IntExpr,
99 SourceLocation EndLoc) {
100 void *Mem = C.Allocate(sizeof(OpenACCNumWorkersClause),
101 alignof(OpenACCNumWorkersClause));
102 return new (Mem)
103 OpenACCNumWorkersClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
104}
105
106OpenACCVectorLengthClause::OpenACCVectorLengthClause(SourceLocation BeginLoc,
107 SourceLocation LParenLoc,
108 Expr *IntExpr,
109 SourceLocation EndLoc)
111 LParenLoc, IntExpr, EndLoc) {
112 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
113 IntExpr->getType()->isIntegerType()) &&
114 "Condition expression type not scalar/dependent");
115}
116
119 SourceLocation LParenLoc, Expr *IntExpr,
120 SourceLocation EndLoc) {
121 void *Mem = C.Allocate(sizeof(OpenACCVectorLengthClause),
123 return new (Mem)
124 OpenACCVectorLengthClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
125}
126
128 SourceLocation BeginLoc,
129 SourceLocation LParenLoc,
130 ArrayRef<Expr *> IntExprs,
131 SourceLocation EndLoc) {
132 void *Mem = C.Allocate(
133 OpenACCNumGangsClause::totalSizeToAlloc<Expr *>(IntExprs.size()));
134 return new (Mem) OpenACCNumGangsClause(BeginLoc, LParenLoc, IntExprs, EndLoc);
135}
136
138 SourceLocation BeginLoc,
139 SourceLocation LParenLoc,
140 ArrayRef<Expr *> VarList,
141 SourceLocation EndLoc) {
142 void *Mem = C.Allocate(
143 OpenACCPrivateClause::totalSizeToAlloc<Expr *>(VarList.size()));
144 return new (Mem) OpenACCPrivateClause(BeginLoc, LParenLoc, VarList, EndLoc);
145}
146
147//===----------------------------------------------------------------------===//
148// OpenACC clauses printing methods
149//===----------------------------------------------------------------------===//
150
151void OpenACCClausePrinter::printExpr(const Expr *E) {
152 E->printPretty(OS, nullptr, Policy, 0);
153}
154
155void OpenACCClausePrinter::VisitDefaultClause(const OpenACCDefaultClause &C) {
156 OS << "default(" << C.getDefaultClauseKind() << ")";
157}
158
159void OpenACCClausePrinter::VisitIfClause(const OpenACCIfClause &C) {
160 OS << "if(";
161 printExpr(C.getConditionExpr());
162 OS << ")";
163}
164
165void OpenACCClausePrinter::VisitSelfClause(const OpenACCSelfClause &C) {
166 OS << "self";
167 if (const Expr *CondExpr = C.getConditionExpr()) {
168 OS << "(";
169 printExpr(CondExpr);
170 OS << ")";
171 }
172}
173
174void OpenACCClausePrinter::VisitNumGangsClause(const OpenACCNumGangsClause &C) {
175 OS << "num_gangs(";
176 llvm::interleaveComma(C.getIntExprs(), OS,
177 [&](const Expr *E) { printExpr(E); });
178 OS << ")";
179}
180
181void OpenACCClausePrinter::VisitNumWorkersClause(
182 const OpenACCNumWorkersClause &C) {
183 OS << "num_workers(";
184 printExpr(C.getIntExpr());
185 OS << ")";
186}
187
188void OpenACCClausePrinter::VisitVectorLengthClause(
190 OS << "vector_length(";
191 printExpr(C.getIntExpr());
192 OS << ")";
193}
194
195void OpenACCClausePrinter::VisitPrivateClause(const OpenACCPrivateClause &C) {
196 OS << "private(";
197 llvm::interleaveComma(C.getVarList(), OS,
198 [&](const Expr *E) { printExpr(E); });
199 OS << ")";
200}
Defines the clang::ASTContext interface.
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
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
QualType getType() const
Definition: Expr.h:142
Represents one of the handful of classes that has an optional/required 'condition' expression as an a...
Represents one of a handful of clauses that have a single integer expression.
child_range children()
StmtIterator child_iterator
Definition: OpenACCClause.h:38
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:32
llvm::iterator_range< child_iterator > child_range
Definition: OpenACCClause.h:40
A 'default' clause, has the optional 'none' or 'present' argument.
Definition: OpenACCClause.h:74
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
An 'if' clause, which has a required condition expression.
OpenACCIfClause(SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'self' clause, which has an optional condition expression.
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
Encodes a location in the source.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7945
bool isScalarType() const
Definition: Type.h:8004
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:164
@ VectorLength
'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', and 'kernels loop' constru...
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ NumWorkers
'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs...
OpenACCDefaultClauseKind
Definition: OpenACCKinds.h:419