xref: /llvm-project/clang/lib/AST/StmtOpenACC.cpp (revision db81e8c42e121e62a00587b12d2b972dfcfb98c0)
1f6557783SErich Keane //===--- StmtOpenACC.cpp - Classes for OpenACC Constructs -----------------===//
2f6557783SErich Keane //
3f6557783SErich Keane // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4f6557783SErich Keane // See https://llvm.org/LICENSE.txt for license information.
5f6557783SErich Keane // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f6557783SErich Keane //
7f6557783SErich Keane //===----------------------------------------------------------------------===//
8f6557783SErich Keane //
913bb726bSerichkeane // This file implements the subclasses of Stmt class declared in StmtOpenACC.h
10f6557783SErich Keane //
11f6557783SErich Keane //===----------------------------------------------------------------------===//
12f6557783SErich Keane 
13f6557783SErich Keane #include "clang/AST/StmtOpenACC.h"
14f6557783SErich Keane #include "clang/AST/ASTContext.h"
1542f4e505SErich Keane #include "clang/AST/StmtCXX.h"
16f6557783SErich Keane using namespace clang;
17f6557783SErich Keane 
18f6557783SErich Keane OpenACCComputeConstruct *
1930f6eafaSErich Keane OpenACCComputeConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
2030f6eafaSErich Keane   void *Mem = C.Allocate(
2130f6eafaSErich Keane       OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>(
2230f6eafaSErich Keane           NumClauses));
2330f6eafaSErich Keane   auto *Inst = new (Mem) OpenACCComputeConstruct(NumClauses);
24f6557783SErich Keane   return Inst;
25f6557783SErich Keane }
26f6557783SErich Keane 
27193e9007Serichkeane OpenACCComputeConstruct *OpenACCComputeConstruct::Create(
28193e9007Serichkeane     const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc,
29193e9007Serichkeane     SourceLocation DirLoc, SourceLocation EndLoc,
30e4d57d6aSerichkeane     ArrayRef<const OpenACCClause *> Clauses, Stmt *StructuredBlock) {
3130f6eafaSErich Keane   void *Mem = C.Allocate(
3230f6eafaSErich Keane       OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>(
3330f6eafaSErich Keane           Clauses.size()));
34193e9007Serichkeane   auto *Inst = new (Mem) OpenACCComputeConstruct(K, BeginLoc, DirLoc, EndLoc,
35193e9007Serichkeane                                                  Clauses, StructuredBlock);
3642f4e505SErich Keane   return Inst;
3742f4e505SErich Keane }
3842f4e505SErich Keane 
3942f4e505SErich Keane OpenACCLoopConstruct::OpenACCLoopConstruct(unsigned NumClauses)
4042f4e505SErich Keane     : OpenACCAssociatedStmtConstruct(
4142f4e505SErich Keane           OpenACCLoopConstructClass, OpenACCDirectiveKind::Loop,
4242f4e505SErich Keane           SourceLocation{}, SourceLocation{}, SourceLocation{},
4342f4e505SErich Keane           /*AssociatedStmt=*/nullptr) {
4442f4e505SErich Keane   std::uninitialized_value_construct(
4542f4e505SErich Keane       getTrailingObjects<const OpenACCClause *>(),
4642f4e505SErich Keane       getTrailingObjects<const OpenACCClause *>() + NumClauses);
4742f4e505SErich Keane   setClauseList(
4842f4e505SErich Keane       MutableArrayRef(getTrailingObjects<const OpenACCClause *>(), NumClauses));
4942f4e505SErich Keane }
5042f4e505SErich Keane 
5142f4e505SErich Keane OpenACCLoopConstruct::OpenACCLoopConstruct(
52e4d57d6aSerichkeane     OpenACCDirectiveKind ParentKind, SourceLocation Start,
53e4d57d6aSerichkeane     SourceLocation DirLoc, SourceLocation End,
5442f4e505SErich Keane     ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop)
5542f4e505SErich Keane     : OpenACCAssociatedStmtConstruct(OpenACCLoopConstructClass,
5642f4e505SErich Keane                                      OpenACCDirectiveKind::Loop, Start, DirLoc,
57e4d57d6aSerichkeane                                      End, Loop),
58e4d57d6aSerichkeane       ParentComputeConstructKind(ParentKind) {
5942f4e505SErich Keane   // accept 'nullptr' for the loop. This is diagnosed somewhere, but this gives
6042f4e505SErich Keane   // us some level of AST fidelity in the error case.
6142f4e505SErich Keane   assert((Loop == nullptr || isa<ForStmt, CXXForRangeStmt>(Loop)) &&
6242f4e505SErich Keane          "Associated Loop not a for loop?");
6342f4e505SErich Keane   // Initialize the trailing storage.
6442f4e505SErich Keane   std::uninitialized_copy(Clauses.begin(), Clauses.end(),
6542f4e505SErich Keane                           getTrailingObjects<const OpenACCClause *>());
6642f4e505SErich Keane 
6742f4e505SErich Keane   setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
6842f4e505SErich Keane                                 Clauses.size()));
6942f4e505SErich Keane }
7042f4e505SErich Keane 
7142f4e505SErich Keane OpenACCLoopConstruct *OpenACCLoopConstruct::CreateEmpty(const ASTContext &C,
7242f4e505SErich Keane                                                         unsigned NumClauses) {
7342f4e505SErich Keane   void *Mem =
7442f4e505SErich Keane       C.Allocate(OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>(
7542f4e505SErich Keane           NumClauses));
7642f4e505SErich Keane   auto *Inst = new (Mem) OpenACCLoopConstruct(NumClauses);
7742f4e505SErich Keane   return Inst;
7842f4e505SErich Keane }
7942f4e505SErich Keane 
80e4d57d6aSerichkeane OpenACCLoopConstruct *OpenACCLoopConstruct::Create(
81e4d57d6aSerichkeane     const ASTContext &C, OpenACCDirectiveKind ParentKind,
82e4d57d6aSerichkeane     SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc,
83e4d57d6aSerichkeane     ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop) {
8442f4e505SErich Keane   void *Mem =
8542f4e505SErich Keane       C.Allocate(OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>(
8642f4e505SErich Keane           Clauses.size()));
87e4d57d6aSerichkeane   auto *Inst = new (Mem)
88e4d57d6aSerichkeane       OpenACCLoopConstruct(ParentKind, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
89f6557783SErich Keane   return Inst;
90f6557783SErich Keane }
9139351f8eSerichkeane 
9239351f8eSerichkeane OpenACCCombinedConstruct *
9339351f8eSerichkeane OpenACCCombinedConstruct::CreateEmpty(const ASTContext &C,
9439351f8eSerichkeane                                       unsigned NumClauses) {
9539351f8eSerichkeane   void *Mem = C.Allocate(
9639351f8eSerichkeane       OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>(
9739351f8eSerichkeane           NumClauses));
9839351f8eSerichkeane   auto *Inst = new (Mem) OpenACCCombinedConstruct(NumClauses);
9939351f8eSerichkeane   return Inst;
10039351f8eSerichkeane }
10139351f8eSerichkeane 
10239351f8eSerichkeane OpenACCCombinedConstruct *OpenACCCombinedConstruct::Create(
10339351f8eSerichkeane     const ASTContext &C, OpenACCDirectiveKind DK, SourceLocation BeginLoc,
10439351f8eSerichkeane     SourceLocation DirLoc, SourceLocation EndLoc,
10539351f8eSerichkeane     ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop) {
10639351f8eSerichkeane   void *Mem = C.Allocate(
10739351f8eSerichkeane       OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>(
10839351f8eSerichkeane           Clauses.size()));
10939351f8eSerichkeane   auto *Inst = new (Mem)
11039351f8eSerichkeane       OpenACCCombinedConstruct(DK, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
11139351f8eSerichkeane   return Inst;
11239351f8eSerichkeane }
113010d0115Serichkeane 
114010d0115Serichkeane OpenACCDataConstruct *OpenACCDataConstruct::CreateEmpty(const ASTContext &C,
115010d0115Serichkeane                                                         unsigned NumClauses) {
116010d0115Serichkeane   void *Mem =
117010d0115Serichkeane       C.Allocate(OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
118010d0115Serichkeane           NumClauses));
119010d0115Serichkeane   auto *Inst = new (Mem) OpenACCDataConstruct(NumClauses);
120010d0115Serichkeane   return Inst;
121010d0115Serichkeane }
122010d0115Serichkeane 
123010d0115Serichkeane OpenACCDataConstruct *
124010d0115Serichkeane OpenACCDataConstruct::Create(const ASTContext &C, SourceLocation Start,
125010d0115Serichkeane                              SourceLocation DirectiveLoc, SourceLocation End,
126010d0115Serichkeane                              ArrayRef<const OpenACCClause *> Clauses,
127010d0115Serichkeane                              Stmt *StructuredBlock) {
128010d0115Serichkeane   void *Mem =
129010d0115Serichkeane       C.Allocate(OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
130010d0115Serichkeane           Clauses.size()));
131010d0115Serichkeane   auto *Inst = new (Mem)
132010d0115Serichkeane       OpenACCDataConstruct(Start, DirectiveLoc, End, Clauses, StructuredBlock);
133010d0115Serichkeane   return Inst;
134010d0115Serichkeane }
135010d0115Serichkeane 
136010d0115Serichkeane OpenACCEnterDataConstruct *
137010d0115Serichkeane OpenACCEnterDataConstruct::CreateEmpty(const ASTContext &C,
138010d0115Serichkeane                                        unsigned NumClauses) {
139010d0115Serichkeane   void *Mem = C.Allocate(
140010d0115Serichkeane       OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
141010d0115Serichkeane           NumClauses));
142010d0115Serichkeane   auto *Inst = new (Mem) OpenACCEnterDataConstruct(NumClauses);
143010d0115Serichkeane   return Inst;
144010d0115Serichkeane }
145010d0115Serichkeane 
146010d0115Serichkeane OpenACCEnterDataConstruct *OpenACCEnterDataConstruct::Create(
147010d0115Serichkeane     const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
148010d0115Serichkeane     SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) {
149010d0115Serichkeane   void *Mem = C.Allocate(
150010d0115Serichkeane       OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
151010d0115Serichkeane           Clauses.size()));
152010d0115Serichkeane   auto *Inst =
153010d0115Serichkeane       new (Mem) OpenACCEnterDataConstruct(Start, DirectiveLoc, End, Clauses);
154010d0115Serichkeane   return Inst;
155010d0115Serichkeane }
156010d0115Serichkeane 
157010d0115Serichkeane OpenACCExitDataConstruct *
158010d0115Serichkeane OpenACCExitDataConstruct::CreateEmpty(const ASTContext &C,
159010d0115Serichkeane                                       unsigned NumClauses) {
160010d0115Serichkeane   void *Mem = C.Allocate(
161010d0115Serichkeane       OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
162010d0115Serichkeane           NumClauses));
163010d0115Serichkeane   auto *Inst = new (Mem) OpenACCExitDataConstruct(NumClauses);
164010d0115Serichkeane   return Inst;
165010d0115Serichkeane }
166010d0115Serichkeane 
167010d0115Serichkeane OpenACCExitDataConstruct *OpenACCExitDataConstruct::Create(
168010d0115Serichkeane     const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
169010d0115Serichkeane     SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) {
170010d0115Serichkeane   void *Mem = C.Allocate(
171010d0115Serichkeane       OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
172010d0115Serichkeane           Clauses.size()));
173010d0115Serichkeane   auto *Inst =
174010d0115Serichkeane       new (Mem) OpenACCExitDataConstruct(Start, DirectiveLoc, End, Clauses);
175010d0115Serichkeane   return Inst;
176010d0115Serichkeane }
177010d0115Serichkeane 
178010d0115Serichkeane OpenACCHostDataConstruct *
179010d0115Serichkeane OpenACCHostDataConstruct::CreateEmpty(const ASTContext &C,
180010d0115Serichkeane                                       unsigned NumClauses) {
181010d0115Serichkeane   void *Mem = C.Allocate(
182010d0115Serichkeane       OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
183010d0115Serichkeane           NumClauses));
184010d0115Serichkeane   auto *Inst = new (Mem) OpenACCHostDataConstruct(NumClauses);
185010d0115Serichkeane   return Inst;
186010d0115Serichkeane }
187010d0115Serichkeane 
188010d0115Serichkeane OpenACCHostDataConstruct *OpenACCHostDataConstruct::Create(
189010d0115Serichkeane     const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
190010d0115Serichkeane     SourceLocation End, ArrayRef<const OpenACCClause *> Clauses,
191010d0115Serichkeane     Stmt *StructuredBlock) {
192010d0115Serichkeane   void *Mem = C.Allocate(
193010d0115Serichkeane       OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
194010d0115Serichkeane           Clauses.size()));
195010d0115Serichkeane   auto *Inst = new (Mem) OpenACCHostDataConstruct(Start, DirectiveLoc, End,
196010d0115Serichkeane                                                   Clauses, StructuredBlock);
197010d0115Serichkeane   return Inst;
198010d0115Serichkeane }
199e34cc7c9Serichkeane 
200e34cc7c9Serichkeane OpenACCWaitConstruct *OpenACCWaitConstruct::CreateEmpty(const ASTContext &C,
201e34cc7c9Serichkeane                                                         unsigned NumExprs,
202e34cc7c9Serichkeane                                                         unsigned NumClauses) {
203e34cc7c9Serichkeane   void *Mem = C.Allocate(
204e34cc7c9Serichkeane       OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(
205e34cc7c9Serichkeane           NumExprs, NumClauses));
206e34cc7c9Serichkeane 
207e34cc7c9Serichkeane   auto *Inst = new (Mem) OpenACCWaitConstruct(NumExprs, NumClauses);
208e34cc7c9Serichkeane   return Inst;
209e34cc7c9Serichkeane }
210e34cc7c9Serichkeane 
211e34cc7c9Serichkeane OpenACCWaitConstruct *OpenACCWaitConstruct::Create(
212e34cc7c9Serichkeane     const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
213e34cc7c9Serichkeane     SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc,
214e34cc7c9Serichkeane     ArrayRef<Expr *> QueueIdExprs, SourceLocation RParenLoc, SourceLocation End,
215e34cc7c9Serichkeane     ArrayRef<const OpenACCClause *> Clauses) {
216e34cc7c9Serichkeane 
217e34cc7c9Serichkeane   assert(llvm::all_of(QueueIdExprs, [](Expr *E) { return E != nullptr; }));
218e34cc7c9Serichkeane 
219e34cc7c9Serichkeane   void *Mem = C.Allocate(
220e34cc7c9Serichkeane       OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(
221e34cc7c9Serichkeane           QueueIdExprs.size() + 1, Clauses.size()));
222e34cc7c9Serichkeane 
223e34cc7c9Serichkeane   auto *Inst = new (Mem)
224e34cc7c9Serichkeane       OpenACCWaitConstruct(Start, DirectiveLoc, LParenLoc, DevNumExpr,
225e34cc7c9Serichkeane                            QueuesLoc, QueueIdExprs, RParenLoc, End, Clauses);
226e34cc7c9Serichkeane   return Inst;
227e34cc7c9Serichkeane }
2284bbdb018Serichkeane OpenACCInitConstruct *OpenACCInitConstruct::CreateEmpty(const ASTContext &C,
2294bbdb018Serichkeane                                                         unsigned NumClauses) {
2304bbdb018Serichkeane   void *Mem =
2314bbdb018Serichkeane       C.Allocate(OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>(
2324bbdb018Serichkeane           NumClauses));
2334bbdb018Serichkeane   auto *Inst = new (Mem) OpenACCInitConstruct(NumClauses);
2344bbdb018Serichkeane   return Inst;
2354bbdb018Serichkeane }
2364bbdb018Serichkeane 
2374bbdb018Serichkeane OpenACCInitConstruct *
2384bbdb018Serichkeane OpenACCInitConstruct::Create(const ASTContext &C, SourceLocation Start,
2394bbdb018Serichkeane                              SourceLocation DirectiveLoc, SourceLocation End,
2404bbdb018Serichkeane                              ArrayRef<const OpenACCClause *> Clauses) {
2414bbdb018Serichkeane   void *Mem =
2424bbdb018Serichkeane       C.Allocate(OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>(
2434bbdb018Serichkeane           Clauses.size()));
2444bbdb018Serichkeane   auto *Inst =
2454bbdb018Serichkeane       new (Mem) OpenACCInitConstruct(Start, DirectiveLoc, End, Clauses);
2464bbdb018Serichkeane   return Inst;
2474bbdb018Serichkeane }
2484bbdb018Serichkeane OpenACCShutdownConstruct *
2494bbdb018Serichkeane OpenACCShutdownConstruct::CreateEmpty(const ASTContext &C,
2504bbdb018Serichkeane                                       unsigned NumClauses) {
2514bbdb018Serichkeane   void *Mem = C.Allocate(
2524bbdb018Serichkeane       OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>(
2534bbdb018Serichkeane           NumClauses));
2544bbdb018Serichkeane   auto *Inst = new (Mem) OpenACCShutdownConstruct(NumClauses);
2554bbdb018Serichkeane   return Inst;
2564bbdb018Serichkeane }
2574bbdb018Serichkeane 
2584bbdb018Serichkeane OpenACCShutdownConstruct *OpenACCShutdownConstruct::Create(
2594bbdb018Serichkeane     const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
2604bbdb018Serichkeane     SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) {
2614bbdb018Serichkeane   void *Mem = C.Allocate(
2624bbdb018Serichkeane       OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>(
2634bbdb018Serichkeane           Clauses.size()));
2644bbdb018Serichkeane   auto *Inst =
2654bbdb018Serichkeane       new (Mem) OpenACCShutdownConstruct(Start, DirectiveLoc, End, Clauses);
2664bbdb018Serichkeane   return Inst;
2674bbdb018Serichkeane }
26821c785d7Serichkeane 
26921c785d7Serichkeane OpenACCSetConstruct *OpenACCSetConstruct::CreateEmpty(const ASTContext &C,
27021c785d7Serichkeane                                                       unsigned NumClauses) {
27121c785d7Serichkeane   void *Mem = C.Allocate(
27221c785d7Serichkeane       OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(NumClauses));
27321c785d7Serichkeane   auto *Inst = new (Mem) OpenACCSetConstruct(NumClauses);
27421c785d7Serichkeane   return Inst;
27521c785d7Serichkeane }
27621c785d7Serichkeane 
27721c785d7Serichkeane OpenACCSetConstruct *
27821c785d7Serichkeane OpenACCSetConstruct::Create(const ASTContext &C, SourceLocation Start,
27921c785d7Serichkeane                             SourceLocation DirectiveLoc, SourceLocation End,
28021c785d7Serichkeane                             ArrayRef<const OpenACCClause *> Clauses) {
28121c785d7Serichkeane   void *Mem =
28221c785d7Serichkeane       C.Allocate(OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(
28321c785d7Serichkeane           Clauses.size()));
28421c785d7Serichkeane   auto *Inst = new (Mem) OpenACCSetConstruct(Start, DirectiveLoc, End, Clauses);
28521c785d7Serichkeane   return Inst;
28621c785d7Serichkeane }
287*db81e8c4Serichkeane 
288*db81e8c4Serichkeane OpenACCUpdateConstruct *
289*db81e8c4Serichkeane OpenACCUpdateConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
290*db81e8c4Serichkeane   void *Mem = C.Allocate(
291*db81e8c4Serichkeane       OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
292*db81e8c4Serichkeane           NumClauses));
293*db81e8c4Serichkeane   auto *Inst = new (Mem) OpenACCUpdateConstruct(NumClauses);
294*db81e8c4Serichkeane   return Inst;
295*db81e8c4Serichkeane }
296*db81e8c4Serichkeane 
297*db81e8c4Serichkeane OpenACCUpdateConstruct *
298*db81e8c4Serichkeane OpenACCUpdateConstruct::Create(const ASTContext &C, SourceLocation Start,
299*db81e8c4Serichkeane                                SourceLocation DirectiveLoc, SourceLocation End,
300*db81e8c4Serichkeane                                ArrayRef<const OpenACCClause *> Clauses) {
301*db81e8c4Serichkeane   void *Mem = C.Allocate(
302*db81e8c4Serichkeane       OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
303*db81e8c4Serichkeane           Clauses.size()));
304*db81e8c4Serichkeane   auto *Inst =
305*db81e8c4Serichkeane       new (Mem) OpenACCUpdateConstruct(Start, DirectiveLoc, End, Clauses);
306*db81e8c4Serichkeane   return Inst;
307*db81e8c4Serichkeane }
308