Skip to content

Commit 4ac6d51

Browse files
committed
[clang][OpenMP] 6.0: Add default clause support for 'target' directive
Per OpenMP 6.0 specification, section 7.5.1, default Clause Page 224, lines 3-5 default Clause, Semantics If data-sharing-attribute is shared then the clause has no effect on a target construct; otherwise, its effect on a target construct is equivalent to specifying the defaultmap clause with the same data-sharing-attribute and variable-category. Testing: OpenMP LIT tests check-all
1 parent 346da3d commit 4ac6d51

File tree

4 files changed

+1605
-15
lines changed

4 files changed

+1605
-15
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ OpenMP Support
689689
- Added support for 'omp fuse' directive.
690690
- Updated parsing and semantic analysis support for ``nowait`` clause to accept
691691
optional argument in OpenMP >= 60.
692+
- Added support for ``default`` clause on ``target`` directive.
692693

693694
Improvements
694695
^^^^^^^^^^^^

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17305,6 +17305,43 @@ OMPClause *SemaOpenMP::ActOnOpenMPSimpleClause(
1730517305
return Res;
1730617306
}
1730717307

17308+
static std::pair<OpenMPDefaultmapClauseModifier, OpenMPDefaultmapClauseKind>
17309+
getDefaultmapModifierAndKind(llvm::omp::DefaultKind M,
17310+
OpenMPDefaultClauseVariableCategory VCKind) {
17311+
OpenMPDefaultmapClauseModifier DefMapMod;
17312+
OpenMPDefaultmapClauseKind DefMapKind;
17313+
switch (M) {
17314+
case OMP_DEFAULT_none:
17315+
DefMapMod = OMPC_DEFAULTMAP_MODIFIER_none;
17316+
break;
17317+
case OMP_DEFAULT_firstprivate:
17318+
DefMapMod = OMPC_DEFAULTMAP_MODIFIER_firstprivate;
17319+
break;
17320+
case OMP_DEFAULT_private:
17321+
DefMapMod = OMPC_DEFAULTMAP_MODIFIER_private;
17322+
break;
17323+
default:
17324+
llvm_unreachable("unexpected DSA in OpenMP default clause");
17325+
}
17326+
switch (VCKind) {
17327+
case OMPC_DEFAULT_VC_aggregate:
17328+
DefMapKind = OMPC_DEFAULTMAP_aggregate;
17329+
break;
17330+
case OMPC_DEFAULT_VC_pointer:
17331+
DefMapKind = OMPC_DEFAULTMAP_pointer;
17332+
break;
17333+
case OMPC_DEFAULT_VC_scalar:
17334+
DefMapKind = OMPC_DEFAULTMAP_scalar;
17335+
break;
17336+
case OMPC_DEFAULT_VC_all:
17337+
DefMapKind = OMPC_DEFAULTMAP_all;
17338+
break;
17339+
default:
17340+
llvm_unreachable("unexpected variable category in OpenMP default clause");
17341+
}
17342+
return std::make_pair(DefMapMod, DefMapKind);
17343+
}
17344+
1730817345
OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
1730917346
llvm::omp::DefaultKind M, SourceLocation MLoc,
1731017347
OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCKindLoc,
@@ -17317,21 +17354,40 @@ OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
1731717354
return nullptr;
1731817355
}
1731917356

17320-
switch (M) {
17321-
case OMP_DEFAULT_none:
17322-
DSAStack->setDefaultDSANone(MLoc);
17323-
break;
17324-
case OMP_DEFAULT_shared:
17325-
DSAStack->setDefaultDSAShared(MLoc);
17326-
break;
17327-
case OMP_DEFAULT_firstprivate:
17328-
DSAStack->setDefaultDSAFirstPrivate(MLoc);
17329-
break;
17330-
case OMP_DEFAULT_private:
17331-
DSAStack->setDefaultDSAPrivate(MLoc);
17332-
break;
17333-
default:
17334-
llvm_unreachable("DSA unexpected in OpenMP default clause");
17357+
if (getLangOpts().OpenMP >= 60 &&
17358+
DSAStack->getCurrentDirective() == OMPD_target) {
17359+
// OpenMP 6.0 (see page 224, lines 3-5) default Clause, Semantics
17360+
// If data-sharing-attribute is shared then the clause has no effect
17361+
// on a target construct; otherwise, its effect on a target construct is
17362+
// equivalent to specifying the defaultmap clause with the same
17363+
// data-sharing-attribute and variable-category.
17364+
if (M != OMP_DEFAULT_shared) {
17365+
auto [DefMapMod, DefMapKind] = getDefaultmapModifierAndKind(M, VCKind);
17366+
if (DefMapKind == OMPC_DEFAULTMAP_all) {
17367+
DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_aggregate, MLoc);
17368+
DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_scalar, MLoc);
17369+
DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_pointer, MLoc);
17370+
} else {
17371+
DSAStack->setDefaultDMAAttr(DefMapMod, DefMapKind, MLoc);
17372+
}
17373+
}
17374+
} else {
17375+
switch (M) {
17376+
case OMP_DEFAULT_none:
17377+
DSAStack->setDefaultDSANone(MLoc);
17378+
break;
17379+
case OMP_DEFAULT_shared:
17380+
DSAStack->setDefaultDSAShared(MLoc);
17381+
break;
17382+
case OMP_DEFAULT_firstprivate:
17383+
DSAStack->setDefaultDSAFirstPrivate(MLoc);
17384+
break;
17385+
case OMP_DEFAULT_private:
17386+
DSAStack->setDefaultDSAPrivate(MLoc);
17387+
break;
17388+
default:
17389+
llvm_unreachable("DSA unexpected in OpenMP default clause");
17390+
}
1733517391
}
1733617392

1733717393
switch (VCKind) {

0 commit comments

Comments
 (0)