-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inital support for privavate variable reduction #127740
Draft
chandraghale
wants to merge
1
commit into
llvm:main
Choose a base branch
from
chandraghale:private_var_reduction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:git-clang-format --diff d34f7ead886aaaca50f672c47e4f97e078d574db cf392f05f9499fd0621ffec91a3b852d4b91820b --extensions cpp,h -- clang/include/clang/Basic/OpenMPKinds.h clang/include/clang/Sema/SemaOpenMP.h clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp View the diff from clang-format here.diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h
index 40e300f099..5e4ec759ff 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1136,7 +1136,7 @@ public:
DeclarationNameInfo ReductionOrMapperId;
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
///< lastprivate clause.
- int OriginalSharingModifier = 0; // Default is shared
+ int OriginalSharingModifier = 0; // Default is shared
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapTypeModifiers;
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
@@ -1199,8 +1199,9 @@ public:
SourceLocation ModifierLoc, SourceLocation ColonLoc,
SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
const DeclarationNameInfo &ReductionId,
- ArrayRef<Expr *> UnresolvedReductions = {},
- OpenMPOriginalSharingModifier OriginalShareModifier = OMPC_ORIGINAL_SHARING_default);
+ ArrayRef<Expr *> UnresolvedReductions = {},
+ OpenMPOriginalSharingModifier OriginalShareModifier =
+ OMPC_ORIGINAL_SHARING_default);
/// Called on well-formed 'task_reduction' clause.
OMPClause *ActOnOpenMPTaskReductionClause(
ArrayRef<Expr *> VarList, SourceLocation StartLoc,
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index f59ecd93de..b6f53c5a9a 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4595,32 +4595,31 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
(void)ConsumeToken();
}
// Handle original(private / shared) Modifier
- if (Kind == OMPC_reduction && getLangOpts().OpenMP >= 60 &&
+ if (Kind == OMPC_reduction && getLangOpts().OpenMP >= 60 &&
Tok.is(tok::identifier) && PP.getSpelling(Tok) == "original" &&
NextToken().is(tok::l_paren)) {
// Parse original(private) modifier.
- ConsumeToken();
+ ConsumeToken();
BalancedDelimiterTracker ParenT(*this, tok::l_paren, tok::r_paren);
ParenT.consumeOpen();
if (Tok.is(tok::kw_private)) {
Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_private;
Data.OriginalSharingModifierLoc = Tok.getLocation();
- ConsumeToken();
- }
- else if (Tok.is(tok::identifier) && PP.getSpelling(Tok) == "shared") {
+ ConsumeToken();
+ } else if (Tok.is(tok::identifier) && PP.getSpelling(Tok) == "shared") {
Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_shared;
Data.OriginalSharingModifierLoc = Tok.getLocation();
- ConsumeToken();
+ ConsumeToken();
} else {
Diag(Tok.getLocation(), diag::err_expected) << "'private or shared'";
SkipUntil(tok::r_paren);
return false;
- }
+ }
ParenT.consumeClose();
assert(Tok.is(tok::comma) && "Expected comma.");
(void)ConsumeToken();
- }
-
+ }
+
ColonProtectionRAIIObject ColonRAII(*this);
if (getLangOpts().CPlusPlus)
ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4daaf44d7c..3a3eb7f044 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -18251,8 +18251,8 @@ struct ReductionData {
unsigned OrigSharingModifier = 0;
ReductionData() = delete;
/// Reserves required memory for the reduction data.
- ReductionData(unsigned Size, unsigned Modifier = 0, unsigned OrgModifier = 0) : RedModifier(Modifier),
- OrigSharingModifier(OrgModifier) {
+ ReductionData(unsigned Size, unsigned Modifier = 0, unsigned OrgModifier = 0)
+ : RedModifier(Modifier), OrigSharingModifier(OrgModifier) {
Vars.reserve(Size);
Privates.reserve(Size);
LHSs.reserve(Size);
@@ -18263,7 +18263,7 @@ struct ReductionData {
InscanCopyArrayTemps.reserve(Size);
InscanCopyArrayElems.reserve(Size);
}
- if( OrigSharingModifier == OMPC_ORIGINAL_SHARING_private){
+ if (OrigSharingModifier == OMPC_ORIGINAL_SHARING_private) {
VarsTmp.reserve(Size);
}
TaskgroupDescriptors.reserve(Size);
@@ -18284,8 +18284,8 @@ struct ReductionData {
InscanCopyArrayTemps.push_back(nullptr);
InscanCopyArrayElems.push_back(nullptr);
}
- // To be analyze later
- if( OrigSharingModifier == OMPC_ORIGINAL_SHARING_private){
+ // To be analyze later
+ if (OrigSharingModifier == OMPC_ORIGINAL_SHARING_private) {
VarsTmp.emplace_back(Item);
}
}
@@ -18625,7 +18625,8 @@ static bool actOnOMPReductionKindClause(
// A list item that appears in a reduction clause of a worksharing
// construct must be shared in the parallel regions to which any of the
// worksharing regions arising from the worksharing construct bind.
- if (RD.OrigSharingModifier !=OMPC_ORIGINAL_SHARING_private && isOpenMPWorksharingDirective(CurrDir) &&
+ if (RD.OrigSharingModifier != OMPC_ORIGINAL_SHARING_private &&
+ isOpenMPWorksharingDirective(CurrDir) &&
!isOpenMPParallelDirective(CurrDir) &&
!isOpenMPTeamsDirective(CurrDir)) {
DVar = Stack->getImplicitDSA(D, true);
@@ -19131,7 +19132,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId,
- ArrayRef<Expr *> UnresolvedReductions, OpenMPOriginalSharingModifier OriginalSharingMod ) {
+ ArrayRef<Expr *> UnresolvedReductions,
+ OpenMPOriginalSharingModifier OriginalSharingMod) {
if (ModifierLoc.isValid() && Modifier == OMPC_REDUCTION_unknown) {
Diag(LParenLoc, diag::err_omp_unexpected_clause_value)
<< getListOfPossibleValues(OMPC_reduction, /*First=*/0,
@@ -19144,8 +19146,9 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
// worksharing-loop construct, a worksharing-loop SIMD construct, a simd
// construct, a parallel worksharing-loop construct or a parallel
// worksharing-loop SIMD construct.
- if ((Modifier == OMPC_REDUCTION_inscan || OriginalSharingMod == OMPC_ORIGINAL_SHARING_private
- || OriginalSharingMod == OMPC_ORIGINAL_SHARING_shared ) &&
+ if ((Modifier == OMPC_REDUCTION_inscan ||
+ OriginalSharingMod == OMPC_ORIGINAL_SHARING_private ||
+ OriginalSharingMod == OMPC_ORIGINAL_SHARING_shared) &&
(DSAStack->getCurrentDirective() != OMPD_for &&
DSAStack->getCurrentDirective() != OMPD_for_simd &&
DSAStack->getCurrentDirective() != OMPD_simd &&
@@ -19154,44 +19157,43 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
return nullptr;
}
-
+
SmallVector<Expr *, 4> ProcessedVarList;
for (Expr *E : VarList) {
DeclRefExpr *OrigDRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts());
- if( !OrigDRE ){
+ if (!OrigDRE) {
ProcessedVarList.push_back(E);
continue;
- }
- ValueDecl *OrigDecl = OrigDRE->getDecl();
- DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(OrigDecl, true);
- if (DVar.CKind == OMPC_private || DVar.CKind == OMPC_firstprivate ||
- OriginalSharingMod == OMPC_ORIGINAL_SHARING_private )
- {
-
- VarDecl *SharedVar = buildVarDecl(SemaRef, E->getExprLoc(), E->getType(),
- ".omp.reduction.shared.tmp", nullptr, nullptr);
- SemaRef.getCurScope()->AddDecl(SharedVar);
- SharedVar->setImplicit();
- DeclRefExpr* SharedRef = buildDeclRefExpr(SemaRef, SharedVar,
- SharedVar->getType(),
- E->getExprLoc());
- DSAStack->addDSA(SharedVar, nullptr, OMPC_shared);
- ExprResult Init = SemaRef.BuildBinOp( SemaRef.getCurScope(), OrigDRE->getBeginLoc(), BO_Assign, static_cast<Expr*>(SharedRef), E);
- if (!Init.isInvalid())
+ }
+ ValueDecl *OrigDecl = OrigDRE->getDecl();
+ DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(OrigDecl, true);
+ if (DVar.CKind == OMPC_private || DVar.CKind == OMPC_firstprivate ||
+ OriginalSharingMod == OMPC_ORIGINAL_SHARING_private) {
+
+ VarDecl *SharedVar =
+ buildVarDecl(SemaRef, E->getExprLoc(), E->getType(),
+ ".omp.reduction.shared.tmp", nullptr, nullptr);
+ SemaRef.getCurScope()->AddDecl(SharedVar);
+ SharedVar->setImplicit();
+ DeclRefExpr *SharedRef = buildDeclRefExpr(
+ SemaRef, SharedVar, SharedVar->getType(), E->getExprLoc());
+ DSAStack->addDSA(SharedVar, nullptr, OMPC_shared);
+ ExprResult Init =
+ SemaRef.BuildBinOp(SemaRef.getCurScope(), OrigDRE->getBeginLoc(),
+ BO_Assign, static_cast<Expr *>(SharedRef), E);
+ if (!Init.isInvalid())
SemaRef.AddInitializerToDecl(SharedVar, Init.get(), false);
- ProcessedVarList.push_back(static_cast<Expr*>(SharedRef));
- }
- else
- {
- ProcessedVarList.push_back(E);
- }
+ ProcessedVarList.push_back(static_cast<Expr *>(SharedRef));
+ } else {
+ ProcessedVarList.push_back(E);
+ }
}
- ReductionData RD(ProcessedVarList.size(), Modifier, OriginalSharingMod );
- if (actOnOMPReductionKindClause(SemaRef, DSAStack, OMPC_reduction, ProcessedVarList,
- StartLoc, LParenLoc, ColonLoc, EndLoc,
- ReductionIdScopeSpec, ReductionId,
- UnresolvedReductions, RD))
+ ReductionData RD(ProcessedVarList.size(), Modifier, OriginalSharingMod);
+ if (actOnOMPReductionKindClause(SemaRef, DSAStack, OMPC_reduction,
+ ProcessedVarList, StartLoc, LParenLoc,
+ ColonLoc, EndLoc, ReductionIdScopeSpec,
+ ReductionId, UnresolvedReductions, RD))
return nullptr;
return OMPReductionClause::Create(
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.