@@ -59,7 +59,8 @@ enum DefaultDataSharingAttributes {
59
59
DSA_unspecified = 0, /// Data sharing attribute not specified.
60
60
DSA_none = 1 << 0, /// Default data sharing attribute 'none'.
61
61
DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'.
62
- DSA_firstprivate = 1 << 2, /// Default data sharing attribute 'firstprivate'.
62
+ DSA_private = 1 << 2, /// Default data sharing attribute 'private'.
63
+ DSA_firstprivate = 1 << 3, /// Default data sharing attribute 'firstprivate'.
63
64
};
64
65
65
66
/// Stack for tracking declarations used in OpenMP directives and
@@ -695,6 +696,11 @@ class DSAStackTy {
695
696
getTopOfStack().DefaultAttr = DSA_shared;
696
697
getTopOfStack().DefaultAttrLoc = Loc;
697
698
}
699
+ /// Set default data sharing attribute to private.
700
+ void setDefaultDSAPrivate(SourceLocation Loc) {
701
+ getTopOfStack().DefaultAttr = DSA_private;
702
+ getTopOfStack().DefaultAttrLoc = Loc;
703
+ }
698
704
/// Set default data sharing attribute to firstprivate.
699
705
void setDefaultDSAFirstPrivate(SourceLocation Loc) {
700
706
getTopOfStack().DefaultAttr = DSA_firstprivate;
@@ -1233,14 +1239,26 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter,
1233
1239
case DSA_none:
1234
1240
return DVar;
1235
1241
case DSA_firstprivate:
1236
- if (VD->getStorageDuration() == SD_Static &&
1242
+ if (VD && VD ->getStorageDuration() == SD_Static &&
1237
1243
VD->getDeclContext()->isFileContext()) {
1238
1244
DVar.CKind = OMPC_unknown;
1239
1245
} else {
1240
1246
DVar.CKind = OMPC_firstprivate;
1241
1247
}
1242
1248
DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1243
1249
return DVar;
1250
+ case DSA_private:
1251
+ // each variable with static storage duration that is declared
1252
+ // in a namespace or global scope and referenced in the construct,
1253
+ // and that does not have a predetermined data-sharing attribute
1254
+ if (VD && VD->getStorageDuration() == SD_Static &&
1255
+ VD->getDeclContext()->isFileContext()) {
1256
+ DVar.CKind = OMPC_unknown;
1257
+ } else {
1258
+ DVar.CKind = OMPC_private;
1259
+ }
1260
+ DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1261
+ return DVar;
1244
1262
case DSA_unspecified:
1245
1263
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1246
1264
// in a Construct, implicitly determined, p.2]
@@ -2142,7 +2160,8 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
2142
2160
!cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()) &&
2143
2161
// If the variable is implicitly firstprivate and scalar - capture by
2144
2162
// copy
2145
- !(DSAStack->getDefaultDSA() == DSA_firstprivate &&
2163
+ !((DSAStack->getDefaultDSA() == DSA_firstprivate ||
2164
+ DSAStack->getDefaultDSA() == DSA_private) &&
2146
2165
!DSAStack->hasExplicitDSA(
2147
2166
D, [](OpenMPClauseKind K, bool) { return K != OMPC_unknown; },
2148
2167
Level) &&
@@ -2290,11 +2309,13 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
2290
2309
// Global shared must not be captured.
2291
2310
if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_unknown &&
2292
2311
((DSAStack->getDefaultDSA() != DSA_none &&
2312
+ DSAStack->getDefaultDSA() != DSA_private &&
2293
2313
DSAStack->getDefaultDSA() != DSA_firstprivate) ||
2294
2314
DVarTop.CKind == OMPC_shared))
2295
2315
return nullptr;
2296
2316
if (DVarPrivate.CKind != OMPC_unknown ||
2297
2317
(VD && (DSAStack->getDefaultDSA() == DSA_none ||
2318
+ DSAStack->getDefaultDSA() == DSA_private ||
2298
2319
DSAStack->getDefaultDSA() == DSA_firstprivate)))
2299
2320
return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl());
2300
2321
}
@@ -2464,7 +2485,11 @@ bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
2464
2485
unsigned NumLevels =
2465
2486
getOpenMPCaptureLevels(DSAStack->getDirective(Level));
2466
2487
if (Level == 0)
2467
- return (NumLevels == CaptureLevel + 1) && TopDVar.CKind != OMPC_shared;
2488
+ // non-file scope static variale with default(firstprivate)
2489
+ // should be gloabal captured.
2490
+ return (NumLevels == CaptureLevel + 1 &&
2491
+ (TopDVar.CKind != OMPC_shared ||
2492
+ DSAStack->getDefaultDSA() == DSA_firstprivate));
2468
2493
do {
2469
2494
--Level;
2470
2495
DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
@@ -3444,6 +3469,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
3444
3469
CapturedStmt *CS = nullptr;
3445
3470
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
3446
3471
llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
3472
+ llvm::SmallVector<Expr *, 4> ImplicitPrivate;
3447
3473
llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete];
3448
3474
llvm::SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
3449
3475
ImplicitMapModifier[DefaultmapKindNum];
@@ -3539,26 +3565,29 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
3539
3565
// by being listed in a data-sharing attribute clause.
3540
3566
if (DVar.CKind == OMPC_unknown &&
3541
3567
(Stack->getDefaultDSA() == DSA_none ||
3568
+ Stack->getDefaultDSA() == DSA_private ||
3542
3569
Stack->getDefaultDSA() == DSA_firstprivate) &&
3543
3570
isImplicitOrExplicitTaskingRegion(DKind) &&
3544
3571
VarsWithInheritedDSA.count(VD) == 0) {
3545
3572
bool InheritedDSA = Stack->getDefaultDSA() == DSA_none;
3546
- if (!InheritedDSA && Stack->getDefaultDSA() == DSA_firstprivate) {
3573
+ if (!InheritedDSA && (Stack->getDefaultDSA() == DSA_firstprivate ||
3574
+ Stack->getDefaultDSA() == DSA_private)) {
3547
3575
DSAStackTy::DSAVarData DVar =
3548
3576
Stack->getImplicitDSA(VD, /*FromParent=*/false);
3549
3577
InheritedDSA = DVar.CKind == OMPC_unknown;
3550
3578
}
3551
3579
if (InheritedDSA)
3552
3580
VarsWithInheritedDSA[VD] = E;
3553
- return;
3581
+ if (Stack->getDefaultDSA() == DSA_none)
3582
+ return;
3554
3583
}
3555
3584
3556
3585
// OpenMP 5.0 [2.19.7.2, defaultmap clause, Description]
3557
3586
// If implicit-behavior is none, each variable referenced in the
3558
3587
// construct that does not have a predetermined data-sharing attribute
3559
3588
// and does not appear in a to or link clause on a declare target
3560
3589
// directive must be listed in a data-mapping attribute clause, a
3561
- // data-haring attribute clause (including a data-sharing attribute
3590
+ // data-sharing attribute clause (including a data-sharing attribute
3562
3591
// clause on a combined construct where target. is one of the
3563
3592
// constituent constructs), or an is_device_ptr clause.
3564
3593
OpenMPDefaultmapClauseKind ClauseKind =
@@ -3669,10 +3698,16 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
3669
3698
// Define implicit data-sharing attributes for task.
3670
3699
DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false);
3671
3700
if (((isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared) ||
3672
- (Stack->getDefaultDSA() == DSA_firstprivate &&
3673
- DVar.CKind == OMPC_firstprivate && !DVar.RefExpr)) &&
3701
+ (((Stack->getDefaultDSA() == DSA_firstprivate &&
3702
+ DVar.CKind == OMPC_firstprivate) ||
3703
+ (Stack->getDefaultDSA() == DSA_private &&
3704
+ DVar.CKind == OMPC_private)) &&
3705
+ !DVar.RefExpr)) &&
3674
3706
!Stack->isLoopControlVariable(VD).first) {
3675
- ImplicitFirstprivate.push_back(E);
3707
+ if (Stack->getDefaultDSA() == DSA_private)
3708
+ ImplicitPrivate.push_back(E);
3709
+ else
3710
+ ImplicitFirstprivate.push_back(E);
3676
3711
return;
3677
3712
}
3678
3713
@@ -3888,6 +3923,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
3888
3923
ArrayRef<Expr *> getImplicitFirstprivate() const {
3889
3924
return ImplicitFirstprivate;
3890
3925
}
3926
+ ArrayRef<Expr *> getImplicitPrivate() const { return ImplicitPrivate; }
3891
3927
ArrayRef<Expr *> getImplicitMap(OpenMPDefaultmapClauseKind DK,
3892
3928
OpenMPMapClauseKind MK) const {
3893
3929
return ImplicitMap[DK][MK];
@@ -5882,6 +5918,9 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
5882
5918
SmallVector<Expr *, 4> ImplicitFirstprivates(
5883
5919
DSAChecker.getImplicitFirstprivate().begin(),
5884
5920
DSAChecker.getImplicitFirstprivate().end());
5921
+ SmallVector<Expr *, 4> ImplicitPrivates(
5922
+ DSAChecker.getImplicitPrivate().begin(),
5923
+ DSAChecker.getImplicitPrivate().end());
5885
5924
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
5886
5925
SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete];
5887
5926
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
@@ -5934,6 +5973,17 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
5934
5973
ErrorFound = true;
5935
5974
}
5936
5975
}
5976
+ if (!ImplicitPrivates.empty()) {
5977
+ if (OMPClause *Implicit =
5978
+ ActOnOpenMPPrivateClause(ImplicitPrivates, SourceLocation(),
5979
+ SourceLocation(), SourceLocation())) {
5980
+ ClausesWithImplicit.push_back(Implicit);
5981
+ ErrorFound = cast<OMPPrivateClause>(Implicit)->varlist_size() !=
5982
+ ImplicitPrivates.size();
5983
+ } else {
5984
+ ErrorFound = true;
5985
+ }
5986
+ }
5937
5987
// OpenMP 5.0 [2.19.7]
5938
5988
// If a list item appears in a reduction, lastprivate or linear
5939
5989
// clause on a combined target construct then it is treated as
@@ -6352,6 +6402,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
6352
6402
// Check variables in the clauses if default(none) or
6353
6403
// default(firstprivate) was specified.
6354
6404
if (DSAStack->getDefaultDSA() == DSA_none ||
6405
+ DSAStack->getDefaultDSA() == DSA_private ||
6355
6406
DSAStack->getDefaultDSA() == DSA_firstprivate) {
6356
6407
DSAAttrChecker DSAChecker(DSAStack, *this, nullptr);
6357
6408
for (OMPClause *C : Clauses) {
@@ -6471,6 +6522,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
6471
6522
continue;
6472
6523
ErrorFound = true;
6473
6524
if (DSAStack->getDefaultDSA() == DSA_none ||
6525
+ DSAStack->getDefaultDSA() == DSA_private ||
6474
6526
DSAStack->getDefaultDSA() == DSA_firstprivate) {
6475
6527
Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable)
6476
6528
<< P.first << P.second->getSourceRange();
@@ -16027,6 +16079,9 @@ OMPClause *Sema::ActOnOpenMPDefaultClause(DefaultKind Kind,
16027
16079
case OMP_DEFAULT_firstprivate:
16028
16080
DSAStack->setDefaultDSAFirstPrivate(KindKwLoc);
16029
16081
break;
16082
+ case OMP_DEFAULT_private:
16083
+ DSAStack->setDefaultDSAPrivate(KindKwLoc);
16084
+ break;
16030
16085
default:
16031
16086
llvm_unreachable("DSA unexpected in OpenMP default clause");
16032
16087
}
0 commit comments