2013-03-22 14:34:35 +08:00
|
|
|
//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-03-22 14:34:35 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
2018-05-09 09:00:01 +08:00
|
|
|
/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
|
2016-02-08 17:29:13 +08:00
|
|
|
/// classes.
|
2013-03-22 14:34:35 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "clang/AST/DeclBase.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OMPThreadPrivateDecl Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void OMPThreadPrivateDecl::anchor() { }
|
|
|
|
|
|
|
|
OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
2013-05-13 12:18:18 +08:00
|
|
|
ArrayRef<Expr *> VL) {
|
2015-12-30 06:13:13 +08:00
|
|
|
OMPThreadPrivateDecl *D =
|
|
|
|
new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
|
|
|
|
OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
|
2013-03-22 14:34:35 +08:00
|
|
|
D->NumVars = VL.size();
|
|
|
|
D->setVars(VL);
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID,
|
|
|
|
unsigned N) {
|
2015-12-30 06:13:13 +08:00
|
|
|
OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
|
2014-05-12 13:36:57 +08:00
|
|
|
OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
|
2013-03-22 14:34:35 +08:00
|
|
|
D->NumVars = N;
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
|
2013-03-22 14:34:35 +08:00
|
|
|
assert(VL.size() == NumVars &&
|
|
|
|
"Number of variables is not the same as the preallocated buffer");
|
2015-12-30 06:13:13 +08:00
|
|
|
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2019-03-08 01:54:44 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OMPAllocateDecl Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void OMPAllocateDecl::anchor() { }
|
|
|
|
|
|
|
|
OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
|
2019-03-13 02:52:33 +08:00
|
|
|
SourceLocation L, ArrayRef<Expr *> VL,
|
|
|
|
ArrayRef<OMPClause *> CL) {
|
|
|
|
OMPAllocateDecl *D = new (
|
|
|
|
C, DC, additionalSizeToAlloc<Expr *, OMPClause *>(VL.size(), CL.size()))
|
2019-03-08 01:54:44 +08:00
|
|
|
OMPAllocateDecl(OMPAllocate, DC, L);
|
|
|
|
D->NumVars = VL.size();
|
|
|
|
D->setVars(VL);
|
2019-03-13 02:52:33 +08:00
|
|
|
D->NumClauses = CL.size();
|
|
|
|
D->setClauses(CL);
|
2019-03-08 01:54:44 +08:00
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
|
2019-03-13 02:52:33 +08:00
|
|
|
unsigned NVars,
|
|
|
|
unsigned NClauses) {
|
|
|
|
OMPAllocateDecl *D =
|
|
|
|
new (C, ID, additionalSizeToAlloc<Expr *, OMPClause *>(NVars, NClauses))
|
|
|
|
OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
|
|
|
|
D->NumVars = NVars;
|
|
|
|
D->NumClauses = NClauses;
|
2019-03-08 01:54:44 +08:00
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
|
|
|
|
assert(VL.size() == NumVars &&
|
|
|
|
"Number of variables is not the same as the preallocated buffer");
|
|
|
|
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
|
|
|
|
}
|
|
|
|
|
2019-03-13 02:52:33 +08:00
|
|
|
void OMPAllocateDecl::setClauses(ArrayRef<OMPClause *> CL) {
|
|
|
|
assert(CL.size() == NumClauses &&
|
|
|
|
"Number of variables is not the same as the preallocated buffer");
|
|
|
|
std::uninitialized_copy(CL.begin(), CL.end(),
|
|
|
|
getTrailingObjects<OMPClause *>());
|
|
|
|
}
|
|
|
|
|
2018-09-26 12:28:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OMPRequiresDecl Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void OMPRequiresDecl::anchor() {}
|
|
|
|
|
|
|
|
OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
ArrayRef<OMPClause *> CL) {
|
|
|
|
OMPRequiresDecl *D =
|
|
|
|
new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
|
|
|
|
OMPRequiresDecl(OMPRequires, DC, L);
|
|
|
|
D->NumClauses = CL.size();
|
|
|
|
D->setClauses(CL);
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
|
|
|
|
unsigned N) {
|
|
|
|
OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
|
|
|
|
OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
|
|
|
|
D->NumClauses = N;
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
|
|
|
|
assert(CL.size() == NumClauses &&
|
|
|
|
"Number of clauses is not the same as the preallocated buffer");
|
|
|
|
std::uninitialized_copy(CL.begin(), CL.end(),
|
|
|
|
getTrailingObjects<OMPClause *>());
|
|
|
|
}
|
|
|
|
|
2016-03-03 13:21:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OMPDeclareReductionDecl Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-08-02 05:16:54 +08:00
|
|
|
OMPDeclareReductionDecl::OMPDeclareReductionDecl(
|
|
|
|
Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
|
|
|
|
: ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
|
|
|
|
PrevDeclInScope(PrevDeclInScope) {
|
|
|
|
setInitializer(nullptr, CallInit);
|
|
|
|
}
|
|
|
|
|
2016-03-03 13:21:39 +08:00
|
|
|
void OMPDeclareReductionDecl::anchor() {}
|
|
|
|
|
|
|
|
OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
|
|
|
|
ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
|
|
|
|
return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
|
|
|
|
T, PrevDeclInScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPDeclareReductionDecl *
|
|
|
|
OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
|
|
|
|
return new (C, ID) OMPDeclareReductionDecl(
|
|
|
|
OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
|
|
|
|
QualType(), /*PrevDeclInScope=*/nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
|
|
|
|
return cast_or_null<OMPDeclareReductionDecl>(
|
|
|
|
PrevDeclInScope.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
const OMPDeclareReductionDecl *
|
|
|
|
OMPDeclareReductionDecl::getPrevDeclInScope() const {
|
|
|
|
return cast_or_null<OMPDeclareReductionDecl>(
|
|
|
|
PrevDeclInScope.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
|
2016-02-08 17:29:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-02-02 04:25:04 +08:00
|
|
|
// OMPDeclareMapperDecl Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void OMPDeclareMapperDecl::anchor() {}
|
|
|
|
|
|
|
|
OMPDeclareMapperDecl *
|
|
|
|
OMPDeclareMapperDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
|
|
DeclarationName Name, QualType T,
|
|
|
|
DeclarationName VarName,
|
|
|
|
OMPDeclareMapperDecl *PrevDeclInScope) {
|
|
|
|
return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
|
|
|
|
VarName, PrevDeclInScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID,
|
|
|
|
unsigned N) {
|
|
|
|
auto *D = new (C, ID)
|
|
|
|
OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
|
|
|
|
DeclarationName(), QualType(), DeclarationName(),
|
|
|
|
/*PrevDeclInScope=*/nullptr);
|
|
|
|
if (N) {
|
|
|
|
auto **ClauseStorage = C.Allocate<OMPClause *>(N);
|
|
|
|
D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
|
|
|
|
}
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates an array of clauses to this mapper declaration and intializes
|
|
|
|
/// them. The space used to store clause pointers is dynamically allocated,
|
|
|
|
/// because we do not know the number of clauses when creating
|
|
|
|
/// OMPDeclareMapperDecl
|
|
|
|
void OMPDeclareMapperDecl::CreateClauses(ASTContext &C,
|
|
|
|
ArrayRef<OMPClause *> CL) {
|
|
|
|
assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
|
|
|
|
size_t NumClauses = CL.size();
|
|
|
|
if (NumClauses) {
|
|
|
|
auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
|
|
|
|
Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
|
|
|
|
setClauses(CL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
|
|
|
|
assert(CL.size() == Clauses.size() &&
|
|
|
|
"Number of clauses is not the same as the preallocated buffer");
|
|
|
|
std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
|
|
|
|
}
|
|
|
|
|
2019-02-02 05:19:20 +08:00
|
|
|
OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
|
|
|
|
return cast_or_null<OMPDeclareMapperDecl>(
|
|
|
|
PrevDeclInScope.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
|
|
|
|
const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
|
|
|
|
return cast_or_null<OMPDeclareMapperDecl>(
|
|
|
|
PrevDeclInScope.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
|
2019-02-02 04:25:04 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2016-02-11 13:35:55 +08:00
|
|
|
// OMPCapturedExprDecl Implementation.
|
2016-02-08 17:29:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-11 13:35:55 +08:00
|
|
|
void OMPCapturedExprDecl::anchor() {}
|
2016-02-08 17:29:13 +08:00
|
|
|
|
2016-02-11 13:35:55 +08:00
|
|
|
OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
|
2016-12-21 00:51:02 +08:00
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
SourceLocation StartLoc) {
|
2018-06-01 21:04:26 +08:00
|
|
|
return new (C, DC) OMPCapturedExprDecl(
|
|
|
|
C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
|
2016-02-08 17:29:13 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 13:35:55 +08:00
|
|
|
OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
2018-06-01 21:04:26 +08:00
|
|
|
return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
|
|
|
|
/*TInfo=*/nullptr, SourceLocation());
|
2016-02-08 17:29:13 +08:00
|
|
|
}
|
|
|
|
|
2016-12-21 00:51:02 +08:00
|
|
|
SourceRange OMPCapturedExprDecl::getSourceRange() const {
|
|
|
|
assert(hasInit());
|
2018-08-10 05:09:38 +08:00
|
|
|
return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
|
2016-12-21 00:51:02 +08:00
|
|
|
}
|