[flang-commits] [flang] [mlir] [WIP] Delayed privatization. (PR #79862)
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Tue Jan 30 03:55:36 PST 2024
================
@@ -487,15 +491,56 @@ void DataSharingProcessor::collectDefaultSymbols() {
}
}
-void DataSharingProcessor::privatize() {
+void DataSharingProcessor::privatize(
+ llvm::SetVector<mlir::omp::PrivateClauseOp> *privateInitializers) {
+
for (const Fortran::semantics::Symbol *sym : privatizedSymbols) {
+
if (const auto *commonDet =
sym->detailsIf<Fortran::semantics::CommonBlockDetails>()) {
for (const auto &mem : commonDet->objects()) {
cloneSymbol(&*mem);
copyFirstPrivateSymbol(&*mem);
}
} else {
+ if (privateInitializers != nullptr) {
+ auto ip = firOpBuilder.saveInsertionPoint();
+
+ auto moduleOp = firOpBuilder.getInsertionBlock()
+ ->getParentOp()
+ ->getParentOfType<mlir::ModuleOp>();
+
+ firOpBuilder.setInsertionPoint(&moduleOp.getBodyRegion().front(),
+ moduleOp.getBodyRegion().front().end());
+
+ Fortran::lower::SymbolBox hsb = converter.lookupOneLevelUpSymbol(*sym);
+ assert(hsb && "Host symbol box not found");
+
+ auto privatizerOp = firOpBuilder.create<mlir::omp::PrivateClauseOp>(
+ hsb.getAddr().getLoc(), hsb.getAddr().getType(),
+ sym->name().ToString());
+ firOpBuilder.setInsertionPointToEnd(&privatizerOp.getBody().front());
+
+ converter.getLocalSymbols()->pushScope();
+ converter.getLocalSymbols()->addSymbol(*sym,
+ privatizerOp.getArgument(0));
+ converter.getLocalSymbols()->pushScope();
+
+ cloneSymbol(sym);
+ copyFirstPrivateSymbol(sym);
+
+ firOpBuilder.create<mlir::omp::YieldOp>(
+ hsb.getAddr().getLoc(),
+ converter.getLocalSymbols()->shallowLookupSymbol(*sym).getAddr());
+
+ converter.getLocalSymbols()->popScope();
+ converter.getLocalSymbols()->popScope();
+ firOpBuilder.restoreInsertionPoint(ip);
+ }
+
+ // TODO: This will eventually be an else to the `if` above it. For now, I
+ // emit both the outlined privatizer AND directly emitted cloning and
+ // copying ops while I am testing.
----------------
kiranchandramohan wrote:
You could also have a derived class of DataSharingProcessor to do delayed privatization.
https://github.com/llvm/llvm-project/pull/79862
More information about the flang-commits
mailing list