blob: f50775bced24608c68b5628da847fa865042e652 [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Alexey Bataeva769e072013-03-22 06:34:35 +00006//
7//===----------------------------------------------------------------------===//
8/// \file
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
Alexey Bataev90c228f2016-02-08 09:29:13 +000010/// classes.
Alexey Bataeva769e072013-03-22 06:34:35 +000011///
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/ASTContext.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000015#include "clang/AST/Decl.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000016#include "clang/AST/DeclBase.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000017#include "clang/AST/DeclOpenMP.h"
18#include "clang/AST/Expr.h"
19
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// OMPThreadPrivateDecl Implementation.
24//===----------------------------------------------------------------------===//
25
26void OMPThreadPrivateDecl::anchor() { }
27
28OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29 DeclContext *DC,
30 SourceLocation L,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000031 ArrayRef<Expr *> VL) {
James Y Knight967eb202015-12-29 22:13:13 +000032 OMPThreadPrivateDecl *D =
33 new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
34 OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
Alexey Bataeva769e072013-03-22 06:34:35 +000035 D->NumVars = VL.size();
36 D->setVars(VL);
37 return D;
38}
39
40OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
41 unsigned ID,
42 unsigned N) {
James Y Knight967eb202015-12-29 22:13:13 +000043 OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
Craig Topper36250ad2014-05-12 05:36:57 +000044 OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
Alexey Bataeva769e072013-03-22 06:34:35 +000045 D->NumVars = N;
46 return D;
47}
48
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000049void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
Alexey Bataeva769e072013-03-22 06:34:35 +000050 assert(VL.size() == NumVars &&
51 "Number of variables is not the same as the preallocated buffer");
James Y Knight967eb202015-12-29 22:13:13 +000052 std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
Alexey Bataeva769e072013-03-22 06:34:35 +000053}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000054
Alexey Bataev90c228f2016-02-08 09:29:13 +000055//===----------------------------------------------------------------------===//
Alexey Bataev25ed0c02019-03-07 17:54:44 +000056// OMPAllocateDecl Implementation.
57//===----------------------------------------------------------------------===//
58
59void OMPAllocateDecl::anchor() { }
60
61OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
62 SourceLocation L,
63 ArrayRef<Expr *> VL) {
64 OMPAllocateDecl *D = new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
65 OMPAllocateDecl(OMPAllocate, DC, L);
66 D->NumVars = VL.size();
67 D->setVars(VL);
68 return D;
69}
70
71OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
72 unsigned N) {
73 OMPAllocateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
74 OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
75 D->NumVars = N;
76 return D;
77}
78
79void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
80 assert(VL.size() == NumVars &&
81 "Number of variables is not the same as the preallocated buffer");
82 std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
83}
84
85//===----------------------------------------------------------------------===//
Kelvin Li1408f912018-09-26 04:28:39 +000086// OMPRequiresDecl Implementation.
87//===----------------------------------------------------------------------===//
88
89void OMPRequiresDecl::anchor() {}
90
91OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
92 SourceLocation L,
93 ArrayRef<OMPClause *> CL) {
94 OMPRequiresDecl *D =
95 new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
96 OMPRequiresDecl(OMPRequires, DC, L);
97 D->NumClauses = CL.size();
98 D->setClauses(CL);
99 return D;
100}
101
102OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
103 unsigned N) {
104 OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
105 OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
106 D->NumClauses = N;
107 return D;
108}
109
110void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
111 assert(CL.size() == NumClauses &&
112 "Number of clauses is not the same as the preallocated buffer");
113 std::uninitialized_copy(CL.begin(), CL.end(),
114 getTrailingObjects<OMPClause *>());
115}
116
117//===----------------------------------------------------------------------===//
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000118// OMPDeclareReductionDecl Implementation.
119//===----------------------------------------------------------------------===//
120
Erich Keanec9d29902018-08-01 21:16:54 +0000121OMPDeclareReductionDecl::OMPDeclareReductionDecl(
122 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
123 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
124 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
125 PrevDeclInScope(PrevDeclInScope) {
126 setInitializer(nullptr, CallInit);
127}
128
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000129void OMPDeclareReductionDecl::anchor() {}
130
131OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
132 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
133 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
134 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
135 T, PrevDeclInScope);
136}
137
138OMPDeclareReductionDecl *
139OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
140 return new (C, ID) OMPDeclareReductionDecl(
141 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
142 QualType(), /*PrevDeclInScope=*/nullptr);
143}
144
145OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
146 return cast_or_null<OMPDeclareReductionDecl>(
147 PrevDeclInScope.get(getASTContext().getExternalSource()));
148}
149const OMPDeclareReductionDecl *
150OMPDeclareReductionDecl::getPrevDeclInScope() const {
151 return cast_or_null<OMPDeclareReductionDecl>(
152 PrevDeclInScope.get(getASTContext().getExternalSource()));
153}
154
155//===----------------------------------------------------------------------===//
Michael Kruse251e1482019-02-01 20:25:04 +0000156// OMPDeclareMapperDecl Implementation.
157//===----------------------------------------------------------------------===//
158
159void OMPDeclareMapperDecl::anchor() {}
160
161OMPDeclareMapperDecl *
162OMPDeclareMapperDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
163 DeclarationName Name, QualType T,
164 DeclarationName VarName,
165 OMPDeclareMapperDecl *PrevDeclInScope) {
166 return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
167 VarName, PrevDeclInScope);
168}
169
170OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
171 unsigned ID,
172 unsigned N) {
173 auto *D = new (C, ID)
174 OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
175 DeclarationName(), QualType(), DeclarationName(),
176 /*PrevDeclInScope=*/nullptr);
177 if (N) {
178 auto **ClauseStorage = C.Allocate<OMPClause *>(N);
179 D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
180 }
181 return D;
182}
183
184/// Creates an array of clauses to this mapper declaration and intializes
185/// them. The space used to store clause pointers is dynamically allocated,
186/// because we do not know the number of clauses when creating
187/// OMPDeclareMapperDecl
188void OMPDeclareMapperDecl::CreateClauses(ASTContext &C,
189 ArrayRef<OMPClause *> CL) {
190 assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
191 size_t NumClauses = CL.size();
192 if (NumClauses) {
193 auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
194 Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
195 setClauses(CL);
196 }
197}
198
199void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
200 assert(CL.size() == Clauses.size() &&
201 "Number of clauses is not the same as the preallocated buffer");
202 std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
203}
204
Eric Fiselierde9ffab2019-02-01 21:19:20 +0000205OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
206 return cast_or_null<OMPDeclareMapperDecl>(
207 PrevDeclInScope.get(getASTContext().getExternalSource()));
208}
209
210const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
211 return cast_or_null<OMPDeclareMapperDecl>(
212 PrevDeclInScope.get(getASTContext().getExternalSource()));
213}
214
Michael Kruse251e1482019-02-01 20:25:04 +0000215//===----------------------------------------------------------------------===//
Alexey Bataev4244be22016-02-11 05:35:55 +0000216// OMPCapturedExprDecl Implementation.
Alexey Bataev90c228f2016-02-08 09:29:13 +0000217//===----------------------------------------------------------------------===//
218
Alexey Bataev4244be22016-02-11 05:35:55 +0000219void OMPCapturedExprDecl::anchor() {}
Alexey Bataev90c228f2016-02-08 09:29:13 +0000220
Alexey Bataev4244be22016-02-11 05:35:55 +0000221OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
Alexey Bataeva7206b92016-12-20 16:51:02 +0000222 IdentifierInfo *Id, QualType T,
223 SourceLocation StartLoc) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000224 return new (C, DC) OMPCapturedExprDecl(
225 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
Alexey Bataev90c228f2016-02-08 09:29:13 +0000226}
227
Alexey Bataev4244be22016-02-11 05:35:55 +0000228OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
229 unsigned ID) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000230 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
231 /*TInfo=*/nullptr, SourceLocation());
Alexey Bataev90c228f2016-02-08 09:29:13 +0000232}
233
Alexey Bataeva7206b92016-12-20 16:51:02 +0000234SourceRange OMPCapturedExprDecl::getSourceRange() const {
235 assert(hasInit());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000236 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
Alexey Bataeva7206b92016-12-20 16:51:02 +0000237}