aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-08-07 12:01:54 -0400
committerNico Weber <thakis@chromium.org>2023-08-07 12:01:54 -0400
commitfab49721b4ef0b5079194bc09528df78f38c32a8 (patch)
tree93f9b51163c890bd045d3b36bca65a5ec4b06eeb /clang/lib
parent0e2de665f34f59ef26a976c70fcafeb8303d79fc (diff)
downloadllvm-fab49721b4ef0b5079194bc09528df78f38c32a8.zip
llvm-fab49721b4ef0b5079194bc09528df78f38c32a8.tar.gz
llvm-fab49721b4ef0b5079194bc09528df78f38c32a8.tar.bz2
Revert "[Clang][OpenMP] Support for Code Generation of loop bind clause"
This reverts commit 4097a24584121dba562d471fab97d3dfec1b5bff. Breaks tests on macOS, see https://reviews.llvm.org/rG4097a2458412#1235854
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/StmtOpenMP.cpp17
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp177
-rw-r--r--clang/lib/Sema/TreeTransform.h18
-rw-r--r--clang/lib/Serialization/ASTReaderStmt.cpp1
-rw-r--r--clang/lib/Serialization/ASTWriterStmt.cpp1
5 files changed, 26 insertions, 188 deletions
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 5a1001d..a544732 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -297,10 +297,11 @@ OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
/*NumChildren=*/1);
}
-OMPSimdDirective *OMPSimdDirective::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
- unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
- const HelperExprs &Exprs, OpenMPDirectiveKind ParamPrevMappedDirective) {
+OMPSimdDirective *
+OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
+ SourceLocation EndLoc, unsigned CollapsedNum,
+ ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
+ const HelperExprs &Exprs) {
auto *Dir = createDirective<OMPSimdDirective>(
C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_simd),
StartLoc, EndLoc, CollapsedNum);
@@ -320,7 +321,6 @@ OMPSimdDirective *OMPSimdDirective::Create(
Dir->setDependentInits(Exprs.DependentInits);
Dir->setFinalsConditions(Exprs.FinalsConditions);
Dir->setPreInits(Exprs.PreInits);
- Dir->setMappedDirective(ParamPrevMappedDirective);
return Dir;
}
@@ -336,8 +336,7 @@ OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
OMPForDirective *OMPForDirective::Create(
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
- const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel,
- OpenMPDirectiveKind ParamPrevMappedDirective) {
+ const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) {
auto *Dir = createDirective<OMPForDirective>(
C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_for) + 1,
StartLoc, EndLoc, CollapsedNum);
@@ -367,7 +366,6 @@ OMPForDirective *OMPForDirective::Create(
Dir->setPreInits(Exprs.PreInits);
Dir->setTaskReductionRefExpr(TaskRedRef);
Dir->setHasCancel(HasCancel);
- Dir->setMappedDirective(ParamPrevMappedDirective);
return Dir;
}
@@ -1517,7 +1515,7 @@ OMPParallelMaskedTaskLoopSimdDirective::CreateEmpty(const ASTContext &C,
OMPDistributeDirective *OMPDistributeDirective::Create(
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
- const HelperExprs &Exprs, OpenMPDirectiveKind ParamPrevMappedDirective) {
+ const HelperExprs &Exprs) {
auto *Dir = createDirective<OMPDistributeDirective>(
C, Clauses, AssociatedStmt,
numLoopChildren(CollapsedNum, OMPD_distribute), StartLoc, EndLoc,
@@ -1546,7 +1544,6 @@ OMPDistributeDirective *OMPDistributeDirective::Create(
Dir->setDependentInits(Exprs.DependentInits);
Dir->setFinalsConditions(Exprs.FinalsConditions);
Dir->setPreInits(Exprs.PreInits);
- Dir->setMappedDirective(ParamPrevMappedDirective);
return Dir;
}
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3482caf..305ea24 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -163,10 +163,6 @@ private:
SourceLocation DefaultAttrLoc;
DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown];
OpenMPDirectiveKind Directive = OMPD_unknown;
- /// GenericLoopDirective with bind clause is mapped to other directives,
- /// like for, distribute and simd. Presently, set MappedDirective to
- /// OMPLoop. This may also be used in a similar way for other constructs.
- OpenMPDirectiveKind MappedDirective = OMPD_unknown;
DeclarationNameInfo DirectiveName;
Scope *CurScope = nullptr;
DeclContext *Context = nullptr;
@@ -640,24 +636,6 @@ public:
const SharingMapTy *Top = getTopOfStackOrNull();
return Top ? Top->Directive : OMPD_unknown;
}
- OpenMPDirectiveKind getMappedDirective() const {
- const SharingMapTy *Top = getTopOfStackOrNull();
- return Top ? Top->MappedDirective : OMPD_unknown;
- }
- void setCurrentDirective(OpenMPDirectiveKind NewDK) {
- SharingMapTy *Top = getTopOfStackOrNull();
- assert(Top &&
- "Before calling setCurrentDirective Top of Stack not to be NULL.");
- // Store the old into MappedDirective & assign argument NewDK to Directive.
- Top->Directive = NewDK;
- }
- void setMappedDirective(OpenMPDirectiveKind NewDK) {
- SharingMapTy *Top = getTopOfStackOrNull();
- assert(Top &&
- "Before calling setMappedDirective Top of Stack not to be NULL.");
- // Store the old into MappedDirective & assign argument NewDK to Directive.
- Top->MappedDirective = NewDK;
- }
/// Returns directive kind at specified level.
OpenMPDirectiveKind getDirective(unsigned Level) const {
assert(!isStackEmpty() && "No directive at specified level.");
@@ -5701,8 +5679,7 @@ static CapturedStmt *buildDistanceFunc(Sema &Actions, QualType LogicalTy,
// the step size, rounding-up the effective upper bound ensures that the
// last iteration is included.
// Note that the rounding-up may cause an overflow in a temporry that
- // could be avoided, but would have occurred in a C-style for-loop as
- // well.
+ // could be avoided, but would have occurred in a C-style for-loop as well.
Expr *Divisor = BuildVarRef(NewStep);
if (Rel == BO_GE || Rel == BO_GT)
Divisor =
@@ -6109,95 +6086,10 @@ processImplicitMapsWithDefaultMappers(Sema &S, DSAStackTy *Stack,
}
}
-bool Sema::mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind,
- ArrayRef<OMPClause *> Clauses,
- OpenMPBindClauseKind BindKind,
- OpenMPDirectiveKind &Kind,
- OpenMPDirectiveKind &PrevMappedDirective) {
-
- bool UseClausesWithoutBind = false;
-
- // Restricting to "#pragma omp loop bind"
- if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
- 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) {
- BindKind = OMPC_BIND_parallel;
- } else if (ParentDirective == OMPD_teams ||
- 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.
- UseClausesWithoutBind = true;
- }
-
- for (OMPClause *C : Clauses) {
- // Spec restriction : bind(teams) and reduction not permitted.
- if (BindKind == OMPC_BIND_teams &&
- C->getClauseKind() == llvm::omp::Clause::OMPC_reduction)
- Diag(DSAStack->getDefaultDSALocation(),
- diag::err_omp_loop_reduction_clause);
-
- // A new Vector ClausesWithoutBind, which does not contain the bind
- // clause, for passing to new directive.
- if (C->getClauseKind() != llvm::omp::Clause::OMPC_bind)
- ClausesWithoutBind.push_back(C);
- }
-
- switch (BindKind) {
- case OMPC_BIND_parallel:
- Kind = OMPD_for;
- DSAStack->setCurrentDirective(OMPD_for);
- DSAStack->setMappedDirective(OMPD_loop);
- PrevMappedDirective = OMPD_loop;
- break;
- case OMPC_BIND_teams:
- Kind = OMPD_distribute;
- DSAStack->setCurrentDirective(OMPD_distribute);
- DSAStack->setMappedDirective(OMPD_loop);
- PrevMappedDirective = OMPD_loop;
- break;
- case OMPC_BIND_thread:
- Kind = OMPD_simd;
- DSAStack->setCurrentDirective(OMPD_simd);
- DSAStack->setMappedDirective(OMPD_loop);
- PrevMappedDirective = OMPD_loop;
- break;
- case OMPC_BIND_unknown:
- break;
- }
- } else if (PrevMappedDirective == OMPD_loop) {
- /// An initial pass after recognizing all the statements is done in the
- /// Parser when the directive OMPD_loop is mapped to OMPD_for,
- /// OMPD_distribute or OMPD_simd. A second transform pass with call from
- /// clang::TreeTransform::TransformOMPExecutableDirective() is done
- /// with the Directive as one of the above mapped directive without
- /// the bind clause. Then "PrevMappedDirective" stored in the
- /// OMPExecutableDirective is accessed and hence this else statement.
-
- DSAStack->setMappedDirective(OMPD_loop);
- }
-
- return UseClausesWithoutBind;
-}
-
StmtResult Sema::ActOnOpenMPExecutableDirective(
OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
- Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
- OpenMPDirectiveKind PrevMappedDirective) {
+ Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) {
StmtResult Res = StmtError();
OpenMPBindClauseKind BindKind = OMPC_BIND_unknown;
if (const OMPBindClause *BC =
@@ -6214,21 +6106,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
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;
- if (getLangOpts().OpenMP >= 50 && UseClausesWithoutBind) {
- ClausesWithImplicit.append(ClausesWithoutBind.begin(),
- ClausesWithoutBind.end());
- } else {
- ClausesWithImplicit.append(Clauses.begin(), Clauses.end());
- }
+ ClausesWithImplicit.append(Clauses.begin(), Clauses.end());
if (AStmt && !CurContext->isDependentContext() && Kind != OMPD_atomic &&
Kind != OMPD_critical && Kind != OMPD_section && Kind != OMPD_master &&
Kind != OMPD_masked && !isOpenMPLoopTransformationDirective(Kind)) {
@@ -9322,13 +9203,9 @@ static bool checkOpenMPIterationSpace(
auto *CXXFor = dyn_cast_or_null<CXXForRangeStmt>(S);
// Ranged for is supported only in OpenMP 5.0.
if (!For && (SemaRef.LangOpts.OpenMP <= 45 || !CXXFor)) {
- OpenMPDirectiveKind DK = (SemaRef.getLangOpts().OpenMP < 50 ||
- DSA.getMappedDirective() == OMPD_unknown)
- ? DKind
- : DSA.getMappedDirective();
SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for)
<< (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr)
- << getOpenMPDirectiveName(DK) << TotalNestedLoopCount
+ << getOpenMPDirectiveName(DKind) << TotalNestedLoopCount
<< (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount;
if (TotalNestedLoopCount > 1) {
if (CollapseLoopCountExpr && OrderedLoopCountExpr)
@@ -10443,24 +10320,6 @@ static bool checkSimdlenSafelenSpecified(Sema &S,
return false;
}
-static bool checkGenericLoopLastprivate(Sema &S, ArrayRef<OMPClause *> Clauses,
- OpenMPDirectiveKind K,
- DSAStackTy *Stack);
-
-bool Sema::checkLastPrivateForMappedDirectives(ArrayRef<OMPClause *> Clauses) {
-
- // Check for syntax of lastprivate
- // Param of the lastprivate have different meanings in the mapped directives
- // e.g. "omp loop" Only loop iteration vars are allowed in lastprivate clause
- // "omp for" lastprivate vars must be shared
- if (getLangOpts().OpenMP >= 50 &&
- DSAStack->getMappedDirective() == OMPD_loop &&
- checkGenericLoopLastprivate(*this, Clauses, OMPD_loop, DSAStack)) {
- return false;
- }
- return true;
-}
-
StmtResult
Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
SourceLocation StartLoc, SourceLocation EndLoc,
@@ -10468,9 +10327,6 @@ Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
if (!AStmt)
return StmtError();
- if (!checkLastPrivateForMappedDirectives(Clauses))
- return StmtError();
-
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
OMPLoopBasedDirective::HelperExprs B;
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
@@ -10499,10 +10355,8 @@ Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
return StmtError();
setFunctionHasBranchProtectedScope();
- auto *SimdDirective = OMPSimdDirective::Create(
- Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,
- DSAStack->getMappedDirective());
- return SimdDirective;
+ return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount,
+ Clauses, AStmt, B);
}
StmtResult
@@ -10512,9 +10366,6 @@ Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
if (!AStmt)
return StmtError();
- if (!checkLastPrivateForMappedDirectives(Clauses))
- return StmtError();
-
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
OMPLoopBasedDirective::HelperExprs B;
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
@@ -10539,11 +10390,10 @@ Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
}
}
- auto *ForDirective = OMPForDirective::Create(
+ setFunctionHasBranchProtectedScope();
+ return OMPForDirective::Create(
Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,
- DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion(),
- DSAStack->getMappedDirective());
- return ForDirective;
+ DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
}
StmtResult Sema::ActOnOpenMPForSimdDirective(
@@ -14090,9 +13940,6 @@ StmtResult Sema::ActOnOpenMPDistributeDirective(
if (!AStmt)
return StmtError();
- if (!checkLastPrivateForMappedDirectives(Clauses))
- return StmtError();
-
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
OMPLoopBasedDirective::HelperExprs B;
// In presence of clause 'collapse' with number of loops, it will
@@ -14108,10 +13955,8 @@ StmtResult Sema::ActOnOpenMPDistributeDirective(
"omp for loop exprs were not built");
setFunctionHasBranchProtectedScope();
- auto *DistributeDirective = OMPDistributeDirective::Create(
- Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,
- DSAStack->getMappedDirective());
- return DistributeDirective;
+ return OMPDistributeDirective::Create(Context, StartLoc, EndLoc,
+ NestedLoopCount, Clauses, AStmt, B);
}
StmtResult Sema::ActOnOpenMPDistributeParallelForDirective(
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index d99c1d6..a73b54b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -1645,15 +1645,14 @@ public:
///
/// By default, performs semantic analysis to build the new statement.
/// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildOMPExecutableDirective(
- OpenMPDirectiveKind Kind, DeclarationNameInfo DirName,
- OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
- Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
- OpenMPDirectiveKind PrevMappedDirective = OMPD_unknown) {
-
+ StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
+ DeclarationNameInfo DirName,
+ OpenMPDirectiveKind CancelRegion,
+ ArrayRef<OMPClause *> Clauses,
+ Stmt *AStmt, SourceLocation StartLoc,
+ SourceLocation EndLoc) {
return getSema().ActOnOpenMPExecutableDirective(
- Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc,
- PrevMappedDirective);
+ Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
}
/// Build a new OpenMP 'if' clause.
@@ -8820,8 +8819,7 @@ StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
return getDerived().RebuildOMPExecutableDirective(
D->getDirectiveKind(), DirName, CancelRegion, TClauses,
- AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc(),
- D->getMappedDirective());
+ AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
}
template <typename Derived>
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index e9ad324..96307c3 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2325,7 +2325,6 @@ void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Record.readOMPChildren(E->Data);
E->setLocStart(readSourceLocation());
E->setLocEnd(readSourceLocation());
- E->setMappedDirective(Record.readEnum<OpenMPDirectiveKind>());
}
void ASTStmtReader::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 0c267d3..896e24c 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2235,7 +2235,6 @@ void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
Record.writeOMPChildren(E->Data);
Record.AddSourceLocation(E->getBeginLoc());
Record.AddSourceLocation(E->getEndLoc());
- Record.writeEnum(E->getMappedDirective());
}
void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {