@@ -47,6 +47,7 @@ class DSAStackTy {
47
47
OmpSsClauseKind CKind = OSSC_unknown;
48
48
const Expr *RefExpr = nullptr ;
49
49
bool Ignore = false ;
50
+ bool Implicit = false ;
50
51
DSAVarData () = default ;
51
52
DSAVarData (OmpSsDirectiveKind DKind, OmpSsClauseKind CKind,
52
53
const Expr *RefExpr, bool Ignore)
@@ -59,6 +60,7 @@ class DSAStackTy {
59
60
OmpSsClauseKind Attributes = OSSC_unknown;
60
61
const Expr * RefExpr;
61
62
bool Ignore = false ;
63
+ bool Implicit = false ;
62
64
};
63
65
using DeclSAMapTy = llvm::SmallDenseMap<const ValueDecl *, DSAInfo, 8 >;
64
66
@@ -106,7 +108,8 @@ class DSAStackTy {
106
108
}
107
109
108
110
// / Adds explicit data sharing attribute to the specified declaration.
109
- void addDSA (const ValueDecl *D, const Expr *E, OmpSsClauseKind A, bool Ignore=false );
111
+ void addDSA (const ValueDecl *D, const Expr *E, OmpSsClauseKind A,
112
+ bool Ignore, bool Implicit);
110
113
111
114
// / Returns data sharing attributes from top of the stack for the
112
115
// / specified declaration.
@@ -180,20 +183,23 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(iterator &Iter,
180
183
const DSAInfo &Data = Iter->SharingMap .lookup (D);
181
184
DVar.RefExpr = Data.RefExpr ;
182
185
DVar.Ignore = Data.Ignore ;
186
+ DVar.Implicit = Data.Implicit ;
183
187
DVar.CKind = Data.Attributes ;
184
188
return DVar;
185
189
}
186
190
187
191
return DVar;
188
192
}
189
193
190
- void DSAStackTy::addDSA (const ValueDecl *D, const Expr *E, OmpSsClauseKind A, bool Ignore) {
194
+ void DSAStackTy::addDSA (const ValueDecl *D, const Expr *E, OmpSsClauseKind A,
195
+ bool Ignore, bool Implicit) {
191
196
D = getCanonicalDecl (D);
192
197
assert (!isStackEmpty () && " Data-sharing attributes stack is empty" );
193
198
DSAInfo &Data = Stack.back ().SharingMap [D];
194
199
Data.Attributes = A;
195
200
Data.RefExpr = E;
196
201
Data.Ignore = Ignore;
202
+ Data.Implicit = Implicit;
197
203
}
198
204
199
205
const DSAStackTy::DSAVarData DSAStackTy::getTopDSA (ValueDecl *D,
@@ -336,13 +342,13 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
336
342
if (isOmpSsTaskingDirective (DKind))
337
343
ImplicitShared.push_back (E);
338
344
// Record DSA as Ignored to avoid making the same node again
339
- Stack->addDSA (VD, E, OSSC_shared, /* Ignore=*/ true );
345
+ Stack->addDSA (VD, E, OSSC_shared, /* Ignore=*/ true , /* Implicit= */ true );
340
346
break ;
341
347
case DSA_none:
342
348
if (!DVarCurrent.Ignore ) {
343
349
SemaRef.Diag (E->getExprLoc (), diag::err_oss_not_defined_dsa_when_default_none) << E->getDecl ();
344
350
// Record DSA as ignored to diagnostic only once
345
- Stack->addDSA (VD, E, OSSC_unknown, /* Ignore=*/ true );
351
+ Stack->addDSA (VD, E, OSSC_unknown, /* Ignore=*/ true , /* Implicit= */ true );
346
352
}
347
353
break ;
348
354
case DSA_unspecified:
@@ -356,7 +362,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
356
362
ImplicitFirstprivate.push_back (E);
357
363
358
364
// Record DSA as Ignored to avoid making the same node again
359
- Stack->addDSA (VD, E, OSSC_firstprivate, /* Ignore=*/ true );
365
+ Stack->addDSA (VD, E, OSSC_firstprivate, /* Ignore=*/ true , /* Implicit= */ true );
360
366
} else {
361
367
// If no default clause is present and the variable was shared/global
362
368
// in the context encountering the construct, the variable will be shared.
@@ -366,7 +372,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
366
372
ImplicitShared.push_back (E);
367
373
368
374
// Record DSA as Ignored to avoid making the same node again
369
- Stack->addDSA (VD, E, OSSC_shared, /* Ignore=*/ true );
375
+ Stack->addDSA (VD, E, OSSC_shared, /* Ignore=*/ true , /* Implicit= */ true );
370
376
}
371
377
}
372
378
}
@@ -479,6 +485,10 @@ class OSSClauseDSAChecker final : public StmtVisitor<OSSClauseDSAChecker, void>
479
485
DSAStackTy::DSAVarData DVarCurrent = Stack->getCurrentDSA (VD);
480
486
switch (DVarCurrent.CKind ) {
481
487
case OSSC_shared:
488
+ if (IsArraySubscriptIdx) {
489
+ // shared(n) in(array[n])
490
+ break ;
491
+ }
482
492
if (VKind == OSSC_private || VKind == OSSC_firstprivate) {
483
493
ErrorFound = true ;
484
494
SemaRef.Diag (ELoc, diag::err_oss_mismatch_depend_dsa)
@@ -489,28 +499,34 @@ class OSSClauseDSAChecker final : public StmtVisitor<OSSClauseDSAChecker, void>
489
499
case OSSC_private:
490
500
case OSSC_firstprivate:
491
501
if (VKind == OSSC_shared) {
492
- ErrorFound = true ;
493
- SemaRef.Diag (ELoc, diag::err_oss_mismatch_depend_dsa)
494
- << getOmpSsClauseName (DVarCurrent.CKind )
495
- << getOmpSsClauseName (VKind) << ERange;
502
+ if (DVarCurrent.Implicit ) {
503
+ // Promote Implicit firstprivate to Implicit shared
504
+ auto It = ImplicitFirstprivate.begin ();
505
+ while (It != ImplicitFirstprivate.end ()) {
506
+ if (*It == DVarCurrent.RefExpr ) break ;
507
+ ++It;
508
+ }
509
+ assert (It != ImplicitFirstprivate.end ());
510
+ ImplicitFirstprivate.erase (It);
511
+
512
+ ImplicitShared.push_back (E);
513
+ // Rewrite DSA
514
+ Stack->addDSA (VD, E, VKind, /* Ignore=*/ false , /* Implicit=*/ true );
515
+ } else {
516
+ ErrorFound = true ;
517
+ SemaRef.Diag (ELoc, diag::err_oss_mismatch_depend_dsa)
518
+ << getOmpSsClauseName (DVarCurrent.CKind )
519
+ << getOmpSsClauseName (VKind) << ERange;
520
+ }
496
521
}
497
522
break ;
498
523
case OSSC_unknown:
499
- // No DSA explicit
500
- if (Stack->getCurrentDefaultDataSharingAttributtes () == DSA_none) {
501
- // KO: but default(none)
502
- // Record DSA as ignored
503
- SemaRef.Diag (ELoc, diag::err_oss_not_defined_dsa_when_default_none) << E->getDecl ();
504
- Stack->addDSA (VD, E, OSSC_unknown, /* Ignore=*/ true );
505
- } else {
506
- // OK: record DSA as explicit
507
- if (VKind == OSSC_shared)
508
- ImplicitShared.push_back (E);
509
- if (VKind == OSSC_firstprivate)
510
- ImplicitFirstprivate.push_back (E);
524
+ if (VKind == OSSC_shared)
525
+ ImplicitShared.push_back (E);
526
+ if (VKind == OSSC_firstprivate)
527
+ ImplicitFirstprivate.push_back (E);
511
528
512
- Stack->addDSA (VD, E, VKind);
513
- }
529
+ Stack->addDSA (VD, E, VKind, /* Ignore=*/ false , /* Implicit=*/ true );
514
530
515
531
break ;
516
532
default :
@@ -595,46 +611,47 @@ void Sema::ActOnOmpSsAfterClauseGathering(SmallVectorImpl<OSSClause *>& Clauses)
595
611
596
612
bool ErrorFound = false ;
597
613
614
+ OSSClauseDSAChecker OSSDependChecker (DSAStack, *this );
598
615
for (auto *Clause : Clauses) {
599
- OSSClauseDSAChecker OSSDependChecker (DSAStack, *this );
600
616
if (isa<OSSDependClause>(Clause)) {
601
617
OSSDependChecker.VisitOSSDepend (cast<OSSDependClause> (Clause));
618
+ }
619
+ // FIXME: how to handle an error?
620
+ if (OSSDependChecker.isErrorFound ())
621
+ ErrorFound = true ;
622
+ }
602
623
603
- if (OSSDependChecker.isErrorFound ())
604
- ErrorFound = true ;
605
624
606
- SmallVector<Expr *, 4 > ImplicitShared (
607
- OSSDependChecker.getImplicitShared ().begin (),
608
- OSSDependChecker.getImplicitShared ().end ());
625
+ SmallVector<Expr *, 4 > ImplicitShared (
626
+ OSSDependChecker.getImplicitShared ().begin (),
627
+ OSSDependChecker.getImplicitShared ().end ());
609
628
610
- SmallVector<Expr *, 4 > ImplicitFirstprivate (
611
- OSSDependChecker.getImplicitFirstprivate ().begin (),
612
- OSSDependChecker.getImplicitFirstprivate ().end ());
629
+ SmallVector<Expr *, 4 > ImplicitFirstprivate (
630
+ OSSDependChecker.getImplicitFirstprivate ().begin (),
631
+ OSSDependChecker.getImplicitFirstprivate ().end ());
613
632
614
- if (!ImplicitShared.empty ()) {
615
- if (OSSClause *Implicit = ActOnOmpSsSharedClause (
616
- ImplicitShared, SourceLocation (), SourceLocation (),
617
- SourceLocation (), /* isImplicit=*/ true )) {
618
- Clauses.push_back (Implicit);
619
- if (cast<OSSSharedClause>(Implicit)->varlist_size () != ImplicitShared.size ())
620
- ErrorFound = true ;
633
+ if (!ImplicitShared.empty ()) {
634
+ if (OSSClause *Implicit = ActOnOmpSsSharedClause (
635
+ ImplicitShared, SourceLocation (), SourceLocation (),
636
+ SourceLocation (), /* isImplicit=*/ true )) {
637
+ Clauses.push_back (Implicit);
638
+ if (cast<OSSSharedClause>(Implicit)->varlist_size () != ImplicitShared.size ())
639
+ ErrorFound = true ;
621
640
622
- } else {
623
- ErrorFound = true ;
624
- }
625
- }
641
+ } else {
642
+ ErrorFound = true ;
643
+ }
644
+ }
626
645
627
- if (!ImplicitFirstprivate.empty ()) {
628
- if (OSSClause *Implicit = ActOnOmpSsFirstprivateClause (
629
- ImplicitFirstprivate, SourceLocation (), SourceLocation (),
630
- SourceLocation ())) {
631
- Clauses.push_back (Implicit);
632
- if (cast<OSSFirstprivateClause>(Implicit)->varlist_size () != ImplicitFirstprivate.size ())
633
- ErrorFound = true ;
634
- } else {
635
- ErrorFound = true ;
636
- }
637
- }
646
+ if (!ImplicitFirstprivate.empty ()) {
647
+ if (OSSClause *Implicit = ActOnOmpSsFirstprivateClause (
648
+ ImplicitFirstprivate, SourceLocation (), SourceLocation (),
649
+ SourceLocation ())) {
650
+ Clauses.push_back (Implicit);
651
+ if (cast<OSSFirstprivateClause>(Implicit)->varlist_size () != ImplicitFirstprivate.size ())
652
+ ErrorFound = true ;
653
+ } else {
654
+ ErrorFound = true ;
638
655
}
639
656
}
640
657
}
@@ -1017,7 +1034,7 @@ Sema::ActOnOmpSsSharedClause(ArrayRef<Expr *> Vars,
1017
1034
<< getOmpSsClauseName (OSSC_shared);
1018
1035
continue ;
1019
1036
}
1020
- DSAStack->addDSA (D, RefExpr, OSSC_shared);
1037
+ DSAStack->addDSA (D, RefExpr, OSSC_shared, /* Ignore= */ false , /* Implicit= */ false );
1021
1038
ClauseVars.push_back (RefExpr);
1022
1039
}
1023
1040
@@ -1055,7 +1072,7 @@ Sema::ActOnOmpSsPrivateClause(ArrayRef<Expr *> Vars,
1055
1072
<< getOmpSsClauseName (OSSC_private);
1056
1073
continue ;
1057
1074
}
1058
- DSAStack->addDSA (D, RefExpr, OSSC_private);
1075
+ DSAStack->addDSA (D, RefExpr, OSSC_private, /* Ignore= */ false , /* Implicit= */ false );
1059
1076
ClauseVars.push_back (RefExpr);
1060
1077
}
1061
1078
@@ -1093,7 +1110,7 @@ Sema::ActOnOmpSsFirstprivateClause(ArrayRef<Expr *> Vars,
1093
1110
<< getOmpSsClauseName (OSSC_firstprivate);
1094
1111
continue ;
1095
1112
}
1096
- DSAStack->addDSA (D, RefExpr, OSSC_firstprivate);
1113
+ DSAStack->addDSA (D, RefExpr, OSSC_firstprivate, /* Ignore= */ false , /* Implicit= */ false );
1097
1114
ClauseVars.push_back (RefExpr);
1098
1115
}
1099
1116
0 commit comments