| 1 | //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===// |
| 2 | // |
| 3 | // 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl |
| 10 | /// classes. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/Decl.h" |
| 16 | #include "clang/AST/DeclBase.h" |
| 17 | #include "clang/AST/DeclOpenMP.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | |
| 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // OMPThreadPrivateDecl Implementation. |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | void OMPThreadPrivateDecl::anchor() {} |
| 27 | |
| 28 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C, |
| 29 | DeclContext *DC, |
| 30 | SourceLocation L, |
| 31 | ArrayRef<Expr *> VL) { |
| 32 | auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>( |
| 33 | C, DC, Clauses: {}, NumChildren: VL.size(), P&: L); |
| 34 | D->setVars(VL); |
| 35 | return D; |
| 36 | } |
| 37 | |
| 38 | OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C, |
| 39 | GlobalDeclID ID, |
| 40 | unsigned N) { |
| 41 | return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>( |
| 42 | C, ID, NumClauses: 0, NumChildren: N); |
| 43 | } |
| 44 | |
| 45 | void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) { |
| 46 | assert(VL.size() == Data->getNumChildren() && |
| 47 | "Number of variables is not the same as the preallocated buffer" ); |
| 48 | llvm::copy(Range&: VL, Out: getVars().begin()); |
| 49 | } |
| 50 | |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | // OMPAllocateDecl Implementation. |
| 53 | //===----------------------------------------------------------------------===// |
| 54 | |
| 55 | void OMPAllocateDecl::anchor() { } |
| 56 | |
| 57 | OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC, |
| 58 | SourceLocation L, ArrayRef<Expr *> VL, |
| 59 | ArrayRef<OMPClause *> CL) { |
| 60 | auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>( |
| 61 | C, DC, Clauses: CL, NumChildren: VL.size(), P&: L); |
| 62 | D->setVars(VL); |
| 63 | return D; |
| 64 | } |
| 65 | |
| 66 | OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, |
| 67 | GlobalDeclID ID, |
| 68 | unsigned NVars, |
| 69 | unsigned NClauses) { |
| 70 | return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>( |
| 71 | C, ID, NumClauses: NClauses, NumChildren: NVars, P: SourceLocation()); |
| 72 | } |
| 73 | |
| 74 | void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) { |
| 75 | assert(VL.size() == Data->getNumChildren() && |
| 76 | "Number of variables is not the same as the preallocated buffer" ); |
| 77 | llvm::copy(Range&: VL, Out: getVars().begin()); |
| 78 | } |
| 79 | |
| 80 | //===----------------------------------------------------------------------===// |
| 81 | // OMPRequiresDecl Implementation. |
| 82 | //===----------------------------------------------------------------------===// |
| 83 | |
| 84 | void OMPRequiresDecl::anchor() {} |
| 85 | |
| 86 | OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC, |
| 87 | SourceLocation L, |
| 88 | ArrayRef<OMPClause *> CL) { |
| 89 | return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, Clauses: CL, NumChildren: 0, |
| 90 | P&: L); |
| 91 | } |
| 92 | |
| 93 | OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, |
| 94 | GlobalDeclID ID, |
| 95 | unsigned N) { |
| 96 | return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>( |
| 97 | C, ID, NumClauses: N, NumChildren: 0, P: SourceLocation()); |
| 98 | } |
| 99 | |
| 100 | //===----------------------------------------------------------------------===// |
| 101 | // OMPDeclareReductionDecl Implementation. |
| 102 | //===----------------------------------------------------------------------===// |
| 103 | |
| 104 | OMPDeclareReductionDecl::OMPDeclareReductionDecl( |
| 105 | Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 106 | QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope) |
| 107 | : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr), |
| 108 | PrevDeclInScope(PrevDeclInScope) { |
| 109 | setInitializer(E: nullptr, IK: OMPDeclareReductionInitKind::Call); |
| 110 | } |
| 111 | |
| 112 | void OMPDeclareReductionDecl::anchor() {} |
| 113 | |
| 114 | OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create( |
| 115 | ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 116 | QualType T, OMPDeclareReductionDecl *PrevDeclInScope) { |
| 117 | return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name, |
| 118 | T, PrevDeclInScope); |
| 119 | } |
| 120 | |
| 121 | OMPDeclareReductionDecl * |
| 122 | OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { |
| 123 | return new (C, ID) OMPDeclareReductionDecl( |
| 124 | OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(), |
| 125 | QualType(), /*PrevDeclInScope=*/nullptr); |
| 126 | } |
| 127 | |
| 128 | OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() { |
| 129 | return cast_or_null<OMPDeclareReductionDecl>( |
| 130 | Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource())); |
| 131 | } |
| 132 | const OMPDeclareReductionDecl * |
| 133 | OMPDeclareReductionDecl::getPrevDeclInScope() const { |
| 134 | return cast_or_null<OMPDeclareReductionDecl>( |
| 135 | Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource())); |
| 136 | } |
| 137 | |
| 138 | //===----------------------------------------------------------------------===// |
| 139 | // OMPDeclareMapperDecl Implementation. |
| 140 | //===----------------------------------------------------------------------===// |
| 141 | |
| 142 | void OMPDeclareMapperDecl::anchor() {} |
| 143 | |
| 144 | OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create( |
| 145 | ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 146 | QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses, |
| 147 | OMPDeclareMapperDecl *PrevDeclInScope) { |
| 148 | return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>( |
| 149 | C, DC, Clauses, NumChildren: 1, P&: L, P&: Name, P&: T, P&: VarName, P&: PrevDeclInScope); |
| 150 | } |
| 151 | |
| 152 | OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C, |
| 153 | GlobalDeclID ID, |
| 154 | unsigned N) { |
| 155 | return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>( |
| 156 | C, ID, NumClauses: N, NumChildren: 1, P: SourceLocation(), P: DeclarationName(), P: QualType(), |
| 157 | P: DeclarationName(), /*PrevDeclInScope=*/P: nullptr); |
| 158 | } |
| 159 | |
| 160 | OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() { |
| 161 | return cast_or_null<OMPDeclareMapperDecl>( |
| 162 | Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource())); |
| 163 | } |
| 164 | |
| 165 | const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const { |
| 166 | return cast_or_null<OMPDeclareMapperDecl>( |
| 167 | Val: PrevDeclInScope.get(Source: getASTContext().getExternalSource())); |
| 168 | } |
| 169 | |
| 170 | //===----------------------------------------------------------------------===// |
| 171 | // OMPCapturedExprDecl Implementation. |
| 172 | //===----------------------------------------------------------------------===// |
| 173 | |
| 174 | void OMPCapturedExprDecl::anchor() {} |
| 175 | |
| 176 | OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC, |
| 177 | IdentifierInfo *Id, QualType T, |
| 178 | SourceLocation StartLoc) { |
| 179 | return new (C, DC) OMPCapturedExprDecl( |
| 180 | C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc); |
| 181 | } |
| 182 | |
| 183 | OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C, |
| 184 | GlobalDeclID ID) { |
| 185 | return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), |
| 186 | /*TInfo=*/nullptr, SourceLocation()); |
| 187 | } |
| 188 | |
| 189 | SourceRange OMPCapturedExprDecl::getSourceRange() const { |
| 190 | assert(hasInit()); |
| 191 | return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc()); |
| 192 | } |
| 193 | |