clang 19.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 GlobalDeclID 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 GlobalDeclID ID,
68 unsigned NVars,
69 unsigned NClauses) {
70 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
71 C, ID, NClauses, NVars, SourceLocation());
72}
73
74void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
75 assert(VL.size() == Data->getNumChildren() &&
76 "Number of variables is not the same as the preallocated buffer");
77 llvm::copy(VL, getVars().begin());
78}
79
80//===----------------------------------------------------------------------===//
81// OMPRequiresDecl Implementation.
82//===----------------------------------------------------------------------===//
83
84void OMPRequiresDecl::anchor() {}
85
89 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
90 L);
91}
92
94 GlobalDeclID ID,
95 unsigned N) {
96 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
97 C, ID, N, 0, SourceLocation());
98}
99
100//===----------------------------------------------------------------------===//
101// OMPDeclareReductionDecl Implementation.
102//===----------------------------------------------------------------------===//
103
104OMPDeclareReductionDecl::OMPDeclareReductionDecl(
105 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
106 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
107 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
108 PrevDeclInScope(PrevDeclInScope) {
109 setInitializer(nullptr, OMPDeclareReductionInitKind::Call);
110}
111
112void OMPDeclareReductionDecl::anchor() {}
113
116 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
117 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
118 T, PrevDeclInScope);
119}
120
123 return new (C, ID) OMPDeclareReductionDecl(
124 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
125 QualType(), /*PrevDeclInScope=*/nullptr);
126}
127
129 return cast_or_null<OMPDeclareReductionDecl>(
130 PrevDeclInScope.get(getASTContext().getExternalSource()));
131}
134 return cast_or_null<OMPDeclareReductionDecl>(
135 PrevDeclInScope.get(getASTContext().getExternalSource()));
136}
137
138//===----------------------------------------------------------------------===//
139// OMPDeclareMapperDecl Implementation.
140//===----------------------------------------------------------------------===//
141
142void OMPDeclareMapperDecl::anchor() {}
143
147 OMPDeclareMapperDecl *PrevDeclInScope) {
148 return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
149 C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
150}
151
153 GlobalDeclID ID,
154 unsigned N) {
155 return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
156 C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
157 DeclarationName(), /*PrevDeclInScope=*/nullptr);
158}
159
161 return cast_or_null<OMPDeclareMapperDecl>(
162 PrevDeclInScope.get(getASTContext().getExternalSource()));
163}
164
166 return cast_or_null<OMPDeclareMapperDecl>(
167 PrevDeclInScope.get(getASTContext().getExternalSource()));
168}
169
170//===----------------------------------------------------------------------===//
171// OMPCapturedExprDecl Implementation.
172//===----------------------------------------------------------------------===//
173
174void OMPCapturedExprDecl::anchor() {}
175
178 SourceLocation StartLoc) {
179 return new (C, DC) OMPCapturedExprDecl(
180 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
181}
182
184 GlobalDeclID ID) {
185 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
186 /*TInfo=*/nullptr, SourceLocation());
187}
188
190 assert(hasInit());
192}
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:185
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
The name of a declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:822
One of these records is kept for each identifier that is lexed.
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:474
static OMPAllocateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL, ArrayRef< OMPClause * > CL)
Definition: DeclOpenMP.cpp:57
static OMPAllocateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID 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:176
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclOpenMP.cpp:183
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenMP.cpp:189
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
static OMPDeclareMapperDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned N)
Creates deserialized declare mapper node.
Definition: DeclOpenMP.cpp:152
OMPDeclareMapperDecl * getPrevDeclInScope()
Get reference to previous declare mapper construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:160
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:144
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:177
static OMPDeclareReductionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, OMPDeclareReductionDecl *PrevDeclInScope)
Create declare reduction node.
Definition: DeclOpenMP.cpp:114
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:128
static OMPDeclareReductionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create deserialized declare reduction node.
Definition: DeclOpenMP.cpp:122
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:417
static OMPRequiresDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned N)
Create deserialized requires node.
Definition: DeclOpenMP.cpp:93
static OMPRequiresDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< OMPClause * > CL)
Create requires node.
Definition: DeclOpenMP.cpp:86
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned N)
Definition: DeclOpenMP.cpp:38
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL)
Definition: DeclOpenMP.cpp:28
A (possibly-)qualified type.
Definition: Type.h:940
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:706
bool hasInit() const
Definition: Decl.cpp:2395
const Expr * getInit() const
Definition: Decl.h:1355
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.