clang  14.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 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclBase.h"
17 #include "clang/AST/DeclOpenMP.h"
18 #include "clang/AST/Expr.h"
19 
20 using namespace clang;
21 
22 //===----------------------------------------------------------------------===//
23 // OMPThreadPrivateDecl Implementation.
24 //===----------------------------------------------------------------------===//
25 
26 void OMPThreadPrivateDecl::anchor() {}
27 
29  DeclContext *DC,
31  ArrayRef<Expr *> VL) {
32  auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33  C, DC, llvm::None, 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 
45 void 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 
55 void 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 
73 void 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 
83 void 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 
102 OMPDeclareReductionDecl::OMPDeclareReductionDecl(
104  QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
105  : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
106  PrevDeclInScope(PrevDeclInScope) {
107  setInitializer(nullptr, CallInit);
108 }
109 
110 void 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 
140 void OMPDeclareMapperDecl::anchor() {}
141 
144  QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
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 
172 void 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());
189  return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
190 }
clang::OMPAllocateDecl
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:473
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::DeclaratorDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:780
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:426
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::OMPRequiresDecl::CreateDeserialized
static OMPRequiresDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Create deserialized requires node.
Definition: DeclOpenMP.cpp:92
clang::OMPDeclareMapperDecl::CreateDeserialized
static OMPDeclareMapperDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Creates deserialized declare mapper node.
Definition: DeclOpenMP.cpp:150
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::OMPThreadPrivateDecl
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
clang::OMPThreadPrivateDecl::CreateDeserialized
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:38
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::OMPDeclareReductionDecl::CreateDeserialized
static OMPDeclareReductionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create deserialized declare reduction node.
Definition: DeclOpenMP.cpp:120
DeclOpenMP.h
clang::OMPAllocateDecl::CreateDeserialized
static OMPAllocateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NVars, unsigned NClauses)
Definition: DeclOpenMP.cpp:66
clang::OMPRequiresDecl::Create
static OMPRequiresDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< OMPClause * > CL)
Create requires node.
Definition: DeclOpenMP.cpp:85
clang::OMPDeclareMapperDecl::Create
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
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
Decl.h
clang::OMPThreadPrivateDecl::Create
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL)
Definition: DeclOpenMP.cpp:28
clang::VarDecl::hasInit
bool hasInit() const
Definition: Decl.cpp:2282
clang::OMPDeclareMapperDecl::getPrevDeclInScope
OMPDeclareMapperDecl * getPrevDeclInScope()
Get reference to previous declare mapper construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:158
clang::OMPDeclareReductionDecl
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:171
Id
int Id
Definition: ASTDiff.cpp:191
DeclBase.h
clang::OMPDeclareReductionDecl::getPrevDeclInScope
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name.
Definition: DeclOpenMP.cpp:126
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
Expr.h
ASTContext.h
clang::OMPDeclareMapperDecl
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:286
clang::OMPCapturedExprDecl::CreateDeserialized
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclOpenMP.cpp:181
clang::OMPChildren::getNumChildren
unsigned getNumChildren() const
Definition: OpenMPClause.h:8607
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:676
clang::OMPCapturedExprDecl
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:383
llvm::ArrayRef
Definition: LLVM.h:34
clang::OMPCapturedExprDecl::Create
static OMPCapturedExprDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, SourceLocation StartLoc)
Definition: DeclOpenMP.cpp:174
clang::VarDecl::getInit
const Expr * getInit() const
Definition: Decl.h:1285
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::LazyOffsetPtr::get
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
Definition: ExternalASTSource.h:374
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
clang::OMPDeclareReductionDecl::Create
static OMPDeclareReductionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, OMPDeclareReductionDecl *PrevDeclInScope)
Create declare reduction node.
Definition: DeclOpenMP.cpp:112
clang::OMPRequiresDecl
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:416
clang::OMPAllocateDecl::Create
static OMPAllocateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr * > VL, ArrayRef< OMPClause * > CL)
Definition: DeclOpenMP.cpp:57
clang::OMPCapturedExprDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenMP.cpp:187
clang::OMPDeclarativeDirective< Decl >::Data
OMPChildren * Data
Data, associated with the directive.
Definition: DeclOpenMP.h:43