Skip to content

Commit 30c862d

Browse files
committed
Revert [flang] Extend localization support for do concurrent
breaks 535.weather ref. timeout bac4aa4 - [flang] Extend localization support for `do concurrent` (`init` regions) (llvm#142564) (3 days ago) <Kareem Ergawy>
1 parent 2fdc4f1 commit 30c862d

23 files changed

+132
-154
lines changed

flang/include/flang/Lower/Support/Utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "mlir/Dialect/Arith/IR/Arith.h"
2121
#include "mlir/Dialect/Func/IR/FuncOps.h"
2222
#include "mlir/IR/BuiltinAttributes.h"
23-
#include "llvm/ADT/SmallSet.h"
2423
#include "llvm/ADT/StringRef.h"
2524

2625
namespace Fortran::lower {
@@ -99,9 +98,8 @@ bool isEqual(const Fortran::lower::ExplicitIterSpace::ArrayBases &x,
9998
template <typename OpType, typename OperandsStructType>
10099
void privatizeSymbol(
101100
lower::AbstractConverter &converter, fir::FirOpBuilder &firOpBuilder,
102-
lower::SymMap &symTable,
101+
lower::SymMap &symTable, std::function<void(OpType, mlir::Type)> initGen,
103102
llvm::SetVector<const semantics::Symbol *> &allPrivatizedSymbols,
104-
llvm::SmallSet<const semantics::Symbol *, 16> &mightHaveReadHostSym,
105103
const semantics::Symbol *symToPrivatize, OperandsStructType *clauseOps);
106104

107105
} // end namespace Fortran::lower

flang/lib/Lower/Bridge.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "flang/Lower/Bridge.h"
1414

15+
#include "OpenMP/DataSharingProcessor.h"
1516
#include "flang/Lower/Allocatable.h"
1617
#include "flang/Lower/CallInterface.h"
1718
#include "flang/Lower/Coarray.h"
@@ -2043,38 +2044,44 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20432044
bool useDelayedPriv =
20442045
enableDelayedPrivatizationStaging && doConcurrentLoopOp;
20452046
llvm::SetVector<const Fortran::semantics::Symbol *> allPrivatizedSymbols;
2046-
llvm::SmallSet<const Fortran::semantics::Symbol *, 16> mightHaveReadHostSym;
20472047

2048-
for (const Fortran::semantics::Symbol *symToPrivatize : info.localSymList) {
2048+
for (const Fortran::semantics::Symbol *sym : info.localSymList) {
20492049
if (useDelayedPriv) {
20502050
Fortran::lower::privatizeSymbol<fir::LocalitySpecifierOp>(
2051-
*this, this->getFirOpBuilder(), localSymbols, allPrivatizedSymbols,
2052-
mightHaveReadHostSym, symToPrivatize, &privateClauseOps);
2051+
*this, this->getFirOpBuilder(), localSymbols,
2052+
[this](fir::LocalitySpecifierOp result, mlir::Type argType) {
2053+
TODO(this->toLocation(),
2054+
"Localizers that need init regions are not supported yet.");
2055+
},
2056+
allPrivatizedSymbols, sym, &privateClauseOps);
20532057
continue;
20542058
}
20552059

2056-
createHostAssociateVarClone(*symToPrivatize, /*skipDefaultInit=*/false);
2060+
createHostAssociateVarClone(*sym, /*skipDefaultInit=*/false);
20572061
}
20582062

2059-
for (const Fortran::semantics::Symbol *symToPrivatize :
2060-
info.localInitSymList) {
2063+
for (const Fortran::semantics::Symbol *sym : info.localInitSymList) {
20612064
if (useDelayedPriv) {
20622065
Fortran::lower::privatizeSymbol<fir::LocalitySpecifierOp>(
2063-
*this, this->getFirOpBuilder(), localSymbols, allPrivatizedSymbols,
2064-
mightHaveReadHostSym, symToPrivatize, &privateClauseOps);
2066+
*this, this->getFirOpBuilder(), localSymbols,
2067+
[this](fir::LocalitySpecifierOp result, mlir::Type argType) {
2068+
TODO(this->toLocation(),
2069+
"Localizers that need init regions are not supported yet.");
2070+
},
2071+
allPrivatizedSymbols, sym, &privateClauseOps);
20652072
continue;
20662073
}
20672074

2068-
createHostAssociateVarClone(*symToPrivatize, /*skipDefaultInit=*/true);
2075+
createHostAssociateVarClone(*sym, /*skipDefaultInit=*/true);
20692076
const auto *hostDetails =
2070-
symToPrivatize->detailsIf<Fortran::semantics::HostAssocDetails>();
2077+
sym->detailsIf<Fortran::semantics::HostAssocDetails>();
20712078
assert(hostDetails && "missing locality spec host symbol");
20722079
const Fortran::semantics::Symbol *hostSym = &hostDetails->symbol();
20732080
Fortran::evaluate::ExpressionAnalyzer ea{semanticsContext};
20742081
Fortran::evaluate::Assignment assign{
2075-
ea.Designate(Fortran::evaluate::DataRef{*symToPrivatize}).value(),
2082+
ea.Designate(Fortran::evaluate::DataRef{*sym}).value(),
20762083
ea.Designate(Fortran::evaluate::DataRef{*hostSym}).value()};
2077-
if (Fortran::semantics::IsPointer(*symToPrivatize))
2084+
if (Fortran::semantics::IsPointer(*sym))
20782085
assign.u = Fortran::evaluate::Assignment::BoundsSpec{};
20792086
genAssignment(assign);
20802087
}

flang/lib/Lower/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ add_flang_library(FortranLower
2828
OpenMP/DataSharingProcessor.cpp
2929
OpenMP/Decomposer.cpp
3030
OpenMP/OpenMP.cpp
31+
OpenMP/PrivateReductionUtils.cpp
3132
OpenMP/ReductionProcessor.cpp
3233
OpenMP/Utils.cpp
3334
PFTBuilder.cpp
3435
Runtime.cpp
35-
Support/PrivateReductionUtils.cpp
3636
Support/Utils.cpp
3737
SymbolMap.cpp
3838
VectorSubscripts.cpp

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
#include "DataSharingProcessor.h"
1414

15+
#include "PrivateReductionUtils.h"
1516
#include "flang/Lower/ConvertVariable.h"
1617
#include "flang/Lower/OpenMP/Utils.h"
1718
#include "flang/Lower/PFTBuilder.h"
18-
#include "flang/Lower/Support/PrivateReductionUtils.h"
1919
#include "flang/Lower/Support/Utils.h"
2020
#include "flang/Lower/SymbolMap.h"
2121
#include "flang/Optimizer/Builder/BoxValue.h"
@@ -543,10 +543,38 @@ void DataSharingProcessor::privatizeSymbol(
543543
return;
544544
}
545545

546+
auto initGen = [&](mlir::omp::PrivateClauseOp result, mlir::Type argType) {
547+
lower::SymbolBox hsb = converter.lookupOneLevelUpSymbol(*symToPrivatize);
548+
assert(hsb && "Host symbol box not found");
549+
hlfir::Entity entity{hsb.getAddr()};
550+
bool cannotHaveNonDefaultLowerBounds =
551+
!entity.mayHaveNonDefaultLowerBounds();
552+
553+
mlir::Region &initRegion = result.getInitRegion();
554+
mlir::Location symLoc = hsb.getAddr().getLoc();
555+
mlir::Block *initBlock = firOpBuilder.createBlock(
556+
&initRegion, /*insertPt=*/{}, {argType, argType}, {symLoc, symLoc});
557+
558+
bool emitCopyRegion =
559+
symToPrivatize->test(semantics::Symbol::Flag::OmpFirstPrivate);
560+
561+
populateByRefInitAndCleanupRegions(
562+
converter, symLoc, argType, /*scalarInitValue=*/nullptr, initBlock,
563+
result.getInitPrivateArg(), result.getInitMoldArg(),
564+
result.getDeallocRegion(),
565+
emitCopyRegion ? omp::DeclOperationKind::FirstPrivate
566+
: omp::DeclOperationKind::Private,
567+
symToPrivatize);
568+
// TODO: currently there are false positives from dead uses of the mold
569+
// arg
570+
if (result.initReadsFromMold())
571+
mightHaveReadHostSym.insert(symToPrivatize);
572+
};
573+
546574
Fortran::lower::privatizeSymbol<mlir::omp::PrivateClauseOp,
547575
mlir::omp::PrivateClauseOps>(
548-
converter, firOpBuilder, symTable, allPrivatizedSymbols,
549-
mightHaveReadHostSym, symToPrivatize, clauseOps);
576+
converter, firOpBuilder, symTable, initGen, allPrivatizedSymbols,
577+
symToPrivatize, clauseOps);
550578
}
551579
} // namespace omp
552580
} // namespace lower

0 commit comments

Comments
 (0)