clang 20.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 /// The location of the directive name.
35 SourceLocation DirectiveLoc;
36
37 /// The list of clauses. This is stored here as an ArrayRef, as this is the
38 /// most convienient place to access the list, however the list itself should
39 /// be stored in leaf nodes, likely in trailing-storage.
41
42protected:
44 SourceLocation Start, SourceLocation DirectiveLoc,
46 : Stmt(SC), Kind(K), Range(Start, End), DirectiveLoc(DirectiveLoc) {}
47
48 // Used only for initialization, the leaf class can initialize this to
49 // trailing storage.
51 assert(Clauses.empty() && "Cannot change clause list");
52 Clauses = NewClauses;
53 }
54
55public:
57
58 static bool classof(const Stmt *S) {
59 return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
60 S->getStmtClass() <= lastOpenACCConstructStmtConstant;
61 }
62
63 SourceLocation getBeginLoc() const { return Range.getBegin(); }
64 SourceLocation getEndLoc() const { return Range.getEnd(); }
65 SourceLocation getDirectiveLoc() const { return DirectiveLoc; }
66 ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
67
70 }
71
73 return const_cast<OpenACCConstructStmt *>(this)->children();
74 }
75};
76
77/// This is a base class for any OpenACC statement-level constructs that have an
78/// associated statement. This class is not intended to be instantiated, but is
79/// a convenient place to hold the associated statement.
81 friend class ASTStmtWriter;
82 friend class ASTStmtReader;
83 template <typename Derived> friend class RecursiveASTVisitor;
84 Stmt *AssociatedStmt = nullptr;
85
86protected:
88 SourceLocation Start,
89 SourceLocation DirectiveLoc,
90 SourceLocation End, Stmt *AssocStmt)
91 : OpenACCConstructStmt(SC, K, Start, DirectiveLoc, End),
92 AssociatedStmt(AssocStmt) {}
93
94 void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
95 Stmt *getAssociatedStmt() { return AssociatedStmt; }
96 const Stmt *getAssociatedStmt() const {
97 return const_cast<OpenACCAssociatedStmtConstruct *>(this)
99 }
100
101public:
102 static bool classof(const Stmt *T) {
103 return false;
104 }
105
107 if (getAssociatedStmt())
108 return child_range(&AssociatedStmt, &AssociatedStmt + 1);
110 }
111
113 return const_cast<OpenACCAssociatedStmtConstruct *>(this)->children();
114 }
115};
116
117/// This class represents a compute construct, representing a 'Kind' of
118/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
119/// 'structured block', defined as:
120///
121/// in C or C++, an executable statement, possibly compound, with a single
122/// entry at the top and a single exit at the bottom
123///
124/// At the moment there is no real motivation to have a different AST node for
125/// those three, as they are semantically identical, and have only minor
126/// differences in the permitted list of clauses, which can be differentiated by
127/// the 'Kind'.
130 private llvm::TrailingObjects<OpenACCComputeConstruct,
131 const OpenACCClause *> {
132 friend class ASTStmtWriter;
133 friend class ASTStmtReader;
134 friend class ASTContext;
135 friend TrailingObjects;
136 OpenACCComputeConstruct(unsigned NumClauses)
138 OpenACCComputeConstructClass,