This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP] Codegen for 'private' clause in 'parallel' directive
ClosedPublic

Authored by ABataev on Aug 1 2014, 4:36 AM.

Details

Summary

This patch generates some helper variables which used as a private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by default (with the default constructor, if any). In outlined function references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables and implicit barier is set by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables.

Diff Detail

Repository
rL LLVM

Event Timeline

ABataev updated this revision to Diff 12099.Aug 1 2014, 4:36 AM
ABataev retitled this revision from to [OPENMP] Codegen for 'private' clause in 'parallel' directive.
ABataev updated this object.
ABataev edited the test plan for this revision. (Show Details)
ABataev added a subscriber: Unknown Object (MLST).
ajayj added a subscriber: ajayj.Aug 27 2014, 11:46 AM

Alexey,

I have a question on the code sequence from SemaOpenMP.cpp, ActOnOpenMPPrivateClause:

` auto VDPrivate =
VarDecl::Create(Context, CurContext, DE->getLocStart(),
DE->getExprLoc(), VD->getIdentifier(), VD->getType(),
VD->getTypeSourceInfo(), /*S*/ SC_Auto);
ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto*/ false);
if (VD->isInvalidDecl())
continue;

CurContext->addDecl(VDPrivate);`

Should the VD->isInvalidDecl() check be moved before the VarDecl::Create(...)? It appears that there is no need to create VDPrivate if the declaration is invalid and we don't add it via addDecl.

Ajay

Ajay, thanks for the review. There must be a check for VDPrivate after
applying default initialization, not VD. I'll fix it.

Best regards,

Alexey Bataev

Software Engineer
Intel Compiler Team

27.08.2014 22:46, Ajay Jayaraj пишет:

Alexey,

I have a question on the code sequence from SemaOpenMP.cpp, ActOnOpenMPPrivateClause:

` auto VDPrivate =

VarDecl::Create(Context, CurContext, DE->getLocStart(),
DE->getExprLoc(), VD->getIdentifier(), VD->getType(),
VD->getTypeSourceInfo(), /*S*/ SC_Auto);
ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto*/ false);
if (VD->isInvalidDecl())
continue;

CurContext->addDecl(VDPrivate);`

Should the VD->isInvalidDecl() check be moved before the VarDecl::Create(...)? It appears that there is no need to create VDPrivate if the declaration is invalid and we don't add it via addDecl.

Ajay

http://reviews.llvm.org/D4752

ABataev updated this revision to Diff 13020.Aug 27 2014, 8:27 PM

Replaced check for VD->isInvalidDecl() by VDPrivate->isInvalidDecl() after applying default initialization.

Looks good to me from an OpenMP perspective. Was able to build with the patch and run some tests.

However, I'm not a clang expert and someone with knowledge of clang internals should also take a look at this patch.

Regds,
Ajay Jayaraj
Texas Instruments

hfinkel edited edge metadata.Sep 22 2014, 1:51 AM

Please separate out the Sema changes into a separate patch.

lib/CodeGen/CGStmtOpenMP.cpp
52 ↗(On Diff #13020)

The note in the patch summary, that this is to ensure all threads initialize using the original values of the variables, is more informative than this comment.

lib/Serialization/ASTWriterStmt.cpp
1755 ↗(On Diff #13020)

Don't need {}

1758 ↗(On Diff #13020)

Don't need {}

ABataev added inline comments.Sep 24 2014, 9:03 PM
lib/CodeGen/CGStmtOpenMP.cpp
52 ↗(On Diff #13020)

Ok, I'll add another comment.

lib/Serialization/ASTWriterStmt.cpp
1755 ↗(On Diff #13020)

Required for compatibility with MSVC.

1758 ↗(On Diff #13020)

The same.

ABataev updated this revision to Diff 14062.Sep 24 2014, 9:50 PM
ABataev edited edge metadata.

Update after review

ABataev updated this revision to Diff 14094.Sep 25 2014, 9:26 PM

Added a comment for new private variable.

hfinkel accepted this revision.Oct 7 2014, 6:00 AM
hfinkel edited edge metadata.

LGTM, thanks! (obviously there is some overlap with D5140, you might want to factor out the common pieces and commit them first -- just note in the commit message that tests will follow in the subsequent commits).

lib/Sema/SemaOpenMP.cpp
3137 ↗(On Diff #14094)

in the CodeGen -> in CodeGen
Missing space before "This"

This revision is now accepted and ready to land.Oct 7 2014, 6:00 AM
hfinkel added inline comments.Oct 7 2014, 6:08 AM
lib/Sema/SemaOpenMP.cpp
3139 ↗(On Diff #14094)

Also, "proper diagnostics" I understand (we don't want diagnostic messages saying that variables are declared inside of OpenMP clauses -- that would get confusing). I don't understand what you mean here by "variable capturing", but I also thing the point is: how much do we want the presence of the OpenMP clauses to affect the AST, and regarding adding an extra layer of indirection for all variables inside the clause when -fopenmp is enabled, I think it makes sense that we don't want that.

Hal, thanks for the review!

lib/Sema/SemaOpenMP.cpp
3137 ↗(On Diff #14094)

Ok, fixed.

3139 ↗(On Diff #14094)

Agree. I'm thinking on small redesign of var capturing.

ABataev closed this revision.Oct 20 2014, 8:27 PM
ABataev updated this revision to Diff 15165.

Closed by commit rL220262 (authored by @ABataev).