diff options
author | Michael Kruse <llvm@meinersbur.de> | 2019-02-01 20:25:04 +0000 |
---|---|---|
committer | Michael Kruse <llvm@meinersbur.de> | 2019-02-01 20:25:04 +0000 |
commit | 251e1488e195a0ab618e503fe5b2bc8ff18d1724 (patch) | |
tree | fb857506e530be8dff680a7f283eaad431bdf545 /clang/lib/AST/DeclOpenMP.cpp | |
parent | 6b653fc70ffdc3ec685a435b42c45611e21d407c (diff) | |
download | bcm5719-llvm-251e1488e195a0ab618e503fe5b2bc8ff18d1724.tar.gz bcm5719-llvm-251e1488e195a0ab618e503fe5b2bc8ff18d1724.zip |
[OpenMP 5.0] Parsing/sema support for "omp declare mapper" directive.
This patch implements parsing and sema for "omp declare mapper"
directive. User defined mapper, i.e., declare mapper directive, is a new
feature in OpenMP 5.0. It is introduced to extend existing map clauses
for the purpose of simplifying the copy of complex data structures
between host and device (i.e., deep copy). An example is shown below:
struct S { int len; int *d; };
#pragma omp declare mapper(struct S s) map(s, s.d[0:s.len]) // Memory region that d points to is also mapped using this mapper.
Contributed-by: Lingda Li <lildmh@gmail.com>
Differential Revision: https://reviews.llvm.org/D56326
llvm-svn: 352906
Diffstat (limited to 'clang/lib/AST/DeclOpenMP.cpp')
-rw-r--r-- | clang/lib/AST/DeclOpenMP.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclOpenMP.cpp b/clang/lib/AST/DeclOpenMP.cpp index f709013ba9d..5a1b0363137 100644 --- a/clang/lib/AST/DeclOpenMP.cpp +++ b/clang/lib/AST/DeclOpenMP.cpp @@ -123,6 +123,56 @@ OMPDeclareReductionDecl::getPrevDeclInScope() const { } //===----------------------------------------------------------------------===// +// 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()); +} + +//===----------------------------------------------------------------------===// // OMPCapturedExprDecl Implementation. //===----------------------------------------------------------------------===// |