clang 18.0.0git
DeclOpenMP.cpp
Go to the documentation of this file.
1//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
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 implements OMPThreadPrivateDecl, OMPCapturedExprDecl
10/// classes.
11///
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclBase.h"
18#include "clang/AST/Expr.h"
19
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// OMPThreadPrivateDecl Implementation.
24//===----------------------------------------------------------------------===//
25
26void OMPThreadPrivateDecl::anchor() {}
27
29 DeclContext *DC,
32 auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33 C, DC, std::nullopt, VL.size(), L);
34 D->setVars(VL);
35 return D;
36}
37
39 unsigned ID,
40 unsigned N) {
41 return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42 C, ID, 0, N);
43}
44
45void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46 assert(VL.size() == Data->getNumChildren() &&
47 "Number of variables is not the same as the preallocated buffer");
48 llvm::copy(VL, getVars().begin());
49}
50
51//===----------------------------------------------------------------------===//
52// OMPAllocateDecl Implementation.
53//===----------------------------------------------------------------------===//
54
55void OMPAllocateDecl::anchor() { }
56
60 auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61 C, DC, CL, VL.size(), L);
62 D->setVars(VL);
63 return D;
64}
65
67 unsigned NVars,
68 unsigned NClauses) {
69 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
70 C, ID, NClauses, NVars, SourceLocation());
71}
72
73void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
74 assert(VL.size() == Data->getNumChildren() &&
75 "Number of variables is not the same as the preallocated buffer");
76 llvm::copy(VL, getVars().begin());
77}
78
79//===----------------------------------------------------------------------===//
80// OMPRequiresDecl Implementation.
81//===----------------------------------------------------------------------===//
82
83void OMPRequiresDecl::anchor() {}
84
88 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
89 L);
90}
91
93 unsigned N) {
94 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
95 C, ID, N, 0, SourceLocation());
96}
97
98//===----------------------------------------------------------------------===//
99// OMPDeclareReductionDecl Implementation.
100//===----------------------------------------------------------------------===//
101
102OMPDeclareReductionDecl::OMPDeclareReductionDecl(
103 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
104 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
105 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
106 PrevDeclInScope(PrevDeclInScope) {
107 setInitializer(nullptr, OMPDeclareReductionInitKind::Call);
108}
109
110void OMPDeclareReductionDecl::anchor() {}
111
114 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
115 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
116 T, PrevDeclInScope);
117}
118
121 return new (C, ID) OMPDeclareReductionDecl(
122 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
123 QualType(), /*PrevDeclInScope=*/nullptr);
124}
125
127 return cast_or_null<OMPDeclareReductionDecl>(
128 PrevDeclInScope.get(getASTContext().getExternalSource()));
129}
132 return cast_or_null<OMPDeclareReductionDecl>(
133 PrevDeclInScope.get(getASTContext().getExternalSource()));
134}
135
136//===----------------------------------------------------------------------===//
137// OMPDeclareMapperDecl Implementation.
138//===----------------------------------------------------------------------===//
139
140void OMPDeclareMapperDecl::anchor() {}
141
145 OMPDeclareMapperDecl *PrevDeclInScope) {
146 return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
147 C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
148}
149
151 unsigned ID,
152 unsigned N) {
153 return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
154 C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
155 DeclarationName(), /*PrevDeclInScope=*/nullptr);
156}
157
159 return cast_or_null<OMPDeclareMapperDecl>(
160 PrevDeclInScope.get(getASTContext().getExternalSource()));
161}
162
164 return cast_or_null<OMPDeclareMapperDecl>(
165 PrevDeclInScope.get(getASTContext().getExternalSource()));
166}
167
168//===----------------------------------------------------------------------===//
169// OMPCapturedExprDecl Implementation.
170//===----------------------------------------------------------------------===//
171
172void OMPCapturedExprDecl::anchor() {}
173
176 SourceLocation StartLoc) {
177 return new (C, DC) OMPCapturedExprDecl(
178 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
179}
180
182 unsigned ID) {
183 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
184 /*TInfo=*/nullptr, SourceLocation());
185}
186
188 assert(hasInit());
190}
Defines the clang::ASTContext interface.
int Id
Definition: ASTDiff.cpp:190
This file defines OpenMP nodes for declarative directives.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:440
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
The name of a declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:820
One of these records is kept for each identifier that is lexed.
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:473
static OMPAllocateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL, ArrayRef< OMPClause * > CL)
Definition: DeclOpenMP.cpp:57
static OMPAllocateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NVars, unsigned NClauses)
Definition: DeclOpenMP.cpp:66
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:383
static OMPCapturedExprDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, SourceLocation StartLoc)
Definition: DeclOpenMP.cpp:174
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclOpenMP.cpp:181
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenMP.cpp:187
unsigned getNumChildren() const
OMPChildren * Data
Data, associated with the directive.
Definition: DeclOpenMP.h:43
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:287
OMPDeclareMapperDecl * getPrevDeclInScope()
Get reference to previous declare mapper construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:158
static OMPDeclareMapperDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Creates deserialized declare mapper node.
Definition: DeclOpenMP.cpp:150
static OMPDeclareMapperDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, DeclarationName VarName, ArrayRef< OMPClause * > Clauses, OMPDeclareMapperDecl *PrevDeclInScope)
Creates declare mapper node.
Definition: DeclOpenMP.cpp:142
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:177
static OMPDeclareReductionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create deserialized declare reduction node.
Definition: DeclOpenMP.cpp:120
static OMPDeclareReductionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, OMPDeclareReductionDecl *PrevDeclInScope)
Create declare reduction node.
Definition: DeclOpenMP.cpp:112
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:126
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:416
static OMPRequiresDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Create deserialized requires node.
Definition: DeclOpenMP.cpp:92
static OMPRequiresDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< OMPClause * > CL)
Create requires node.
Definition: DeclOpenMP.cpp:85
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL)
Definition: DeclOpenMP.cpp:28
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:38
A (possibly-)qualified type.
Definition: Type.h:736
Encodes a location in the source.
A trivial tuple used to represent a source range.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:704
bool hasInit() const
Definition: Decl.cpp:2391
const Expr * getInit() const
Definition: Decl.h:1350
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.