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.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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
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
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 {} |
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 |
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. |