@@ -17054,6 +17054,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1705417054 SourceLocation EndLoc = Locs.EndLoc;
1705517055 OMPClause *Res = nullptr;
1705617056 int ExtraModifier = Data.ExtraModifier;
17057+ int OriginalSharingModifier = Data.OriginalSharingModifier;
1705717058 SourceLocation ExtraModifierLoc = Data.ExtraModifierLoc;
1705817059 SourceLocation ColonLoc = Data.ColonLoc;
1705917060 switch (Kind) {
@@ -17079,7 +17080,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1707917080 Res = ActOnOpenMPReductionClause(
1708017081 VarList, static_cast<OpenMPReductionClauseModifier>(ExtraModifier),
1708117082 StartLoc, LParenLoc, ExtraModifierLoc, ColonLoc, EndLoc,
17082- Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId);
17083+ Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, {},
17084+ static_cast<OpenMPOriginalSharingModifier>(OriginalSharingModifier));
1708317085 break;
1708417086 case OMPC_task_reduction:
1708517087 Res = ActOnOpenMPTaskReductionClause(
@@ -18220,6 +18222,8 @@ namespace {
1822018222struct ReductionData {
1822118223 /// List of original reduction items.
1822218224 SmallVector<Expr *, 8> Vars;
18225+ /// OpenMP 6.0 List of internal shared private reduction items
18226+ SmallVector<Expr *, 8> VarsTmp;
1822318227 /// List of private copies of the reduction items.
1822418228 SmallVector<Expr *, 8> Privates;
1822518229 /// LHS expressions for the reduction_op expressions.
@@ -18243,9 +18247,12 @@ struct ReductionData {
1824318247 SmallVector<Expr *, 4> ExprPostUpdates;
1824418248 /// Reduction modifier.
1824518249 unsigned RedModifier = 0;
18250+ /// OpenMP 6.9 Original sharing modifier
18251+ unsigned OrigSharingModifier = 0;
1824618252 ReductionData() = delete;
1824718253 /// Reserves required memory for the reduction data.
18248- ReductionData(unsigned Size, unsigned Modifier = 0) : RedModifier(Modifier) {
18254+ ReductionData(unsigned Size, unsigned Modifier = 0, unsigned OrgModifier = 0) : RedModifier(Modifier),
18255+ OrigSharingModifier(OrgModifier) {
1824918256 Vars.reserve(Size);
1825018257 Privates.reserve(Size);
1825118258 LHSs.reserve(Size);
@@ -18256,6 +18263,9 @@ struct ReductionData {
1825618263 InscanCopyArrayTemps.reserve(Size);
1825718264 InscanCopyArrayElems.reserve(Size);
1825818265 }
18266+ if( OrigSharingModifier == OMPC_ORIGINAL_SHARING_private){
18267+ VarsTmp.reserve(Size);
18268+ }
1825918269 TaskgroupDescriptors.reserve(Size);
1826018270 ExprCaptures.reserve(Size);
1826118271 ExprPostUpdates.reserve(Size);
@@ -18274,6 +18284,10 @@ struct ReductionData {
1827418284 InscanCopyArrayTemps.push_back(nullptr);
1827518285 InscanCopyArrayElems.push_back(nullptr);
1827618286 }
18287+ // To be analyze later
18288+ if( OrigSharingModifier == OMPC_ORIGINAL_SHARING_private){
18289+ VarsTmp.emplace_back(Item);
18290+ }
1827718291 }
1827818292 /// Stores reduction data.
1827918293 void push(Expr *Item, Expr *Private, Expr *LHS, Expr *RHS, Expr *ReductionOp,
@@ -18599,7 +18613,7 @@ static bool actOnOMPReductionKindClause(
1859918613 S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced);
1860018614 continue;
1860118615 }
18602- if (DVar.CKind != OMPC_unknown) {
18616+ if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared ) {
1860318617 S.Diag(ELoc, diag::err_omp_wrong_dsa)
1860418618 << getOpenMPClauseName(DVar.CKind)
1860518619 << getOpenMPClauseName(OMPC_reduction);
@@ -18611,7 +18625,7 @@ static bool actOnOMPReductionKindClause(
1861118625 // A list item that appears in a reduction clause of a worksharing
1861218626 // construct must be shared in the parallel regions to which any of the
1861318627 // worksharing regions arising from the worksharing construct bind.
18614- if (isOpenMPWorksharingDirective(CurrDir) &&
18628+ if (RD.OrigSharingModifier !=OMPC_ORIGINAL_SHARING_private && isOpenMPWorksharingDirective(CurrDir) &&
1861518629 !isOpenMPParallelDirective(CurrDir) &&
1861618630 !isOpenMPTeamsDirective(CurrDir)) {
1861718631 DVar = Stack->getImplicitDSA(D, true);
@@ -19117,7 +19131,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
1911719131 SourceLocation StartLoc, SourceLocation LParenLoc,
1911819132 SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1911919133 CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId,
19120- ArrayRef<Expr *> UnresolvedReductions) {
19134+ ArrayRef<Expr *> UnresolvedReductions, OpenMPOriginalSharingModifier OriginalSharingMod ) {
1912119135 if (ModifierLoc.isValid() && Modifier == OMPC_REDUCTION_unknown) {
1912219136 Diag(LParenLoc, diag::err_omp_unexpected_clause_value)
1912319137 << getListOfPossibleValues(OMPC_reduction, /*First=*/0,
@@ -19130,7 +19144,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
1913019144 // worksharing-loop construct, a worksharing-loop SIMD construct, a simd
1913119145 // construct, a parallel worksharing-loop construct or a parallel
1913219146 // worksharing-loop SIMD construct.
19133- if (Modifier == OMPC_REDUCTION_inscan &&
19147+ if ((Modifier == OMPC_REDUCTION_inscan || OriginalSharingMod == OMPC_ORIGINAL_SHARING_private
19148+ || OriginalSharingMod == OMPC_ORIGINAL_SHARING_shared ) &&
1913419149 (DSAStack->getCurrentDirective() != OMPD_for &&
1913519150 DSAStack->getCurrentDirective() != OMPD_for_simd &&
1913619151 DSAStack->getCurrentDirective() != OMPD_simd &&
@@ -19139,9 +19154,41 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
1913919154 Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
1914019155 return nullptr;
1914119156 }
19142-
19143- ReductionData RD(VarList.size(), Modifier);
19144- if (actOnOMPReductionKindClause(SemaRef, DSAStack, OMPC_reduction, VarList,
19157+
19158+ SmallVector<Expr *, 4> ProcessedVarList;
19159+ for (Expr *E : VarList) {
19160+ DeclRefExpr *OrigDRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts());
19161+ if( !OrigDRE ){
19162+ ProcessedVarList.push_back(E);
19163+ continue;
19164+ }
19165+ ValueDecl *OrigDecl = OrigDRE->getDecl();
19166+ DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(OrigDecl, true);
19167+ if (DVar.CKind == OMPC_private || DVar.CKind == OMPC_firstprivate ||
19168+ OriginalSharingMod == OMPC_ORIGINAL_SHARING_private )
19169+ {
19170+
19171+ VarDecl *SharedVar = buildVarDecl(SemaRef, E->getExprLoc(), E->getType(),
19172+ ".omp.reduction.shared.tmp", nullptr, nullptr);
19173+ SemaRef.getCurScope()->AddDecl(SharedVar);
19174+ SharedVar->setImplicit();
19175+ DeclRefExpr* SharedRef = buildDeclRefExpr(SemaRef, SharedVar,
19176+ SharedVar->getType(),
19177+ E->getExprLoc());
19178+ DSAStack->addDSA(SharedVar, nullptr, OMPC_shared);
19179+ ExprResult Init = SemaRef.BuildBinOp( SemaRef.getCurScope(), OrigDRE->getBeginLoc(), BO_Assign, static_cast<Expr*>(SharedRef), E);
19180+ if (!Init.isInvalid())
19181+ SemaRef.AddInitializerToDecl(SharedVar, Init.get(), false);
19182+
19183+ ProcessedVarList.push_back(static_cast<Expr*>(SharedRef));
19184+ }
19185+ else
19186+ {
19187+ ProcessedVarList.push_back(E);
19188+ }
19189+ }
19190+ ReductionData RD(ProcessedVarList.size(), Modifier, OriginalSharingMod );
19191+ if (actOnOMPReductionKindClause(SemaRef, DSAStack, OMPC_reduction, ProcessedVarList,
1914519192 StartLoc, LParenLoc, ColonLoc, EndLoc,
1914619193 ReductionIdScopeSpec, ReductionId,
1914719194 UnresolvedReductions, RD))
0 commit comments