blob: 39cb46705e5ca7fa083c10f00aa1c67ac6298371 [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//===----------------------------------------------------------------------===//
Kelvin Li1408f912018-09-26 04:28:39 +000056// OMPRequiresDecl Implementation.
57//===----------------------------------------------------------------------===//
58
59void OMPRequiresDecl::anchor() {}
60
61OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
62 SourceLocation L,
63 ArrayRef<OMPClause *> CL) {
64 OMPRequiresDecl *D =
65 new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
66 OMPRequiresDecl(OMPRequires, DC, L);
67 D->NumClauses = CL.size();
68 D->setClauses(CL);
69 return D;
70}
71
72OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
73 unsigned N) {
74 OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
75 OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
76 D->NumClauses = N;
77 return D;
78}
79
80void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
81 assert(CL.size() == NumClauses &&
82 "Number of clauses is not the same as the preallocated buffer");
83 std::uninitialized_copy(CL.begin(), CL.end(),
84 getTrailingObjects<OMPClause *>());
85}
86
87//===----------------------------------------------------------------------===//
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000088// OMPDeclareReductionDecl Implementation.
89//===----------------------------------------------------------------------===//
90
Erich Keanec9d29902018-08-01 21:16:54 +000091OMPDeclareReductionDecl::OMPDeclareReductionDecl(
92 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
93 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
94 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
95 PrevDeclInScope(PrevDeclInScope) {
96 setInitializer(nullptr, CallInit);
97}
98
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000099void OMPDeclareReductionDecl::anchor() {}
100
101OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
102 ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
103 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
104 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
105 T, PrevDeclInScope);
106}
107
108OMPDeclareReductionDecl *
109OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
110 return new (C, ID) OMPDeclareReductionDecl(
111 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
112 QualType(), /*PrevDeclInScope=*/nullptr);
113}
114
115OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
116 return cast_or_null<OMPDeclareReductionDecl>(
117 PrevDeclInScope.get(getASTContext().getExternalSource()));
118}
119const OMPDeclareReductionDecl *
120OMPDeclareReductionDecl::getPrevDeclInScope() const {
121 return cast_or_null<OMPDeclareReductionDecl>(
122 PrevDeclInScope.get(getASTContext().getExternalSource()));
123}
124
125//===----------------------------------------------------------------------===//
Michael Kruse251e1482019-02-01 20:25:04 +0000126// OMPDeclareMapperDecl Implementation.
127//===----------------------------------------------------------------------===//
128
129void OMPDeclareMapperDecl::anchor() {}
130
131OMPDeclareMapperDecl *
132OMPDeclareMapperDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
133 DeclarationName Name, QualType T,
134 DeclarationName VarName,
135 OMPDeclareMapperDecl *PrevDeclInScope) {
136 return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
137 VarName, PrevDeclInScope);
138}
139
140OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
141 unsigned ID,
142 unsigned N) {
143 auto *D = new (C, ID)
144 OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
145 DeclarationName(), QualType(), DeclarationName(),
146 /*PrevDeclInScope=*/nullptr);
147 if (N) {
148 auto **ClauseStorage = C.Allocate<OMPClause *>(N);
149 D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
150 }
151 return D;
152}
153
154/// Creates an array of clauses to this mapper declaration and intializes
155/// them. The space used to store clause pointers is dynamically allocated,
156/// because we do not know the number of clauses when creating
157/// OMPDeclareMapperDecl
158void OMPDeclareMapperDecl::CreateClauses(ASTContext &C,
159 ArrayRef<OMPClause *> CL) {
160 assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
161 size_t NumClauses = CL.size();
162 if (NumClauses) {
163 auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
164 Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
165 setClauses(CL);
166 }
167}
168
169void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
170 assert(CL.size() == Clauses.size() &&
171 "Number of clauses is not the same as the preallocated buffer");
172 std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
173}
174
Eric Fiselierde9ffab2019-02-01 21:19:20 +0000175OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
176 return cast_or_null<OMPDeclareMapperDecl>(
177 PrevDeclInScope.get(getASTContext().getExternalSource()));
178}
179
180const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
181 return cast_or_null<OMPDeclareMapperDecl>(
182 PrevDeclInScope.get(getASTContext().getExternalSource()));
183}
184
Michael Kruse251e1482019-02-01 20:25:04 +0000185//===----------------------------------------------------------------------===//
Alexey Bataev4244be22016-02-11 05:35:55 +0000186// OMPCapturedExprDecl Implementation.
Alexey Bataev90c228f2016-02-08 09:29:13 +0000187//===----------------------------------------------------------------------===//
188
Alexey Bataev4244be22016-02-11 05:35:55 +0000189void OMPCapturedExprDecl::anchor() {}
Alexey Bataev90c228f2016-02-08 09:29:13 +0000190
Alexey Bataev4244be22016-02-11 05:35:55 +0000191OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
Alexey Bataeva7206b92016-12-20 16:51:02 +0000192 IdentifierInfo *Id, QualType T,
193 SourceLocation StartLoc) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000194 return new (C, DC) OMPCapturedExprDecl(
195 C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
Alexey Bataev90c228f2016-02-08 09:29:13 +0000196}
197
Alexey Bataev4244be22016-02-11 05:35:55 +0000198OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
199 unsigned ID) {
Erich Keaneed6bc342018-06-01 13:04:26 +0000200 return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
201 /*TInfo=*/nullptr, SourceLocation());
Alexey Bataev90c228f2016-02-08 09:29:13 +0000202}
203
Alexey Bataeva7206b92016-12-20 16:51:02 +0000204SourceRange OMPCapturedExprDecl::getSourceRange() const {
205 assert(hasInit());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000206 return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
Alexey Bataeva7206b92016-12-20 16:51:02 +0000207}