10b57cec5SDimitry Andric //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric /// \file 90b57cec5SDimitry Andric /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl 100b57cec5SDimitry Andric /// classes. 110b57cec5SDimitry Andric /// 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #include "clang/AST/ASTContext.h" 150b57cec5SDimitry Andric #include "clang/AST/Decl.h" 160b57cec5SDimitry Andric #include "clang/AST/DeclBase.h" 170b57cec5SDimitry Andric #include "clang/AST/DeclOpenMP.h" 180b57cec5SDimitry Andric #include "clang/AST/Expr.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric using namespace clang; 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 230b57cec5SDimitry Andric // OMPThreadPrivateDecl Implementation. 240b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric void OMPThreadPrivateDecl::anchor() {} 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C, 290b57cec5SDimitry Andric DeclContext *DC, 300b57cec5SDimitry Andric SourceLocation L, 310b57cec5SDimitry Andric ArrayRef<Expr *> VL) { 32e8d8bef9SDimitry Andric auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>( 33bdd1243dSDimitry Andric C, DC, std::nullopt, VL.size(), L); 340b57cec5SDimitry Andric D->setVars(VL); 350b57cec5SDimitry Andric return D; 360b57cec5SDimitry Andric } 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C, 39*0fca6ea1SDimitry Andric GlobalDeclID ID, 400b57cec5SDimitry Andric unsigned N) { 41e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>( 42e8d8bef9SDimitry Andric C, ID, 0, N); 430b57cec5SDimitry Andric } 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) { 46e8d8bef9SDimitry Andric assert(VL.size() == Data->getNumChildren() && 470b57cec5SDimitry Andric "Number of variables is not the same as the preallocated buffer"); 48e8d8bef9SDimitry Andric llvm::copy(VL, getVars().begin()); 490b57cec5SDimitry Andric } 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 520b57cec5SDimitry Andric // OMPAllocateDecl Implementation. 530b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric void OMPAllocateDecl::anchor() { } 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC, 580b57cec5SDimitry Andric SourceLocation L, ArrayRef<Expr *> VL, 590b57cec5SDimitry Andric ArrayRef<OMPClause *> CL) { 60e8d8bef9SDimitry Andric auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>( 61e8d8bef9SDimitry Andric C, DC, CL, VL.size(), L); 620b57cec5SDimitry Andric D->setVars(VL); 630b57cec5SDimitry Andric return D; 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 66*0fca6ea1SDimitry Andric OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, 67*0fca6ea1SDimitry Andric GlobalDeclID ID, 680b57cec5SDimitry Andric unsigned NVars, 690b57cec5SDimitry Andric unsigned NClauses) { 70e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>( 71e8d8bef9SDimitry Andric C, ID, NClauses, NVars, SourceLocation()); 720b57cec5SDimitry Andric } 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) { 75e8d8bef9SDimitry Andric assert(VL.size() == Data->getNumChildren() && 760b57cec5SDimitry Andric "Number of variables is not the same as the preallocated buffer"); 77e8d8bef9SDimitry Andric llvm::copy(VL, getVars().begin()); 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 810b57cec5SDimitry Andric // OMPRequiresDecl Implementation. 820b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric void OMPRequiresDecl::anchor() {} 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC, 870b57cec5SDimitry Andric SourceLocation L, 880b57cec5SDimitry Andric ArrayRef<OMPClause *> CL) { 89e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0, 90e8d8bef9SDimitry Andric L); 910b57cec5SDimitry Andric } 920b57cec5SDimitry Andric 93*0fca6ea1SDimitry Andric OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, 94*0fca6ea1SDimitry Andric GlobalDeclID ID, 950b57cec5SDimitry Andric unsigned N) { 96e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>( 97e8d8bef9SDimitry Andric C, ID, N, 0, SourceLocation()); 980b57cec5SDimitry Andric } 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1010b57cec5SDimitry Andric // OMPDeclareReductionDecl Implementation. 1020b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric OMPDeclareReductionDecl::OMPDeclareReductionDecl( 1050b57cec5SDimitry Andric Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, 1060b57cec5SDimitry Andric QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope) 1070b57cec5SDimitry Andric : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr), 1080b57cec5SDimitry Andric PrevDeclInScope(PrevDeclInScope) { 1095f757f3fSDimitry Andric setInitializer(nullptr, OMPDeclareReductionInitKind::Call); 1100b57cec5SDimitry Andric } 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric void OMPDeclareReductionDecl::anchor() {} 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create( 1150b57cec5SDimitry Andric ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, 1160b57cec5SDimitry Andric QualType T, OMPDeclareReductionDecl *PrevDeclInScope) { 1170b57cec5SDimitry Andric return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name, 1180b57cec5SDimitry Andric T, PrevDeclInScope); 1190b57cec5SDimitry Andric } 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric OMPDeclareReductionDecl * 122*0fca6ea1SDimitry Andric OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { 1230b57cec5SDimitry Andric return new (C, ID) OMPDeclareReductionDecl( 1240b57cec5SDimitry Andric OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(), 1250b57cec5SDimitry Andric QualType(), /*PrevDeclInScope=*/nullptr); 1260b57cec5SDimitry Andric } 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() { 1290b57cec5SDimitry Andric return cast_or_null<OMPDeclareReductionDecl>( 1300b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource())); 1310b57cec5SDimitry Andric } 1320b57cec5SDimitry Andric const OMPDeclareReductionDecl * 1330b57cec5SDimitry Andric OMPDeclareReductionDecl::getPrevDeclInScope() const { 1340b57cec5SDimitry Andric return cast_or_null<OMPDeclareReductionDecl>( 1350b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource())); 1360b57cec5SDimitry Andric } 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1390b57cec5SDimitry Andric // OMPDeclareMapperDecl Implementation. 1400b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric void OMPDeclareMapperDecl::anchor() {} 1430b57cec5SDimitry Andric 144e8d8bef9SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create( 145e8d8bef9SDimitry Andric ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, 146e8d8bef9SDimitry Andric QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses, 1470b57cec5SDimitry Andric OMPDeclareMapperDecl *PrevDeclInScope) { 148e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>( 149e8d8bef9SDimitry Andric C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope); 1500b57cec5SDimitry Andric } 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C, 153*0fca6ea1SDimitry Andric GlobalDeclID ID, 1540b57cec5SDimitry Andric unsigned N) { 155e8d8bef9SDimitry Andric return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>( 156e8d8bef9SDimitry Andric C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(), 157e8d8bef9SDimitry Andric DeclarationName(), /*PrevDeclInScope=*/nullptr); 1580b57cec5SDimitry Andric } 1590b57cec5SDimitry Andric 1600b57cec5SDimitry Andric OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() { 1610b57cec5SDimitry Andric return cast_or_null<OMPDeclareMapperDecl>( 1620b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource())); 1630b57cec5SDimitry Andric } 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const { 1660b57cec5SDimitry Andric return cast_or_null<OMPDeclareMapperDecl>( 1670b57cec5SDimitry Andric PrevDeclInScope.get(getASTContext().getExternalSource())); 1680b57cec5SDimitry Andric } 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1710b57cec5SDimitry Andric // OMPCapturedExprDecl Implementation. 1720b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric void OMPCapturedExprDecl::anchor() {} 1750b57cec5SDimitry Andric 1760b57cec5SDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC, 1770b57cec5SDimitry Andric IdentifierInfo *Id, QualType T, 1780b57cec5SDimitry Andric SourceLocation StartLoc) { 1790b57cec5SDimitry Andric return new (C, DC) OMPCapturedExprDecl( 1800b57cec5SDimitry Andric C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc); 1810b57cec5SDimitry Andric } 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andric OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C, 184*0fca6ea1SDimitry Andric GlobalDeclID ID) { 1850b57cec5SDimitry Andric return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), 1860b57cec5SDimitry Andric /*TInfo=*/nullptr, SourceLocation()); 1870b57cec5SDimitry Andric } 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric SourceRange OMPCapturedExprDecl::getSourceRange() const { 1900b57cec5SDimitry Andric assert(hasInit()); 1910b57cec5SDimitry Andric return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc()); 1920b57cec5SDimitry Andric } 193