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
}
})
-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>
: 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>;
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.
case ObjCCategoryImpl:
case Import:
case OMPThreadPrivate:
- case OMPCapturedField:
+ case OMPCapturedExpr:
case Empty:
// Never looked up by name.
return 0;
//
//===----------------------------------------------------------------------===//
/// \file
-/// \brief This file implements OMPThreadPrivateDecl, OMPCapturedFieldDecl
+/// \brief This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
/// classes.
///
//===----------------------------------------------------------------------===//
}
//===----------------------------------------------------------------------===//
-// 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());
}
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);
}
}
-void DeclPrinter::VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D) {
+void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
D->getInit()->printPretty(Out, nullptr, Policy, Indentation);
}
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
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;
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);
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() &&
}
}
+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()) {
}
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);
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);
}
}
}
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();
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);
}
}
}
return TD;
}
-Decl *TemplateDeclInstantiator::VisitOMPCapturedFieldDecl(
- OMPCapturedFieldDecl * /*D*/) {
+Decl *TemplateDeclInstantiator::VisitOMPCapturedExprDecl(
+ OMPCapturedExprDecl * /*D*/) {
llvm_unreachable("Should not be met in templates");
}
case Decl::ClassScopeFunctionSpecialization:
case Decl::Import:
case Decl::OMPThreadPrivate:
- case Decl::OMPCapturedField:
+ case Decl::OMPCapturedExpr:
case Decl::BuiltinTemplate:
return false;
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
D->setVars(Vars);
}
-void ASTDeclReader::VisitOMPCapturedFieldDecl(OMPCapturedFieldDecl *D) {
+void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
VisitVarDecl(D);
}
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);
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) {
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;
}
//===----------------------------------------------------------------------===//
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: