aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaOpenMP.cpp
diff options
context:
space:
mode:
authorSunil Kuravinakop <koops@hpe.com>2023-10-26 05:01:02 -0500
committerSandeep Kosuri <kosuris@pe28vega.us.cray.com>2023-10-26 05:08:41 -0500
commit85f6b2fac9a367337e43ca288c45ea783981cc16 (patch)
treeaeb60c871216f1637464322bd7f3b0f98726c690 /clang/lib/Sema/SemaOpenMP.cpp
parent80abbeca8e52174157654ee33151da507d098ced (diff)
downloadllvm-85f6b2fac9a367337e43ca288c45ea783981cc16.zip
llvm-85f6b2fac9a367337e43ca288c45ea783981cc16.tar.gz
llvm-85f6b2fac9a367337e43ca288c45ea783981cc16.tar.bz2
[OpenMP] Patch for Support to loop bind clause : Checking Parent Region
Differential revision: https://reviews.llvm.org/D158266
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp64
1 files changed, 45 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 75f9e15..f28e0f2 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5062,6 +5062,18 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
CurrentRegion != OMPD_cancellation_point &&
CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan)
return false;
+ // Checks needed for mapping "loop" construct. Please check mapLoopConstruct
+ // for a detailed explanation
+ if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop &&
+ ((BindKind == OMPC_BIND_parallel) || (BindKind == OMPC_BIND_teams)) &&
+ (isOpenMPWorksharingDirective(ParentRegion) ||
+ ParentRegion == OMPD_loop)) {
+ int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4;
+ SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
+ << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber
+ << getOpenMPDirectiveName(CurrentRegion);
+ return true;
+ }
if (CurrentRegion == OMPD_cancellation_point ||
CurrentRegion == OMPD_cancel) {
// OpenMP [2.16, Nesting of Regions]
@@ -6114,35 +6126,40 @@ processImplicitMapsWithDefaultMappers(Sema &S, DSAStackTy *Stack,
bool Sema::mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind,
ArrayRef<OMPClause *> Clauses,
- OpenMPBindClauseKind BindKind,
+ OpenMPBindClauseKind &BindKind,
OpenMPDirectiveKind &Kind,
- OpenMPDirectiveKind &PrevMappedDirective) {
+ OpenMPDirectiveKind &PrevMappedDirective,
+ SourceLocation StartLoc, SourceLocation EndLoc,
+ const DeclarationNameInfo &DirName,
+ OpenMPDirectiveKind CancelRegion) {
bool UseClausesWithoutBind = false;
// Restricting to "#pragma omp loop bind"
if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
+
+ const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
+
if (BindKind == OMPC_BIND_unknown) {
// Setting the enclosing teams or parallel construct for the loop
// directive without bind clause.
BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is unknown
- const OpenMPDirectiveKind ParentDirective =
- DSAStack->getParentDirective();
if (ParentDirective == OMPD_unknown) {
Diag(DSAStack->getDefaultDSALocation(),
diag::err_omp_bind_required_on_loop);
- } else if (ParentDirective == OMPD_parallel ||
- ParentDirective == OMPD_target_parallel) {
+ } else if (isOpenMPParallelDirective(ParentDirective) &&
+ !isOpenMPTeamsDirective(ParentDirective)) {
BindKind = OMPC_BIND_parallel;
- } else if (ParentDirective == OMPD_teams ||
- ParentDirective == OMPD_target_teams) {
+ } else if (isOpenMPNestingTeamsDirective(ParentDirective) ||
+ (ParentDirective == OMPD_target_teams)) {
BindKind = OMPC_BIND_teams;
}
} else {
- // bind clause is present, so we should set flag indicating to only
- // use the clauses that aren't the bind clause for the new directive that
- // loop is lowered to.
+ // bind clause is present in loop directive. When the loop directive is
+ // changed to a new directive the bind clause is not used. So, we should
+ // set flag indicating to only use the clauses that aren't the
+ // bind clause.
UseClausesWithoutBind = true;
}
@@ -6203,26 +6220,35 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
OpenMPDirectiveKind PrevMappedDirective) {
StmtResult Res = StmtError();
OpenMPBindClauseKind BindKind = OMPC_BIND_unknown;
+ llvm::SmallVector<OMPClause *> ClausesWithoutBind;
+ bool UseClausesWithoutBind = false;
+
if (const OMPBindClause *BC =
OMPExecutableDirective::getSingleClause<OMPBindClause>(Clauses))
BindKind = BC->getBindKind();
+
+ // Variable used to note down the DirectiveKind because mapLoopConstruct may
+ // change "Kind" variable, due to mapping of "omp loop" to other directives.
+ OpenMPDirectiveKind DK = Kind;
+ if ((Kind == OMPD_loop) || (PrevMappedDirective == OMPD_loop)) {
+ UseClausesWithoutBind = mapLoopConstruct(
+ ClausesWithoutBind, Clauses, BindKind, Kind, PrevMappedDirective,
+ StartLoc, EndLoc, DirName, CancelRegion);
+ DK = OMPD_loop;
+ }
+
// First check CancelRegion which is then used in checkNestingOfRegions.
if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) ||
- checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion,
- BindKind, StartLoc))
+ checkNestingOfRegions(*this, DSAStack, DK, DirName, CancelRegion,
+ BindKind, StartLoc)) {
return StmtError();
+ }
// Report affected OpenMP target offloading behavior when in HIP lang-mode.
if (getLangOpts().HIP && (isOpenMPTargetExecutionDirective(Kind) ||
isOpenMPTargetDataManagementDirective(Kind)))
Diag(StartLoc, diag::warn_hip_omp_target_directives);
- llvm::SmallVector<OMPClause *> ClausesWithoutBind;
- bool UseClausesWithoutBind = false;
-
- UseClausesWithoutBind = mapLoopConstruct(ClausesWithoutBind, Clauses,
- BindKind, Kind, PrevMappedDirective);
-
llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit;
VarsWithInheritedDSAType VarsWithInheritedDSA;
bool ErrorFound = false;