[OPENMP] Rename OMPCapturedFieldDecl to OMPCapturedExprDecl, NFC.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 11 Feb 2016 05:35:55 +0000 (05:35 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 11 Feb 2016 05:35:55 +0000 (05:35 +0000)
OMPCapturedExprDecl allows caopturing not only of fielddecls, but also
other expressions. It also allows to simplify codegen for several
clauses.

llvm-svn: 260492

17 files changed:
clang/include/clang/AST/DeclOpenMP.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DeclNodes.td
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclOpenMP.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/tools/libclang/CIndex.cpp

index ed7cb35..c22a92c 100644 (file)
@@ -87,33 +87,33 @@ public:
   static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
 };
 
-/// Pseudo declaration for capturing of non-static data members in non-static
-/// member functions.
+/// Pseudo declaration for capturing expressions. Also is used for capturing of
+/// non-static data members in non-static member functions.
 ///
 /// Clang supports capturing of variables only, but OpenMP 4.5 allows to
 /// privatize non-static members of current class in non-static member
 /// functions. This pseudo-declaration allows properly handle this kind of
 /// capture by wrapping captured expression into a variable-like declaration.
-class OMPCapturedFieldDecl final : public VarDecl {
+class OMPCapturedExprDecl final : public VarDecl {
   friend class ASTDeclReader;
   void anchor() override;
 
-  OMPCapturedFieldDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
-                       QualType Type)
-      : VarDecl(OMPCapturedField, C, DC, SourceLocation(), SourceLocation(), Id,
+  OMPCapturedExprDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
+                      QualType Type)
+      : VarDecl(OMPCapturedExpr, C, DC, SourceLocation(), SourceLocation(), Id,
                 Type, nullptr, SC_None) {
     setImplicit();
   }
 
 public:
-  static OMPCapturedFieldDecl *Create(ASTContext &C, DeclContext *DC,
-                                      IdentifierInfo *Id, QualType T);
+  static OMPCapturedExprDecl *Create(ASTContext &C, DeclContext *DC,
+                                     IdentifierInfo *Id, QualType T);
 
-  static OMPCapturedFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
-  static bool classofKind(Kind K) { return K == OMPCapturedField; }
+  static bool classofKind(Kind K) { return K == OMPCapturedExpr; }
 };
 
 } // end namespace clang
index ea10df1..1e397ae 100644 (file)
@@ -1434,7 +1434,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
   }
 })
 
-DEF_TRAVERSE_DECL(OMPCapturedFieldDecl, { TRY_TO(TraverseVarHelper(D)); })
+DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
 
 // A helper method for TemplateDecl's children.
 template <typename Derived>
index 490c5f2..a8d4520 100644 (file)
@@ -51,7 +51,7 @@ def Named : Decl<1>;
             : DDecl<VarTemplateSpecialization>;
         def ImplicitParam : DDecl<Var>;
         def ParmVar : DDecl<Var>;
-        def OMPCapturedField : DDecl<Var>;
+        def OMPCapturedExpr : DDecl<Var>;
       def NonTypeTemplateParm : DDecl<Declarator>;
   def Template : DDecl<Named, 1>;
     def RedeclarableTemplate : DDecl<Template, 1>;
index cc663d0..09df537 100644 (file)
@@ -1163,8 +1163,8 @@ namespace clang {
       DECL_EMPTY,
       /// \brief An ObjCTypeParamDecl record.
       DECL_OBJC_TYPE_PARAM,
-      /// \brief An OMPCapturedFieldDecl record.
-      DECL_OMP_CAPTUREDFIELD,
+      /// \brief An OMPCapturedExprDecl record.
+      DECL_OMP_CAPTUREDEXPR
     };
 
     /// \brief Record codes for each kind of statement or expression.
index b699bec..58c3cc3 100644 (file)
@@ -655,7 +655,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
     case ObjCCategoryImpl:
     case Import:
     case OMPThreadPrivate:
-    case OMPCapturedField:
+    case OMPCapturedExpr:
     case Empty:
       // Never looked up by name.
       return 0;
index 33677ba..2c47410 100644 (file)
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 /// \file
-/// \brief This file implements OMPThreadPrivateDecl, OMPCapturedFieldDecl
+/// \brief This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
 /// classes.
 ///
 //===----------------------------------------------------------------------===//
@@ -54,20 +54,19 @@ void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
 }
 
 //===----------------------------------------------------------------------===//
-// OMPCapturedFieldDecl Implementation.
+// OMPCapturedExprDecl Implementation.
 //===----------------------------------------------------------------------===//
 
-void OMPCapturedFieldDecl::anchor() {}
+void OMPCapturedExprDecl::anchor() {}
 
-OMPCapturedFieldDecl *OMPCapturedFieldDecl::Create(ASTContext &C,
-                                                   DeclContext *DC,
-                                                   IdentifierInfo *Id,
-                                                   QualType T) {
-  return new (C, DC) OMPCapturedFieldDecl(C, DC, Id, T);
+OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
+                                                 IdentifierInfo *Id,
+                                                 QualType T) {
+  return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T);
 }
 
-OMPCapturedFieldDecl *OMPCapturedFieldDecl::CreateDeserialized(ASTContext &C,
-                                                               unsigned ID) {
-  return new (C, ID) OMPCapturedFieldDecl(C, nullptr, nullptr, QualType());
+OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
+                                                             unsigned ID) {
+  return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType());
 }
 
index 1a0e148..7694084 100644 (file)
@@ -92,7 +92,7 @@ namespace {
     void VisitUsingDecl(UsingDecl *D);
     void VisitUsingShadowDecl(UsingShadowDecl *D);
     void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
-    void VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D);
+    void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
 
     void PrintTemplateParameters(const TemplateParameterList *Params,
                                  const TemplateArgumentList *Args = nullptr);
@@ -1367,7 +1367,7 @@ void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
   }
 }
 
-void DeclPrinter::VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D) {
+void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
   D->getInit()->printPretty(Out, nullptr, Policy, Indentation);
 }
 
index 830eeb9..a45b9a2 100644 (file)
@@ -768,8 +768,8 @@ void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
     assert(*I && "Expected non-null Stmt");
     OS << (I == Node->varlist_begin() ? StartSym : ',');
     if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
-      if (auto *CFD = dyn_cast<OMPCapturedFieldDecl>(DRE->getDecl()))
-        CFD->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy, 0);
+      if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl()))
+        CED->getInit()->printPretty(OS, nullptr, Policy, 0);
       else
         DRE->getDecl()->printQualifiedName(OS);
     } else
index 3d84b26..5b88ef1 100644 (file)
@@ -92,7 +92,7 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
   case Decl::Label:        // __label__ x;
   case Decl::Import:
   case Decl::OMPThreadPrivate:
-  case Decl::OMPCapturedField:
+  case Decl::OMPCapturedExpr:
   case Decl::Empty:
     // None of these decls require codegen support.
     return;
index 46b7923..b378cc6 100644 (file)
@@ -1535,16 +1535,10 @@ emitScheduleClause(CodeGenFunction &CGF, const OMPLoopDirective &S,
     M2 = C->getSecondScheduleModifier();
     if (const auto *Ch = C->getChunkSize()) {
       if (auto *ImpRef = cast_or_null<DeclRefExpr>(C->getHelperChunkSize())) {
-        if (OuterRegion) {
-          const VarDecl *ImpVar = cast<VarDecl>(ImpRef->getDecl());
-          CGF.EmitVarDecl(*ImpVar);
-          CGF.EmitStoreThroughLValue(
-              CGF.EmitAnyExpr(Ch),
-              CGF.MakeAddrLValue(CGF.GetAddrOfLocalVar(ImpVar),
-                                 ImpVar->getType()));
-        } else {
+        if (OuterRegion)
+          CGF.EmitVarDecl(*cast<VarDecl>(ImpRef->getDecl()));
+        else
           Ch = ImpRef;
-        }
       }
       if (!C->getHelperChunkSize() || !OuterRegion) {
         Chunk = CGF.EmitScalarExpr(Ch);
index 0c17aa1..cbbe79a 100644 (file)
@@ -2874,7 +2874,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
     case Decl::Var:
     case Decl::VarTemplateSpecialization:
     case Decl::VarTemplatePartialSpecialization:
-    case Decl::OMPCapturedField:
+    case Decl::OMPCapturedExpr:
       // In C, "extern void blah;" is valid and is an r-value.
       if (!getLangOpts().CPlusPlus &&
           !type.hasQualifiers() &&
index 17d4d3c..41013c4 100644 (file)
@@ -1714,6 +1714,30 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
   }
 }
 
+static DeclRefExpr *buildCapture(Sema &S, IdentifierInfo *Id,
+                                 Expr *CaptureExpr) {
+  ASTContext &C = S.getASTContext();
+  Expr *Init = CaptureExpr->IgnoreImpCasts();
+  QualType Ty = Init->getType();
+  if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) {
+    if (S.getLangOpts().CPlusPlus)
+      Ty = C.getLValueReferenceType(Ty);
+    else {
+      Ty = C.getPointerType(Ty);
+      ExprResult Res =
+          S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
+      if (!Res.isUsable())
+        return nullptr;
+      Init = Res.get();
+    }
+  }
+  auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty);
+  S.CurContext->addHiddenDecl(CED);
+  S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false,
+                         /*TypeMayContainAuto=*/true);
+  return buildDeclRefExpr(S, CED, Ty.getNonReferenceType(), SourceLocation());
+}
+
 StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
                                       ArrayRef<OMPClause *> Clauses) {
   if (!S.isUsable()) {
@@ -1740,13 +1764,18 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
       }
       DSAStack->setForceVarCapturing(/*V=*/false);
     } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) &&
-               Clause->getClauseKind() == OMPC_schedule) {
+               (Clause->getClauseKind() == OMPC_schedule ||
+                Clause->getClauseKind() == OMPC_dist_schedule)) {
       // Mark all variables in private list clauses as used in inner region.
       // Required for proper codegen of combined directives.
       // TODO: add processing for other clauses.
-      if (auto *E = cast_or_null<Expr>(
-              cast<OMPScheduleClause>(Clause)->getHelperChunkSize()))
-        MarkDeclarationsReferencedInExpr(E);
+      if (auto *SC = dyn_cast<OMPScheduleClause>(Clause)) {
+        if (SC->getHelperChunkSize())
+          MarkDeclarationsReferencedInExpr(SC->getHelperChunkSize());
+      } else if (auto *DSC = dyn_cast<OMPDistScheduleClause>(Clause)) {
+        if (DSC->getHelperChunkSize())
+          MarkDeclarationsReferencedInExpr(DSC->getHelperChunkSize());
+      }
     }
     if (Clause->getClauseKind() == OMPC_schedule)
       SC = cast<OMPScheduleClause>(Clause);
@@ -6735,12 +6764,8 @@ OMPClause *Sema::ActOnOpenMPScheduleClause(
           return nullptr;
         }
       } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) {
-        auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(),
-                                    ChunkSize->getType(), ".chunk.");
-        auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(),
-                                           ChunkSize->getExprLoc(),
-                                           /*RefersToCapture=*/true);
-        HelperValExpr = ImpVarRef;
+        HelperValExpr =
+            buildCapture(*this, &Context.Idents.get(".chunk."), ValExpr);
       }
     }
   }
@@ -6973,30 +6998,6 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
   return Res;
 }
 
-static DeclRefExpr *buildCapture(Sema &S, IdentifierInfo *Id,
-                                 Expr *CaptureExpr) {
-  ASTContext &C = S.getASTContext();
-  Expr *Init = CaptureExpr->IgnoreImpCasts();
-  QualType Ty = Init->getType();
-  if (CaptureExpr->getObjectKind() == OK_Ordinary) {
-    if (S.getLangOpts().CPlusPlus)
-      Ty = C.getLValueReferenceType(Ty);
-    else {
-      Ty = C.getPointerType(Ty);
-      ExprResult Res =
-          S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
-      if (!Res.isUsable())
-        return nullptr;
-      Init = Res.get();
-    }
-  }
-  auto *CFD = OMPCapturedFieldDecl::Create(C, S.CurContext, Id, Ty);
-  S.CurContext->addHiddenDecl(CFD);
-  S.AddInitializerToDecl(CFD, Init, /*DirectInit=*/false,
-                         /*TypeMayContainAuto=*/true);
-  return buildDeclRefExpr(S, CFD, Ty.getNonReferenceType(), SourceLocation());
-}
-
 ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK,
                                        ExprObjectKind OK) {
   SourceLocation Loc = Capture->getInit()->getExprLoc();
@@ -9549,12 +9550,8 @@ OMPClause *Sema::ActOnOpenMPDistScheduleClause(
           return nullptr;
         }
       } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) {
-        auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(),
-                                    ChunkSize->getType(), ".chunk.");
-        auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(),
-                                           ChunkSize->getExprLoc(),
-                                           /*RefersToCapture=*/true);
-        HelperValExpr = ImpVarRef;
+        HelperValExpr =
+            buildCapture(*this, &Context.Idents.get(".chunk."), ValExpr);
       }
     }
   }
index 0f011ab..a765500 100644 (file)
@@ -2483,8 +2483,8 @@ Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl(
   return TD;
 }
 
-Decl *TemplateDeclInstantiator::VisitOMPCapturedFieldDecl(
-    OMPCapturedFieldDecl * /*D*/) {
+Decl *TemplateDeclInstantiator::VisitOMPCapturedExprDecl(
+    OMPCapturedExprDecl * /*D*/) {
   llvm_unreachable("Should not be met in templates");
 }
 
index 68621f3..0b4772a 100644 (file)
@@ -329,7 +329,7 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) {
   case Decl::ClassScopeFunctionSpecialization:
   case Decl::Import:
   case Decl::OMPThreadPrivate:
-  case Decl::OMPCapturedField:
+  case Decl::OMPCapturedExpr:
   case Decl::BuiltinTemplate:
     return false;
 
index 074de1a..7aa6d52 100644 (file)
@@ -350,7 +350,7 @@ namespace clang {
     void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
     void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
     void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
-    void VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D);
+    void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
 
     /// We've merged the definition \p MergedDef into the existing definition
     /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made
@@ -2361,7 +2361,7 @@ void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
   D->setVars(Vars);
 }
 
-void ASTDeclReader::VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D) {
+void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
   VisitVarDecl(D);
 }
 
@@ -3328,8 +3328,8 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
   case DECL_OMP_THREADPRIVATE:
     D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record[Idx++]);
     break;
-  case DECL_OMP_CAPTUREDFIELD:
-    D = OMPCapturedFieldDecl::CreateDeserialized(Context, ID);
+  case DECL_OMP_CAPTUREDEXPR:
+    D = OMPCapturedExprDecl::CreateDeserialized(Context, ID);
     break;
   case DECL_EMPTY:
     D = EmptyDecl::CreateDeserialized(Context, ID);
index 4620f56..f2f4a02 100644 (file)
@@ -131,7 +131,7 @@ namespace clang {
     void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
     void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
     void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
-    void VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D);
+    void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
 
     /// Add an Objective-C type parameter list to the given record.
     void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
@@ -1629,9 +1629,9 @@ void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
   Code = serialization::DECL_OMP_THREADPRIVATE;
 }
 
-void ASTDeclWriter::VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D) {
+void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
   VisitVarDecl(D);
-  Code = serialization::DECL_OMP_CAPTUREDFIELD;
+  Code = serialization::DECL_OMP_CAPTUREDEXPR;
 }
 
 //===----------------------------------------------------------------------===//
index 9c1efd1..6f28005 100644 (file)
@@ -5670,7 +5670,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) {
   case Decl::StaticAssert:
   case Decl::Block:
   case Decl::Captured:
-  case Decl::OMPCapturedField:
+  case Decl::OMPCapturedExpr:
   case Decl::Label:  // FIXME: Is this right??
   case Decl::ClassScopeFunctionSpecialization:
   case Decl::Import: