[PATCH] D11395: [OpenMP] Add capture for threadprivate variables used in copyin clause
Alexey Bataev
a.bataev at hotmail.com
Tue Jul 21 21:24:15 PDT 2015
ABataev added inline comments.
================
Comment at: lib/CodeGen/CGStmtOpenMP.cpp:230-238
@@ -229,6 +229,11 @@
if (CopiedVars.insert(VD->getCanonicalDecl()).second) {
- // Get the address of the master variable.
- auto *MasterAddr = VD->isStaticLocal()
- ? CGM.getStaticLocalDeclAddress(VD)
- : CGM.GetAddrOfGlobal(VD);
+
+ // Get the address of the master variable. It is passed from the master
+ // as field in the captured declaration.
+ auto *FD = CapturedStmtInfo->lookup(VD);
+ assert( FD && "Copyin master value should be available in some field!");
+ QualType TagType = getContext().getTagDeclType(FD->getParent());
+ LValue LV = MakeNaturalAlignAddrLValue(CapturedStmtInfo->getContextValue(), TagType);
+ auto *MasterAddr = EmitLValueForField(LV, FD).getAddress();
+
// Get the address of the threadprivate variable.
----------------
DeclRefExpr DRE(const_cast<VarDecl *>(VD),
CapturedStmtInfo->lookup(VD) != nullptr,
(*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc());
auto *MasterAddr = EmitLValue(&DRE).getAddress();
================
Comment at: lib/Sema/SemaOpenMP.cpp:160-667
@@ -159,4 +159,8 @@
+ /// \brief Check if the specified variable is a 'copyin' variable for current
+ /// region.
+ bool isCopyinVariable(VarDecl *D);
+
/// \brief Adds explicit data sharing attribute to the specified declaration.
void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A);
@@ -412,6 +416,12 @@
return Stack.back().LCVSet.count(D) > 0;
}
+bool DSAStackTy::isCopyinVariable(VarDecl *D){
+ assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");
+ D = D->getCanonicalDecl();
+ DSAInfo I = Stack.back().SharingMap.lookup(D);
+ return I.Attributes == OMPC_copyin;
+}
void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {
D = D->getCanonicalDecl();
if (A == OMPC_threadprivate) {
@@ -653,4 +663,6 @@
assert(LangOpts.OpenMP && "OpenMP is not allowed");
VD = VD->getCanonicalDecl();
if (DSAStack->getCurrentDirective() != OMPD_unknown) {
+ if (DSAStack->isCopyinVariable(VD) && !DSAStack->isClauseParsingMode())
+ return true;
if (DSAStack->isLoopControlVariable(VD) ||
----------------
I'd better write a new function isOpenMPPrivateOrCopyin() function and used it instead of isOpenMPPrivate() in Sema::IsOpenMPCapturedVar(). Besides, note, that copyin variables must be captured only if TLS mode is on, if we're using runtime calls we don't need to capture threadprivates.
http://reviews.llvm.org/D11395
More information about the cfe-commits
mailing list