DeclOpenMP.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/Decl.h"
  15. #include "clang/AST/DeclBase.h"
  16. #include "clang/AST/DeclOpenMP.h"
  17. #include "clang/AST/Expr.h"
  18. using namespace clang;
  19. //===----------------------------------------------------------------------===//
  20. // OMPThreadPrivateDecl Implementation.
  21. //===----------------------------------------------------------------------===//
  22. void OMPThreadPrivateDecl::anchor() {}
  23. OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
  24. DeclContext *DC,
  25. SourceLocation L,
  26. ArrayRef<Expr *> VL) {
  27. auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
  28. C, DC, std::nullopt, VL.size(), L);
  29. D->setVars(VL);
  30. return D;
  31. }
  32. OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
  33. unsigned ID,
  34. unsigned N) {
  35. return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
  36. C, ID, 0, N);
  37. }
  38. void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
  39. assert(VL.size() == Data->getNumChildren() &&
  40. "Number of variables is not the same as the preallocated buffer");
  41. llvm::copy(VL, getVars().begin());
  42. }
  43. //===----------------------------------------------------------------------===//
  44. // OMPAllocateDecl Implementation.
  45. //===----------------------------------------------------------------------===//
  46. void OMPAllocateDecl::anchor() { }
  47. OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
  48. SourceLocation L, ArrayRef<Expr *> VL,
  49. ArrayRef<OMPClause *> CL) {
  50. auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
  51. C, DC, CL, VL.size(), L);
  52. D->setVars(VL);
  53. return D;
  54. }
  55. OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
  56. unsigned NVars,
  57. unsigned NClauses) {
  58. return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
  59. C, ID, NClauses, NVars, SourceLocation());
  60. }
  61. void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
  62. assert(VL.size() == Data->getNumChildren() &&
  63. "Number of variables is not the same as the preallocated buffer");
  64. llvm::copy(VL, getVars().begin());
  65. }
  66. //===----------------------------------------------------------------------===//
  67. // OMPRequiresDecl Implementation.
  68. //===----------------------------------------------------------------------===//
  69. void OMPRequiresDecl::anchor() {}
  70. OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
  71. SourceLocation L,
  72. ArrayRef<OMPClause *> CL) {
  73. return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
  74. L);
  75. }
  76. OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
  77. unsigned N) {
  78. return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
  79. C, ID, N, 0, SourceLocation());
  80. }
  81. //===----------------------------------------------------------------------===//
  82. // OMPDeclareReductionDecl Implementation.
  83. //===----------------------------------------------------------------------===//
  84. OMPDeclareReductionDecl::OMPDeclareReductionDecl(
  85. Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
  86. QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
  87. : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
  88. PrevDeclInScope(PrevDeclInScope) {
  89. setInitializer(nullptr, CallInit);
  90. }
  91. void OMPDeclareReductionDecl::anchor() {}
  92. OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
  93. ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
  94. QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
  95. return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
  96. T, PrevDeclInScope);
  97. }
  98. OMPDeclareReductionDecl *
  99. OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
  100. return new (C, ID) OMPDeclareReductionDecl(
  101. OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
  102. QualType(), /*PrevDeclInScope=*/nullptr);
  103. }
  104. OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
  105. return cast_or_null<OMPDeclareReductionDecl>(
  106. PrevDeclInScope.get(getASTContext().getExternalSource()));
  107. }
  108. const OMPDeclareReductionDecl *
  109. OMPDeclareReductionDecl::getPrevDeclInScope() const {
  110. return cast_or_null<OMPDeclareReductionDecl>(
  111. PrevDeclInScope.get(getASTContext().getExternalSource()));
  112. }
  113. //===----------------------------------------------------------------------===//
  114. // OMPDeclareMapperDecl Implementation.
  115. //===----------------------------------------------------------------------===//
  116. void OMPDeclareMapperDecl::anchor() {}
  117. OMPDeclareMapperDecl *OMPDeclareMapperDecl::Create(
  118. ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
  119. QualType T, DeclarationName VarName, ArrayRef<OMPClause *> Clauses,
  120. OMPDeclareMapperDecl *PrevDeclInScope) {
  121. return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
  122. C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);
  123. }
  124. OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
  125. unsigned ID,
  126. unsigned N) {
  127. return OMPDeclarativeDirective::createEmptyDirective<OMPDeclareMapperDecl>(
  128. C, ID, N, 1, SourceLocation(), DeclarationName(), QualType(),
  129. DeclarationName(), /*PrevDeclInScope=*/nullptr);
  130. }
  131. OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
  132. return cast_or_null<OMPDeclareMapperDecl>(
  133. PrevDeclInScope.get(getASTContext().getExternalSource()));
  134. }
  135. const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
  136. return cast_or_null<OMPDeclareMapperDecl>(
  137. PrevDeclInScope.get(getASTContext().getExternalSource()));
  138. }
  139. //===----------------------------------------------------------------------===//
  140. // OMPCapturedExprDecl Implementation.
  141. //===----------------------------------------------------------------------===//
  142. void OMPCapturedExprDecl::anchor() {}
  143. OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
  144. IdentifierInfo *Id, QualType T,
  145. SourceLocation StartLoc) {
  146. return new (C, DC) OMPCapturedExprDecl(
  147. C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
  148. }
  149. OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
  150. unsigned ID) {
  151. return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
  152. /*TInfo=*/nullptr, SourceLocation());
  153. }
  154. SourceRange OMPCapturedExprDecl::getSourceRange() const {
  155. assert(hasInit());
  156. return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
  157. }