Skip to content

Commit e9a3e01

Browse files
committed
[flang][OpenMP][MLIR] Basic support for delayed privatization code-gen
Adds basic support for emitting delayed privatizers from flang. So far, only types of symbols are supported (i.e. scalars), support for more complicated types will be added later. This also makes sure that reductio and delayed privatization work properly together by merging the body-gen callbacks for both in case both clauses are present on the parallel construct.
1 parent b8ed69e commit e9a3e01

File tree

8 files changed

+390
-28
lines changed

8 files changed

+390
-28
lines changed

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "flang/Common/Fortran.h"
1717
#include "flang/Lower/LoweringOptions.h"
1818
#include "flang/Lower/PFTDefs.h"
19+
#include "flang/Lower/SymbolMap.h"
1920
#include "flang/Optimizer/Builder/BoxValue.h"
2021
#include "flang/Semantics/symbol.h"
2122
#include "mlir/IR/Builders.h"
@@ -296,6 +297,9 @@ class AbstractConverter {
296297
return loweringOptions;
297298
}
298299

300+
virtual Fortran::lower::SymbolBox
301+
lookupOneLevelUpSymbol(const Fortran::semantics::Symbol &sym) = 0;
302+
299303
private:
300304
/// Options controlling lowering behavior.
301305
const Fortran::lower::LoweringOptions &loweringOptions;

flang/lib/Lower/Bridge.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10521052
if (sym.detailsIf<Fortran::semantics::CommonBlockDetails>())
10531053
return symMap->lookupSymbol(sym);
10541054

1055+
// For symbols to be privatized in OMP, the symbol is mapped to an
1056+
// instance of `SymbolBox::Intrinsic` (i.e. a direct mapping to an MLIR
1057+
// SSA value). This MLIR SSA value is the block argument to the
1058+
// `omp.private`'s `alloc` block. If this is the case, we return this
1059+
// `SymbolBox::Intrinsic` value.
1060+
if (Fortran::lower::SymbolBox v = symMap->lookupSymbol(sym))
1061+
return v.match(
1062+
[&](const Fortran::lower::SymbolBox::Intrinsic &)
1063+
-> Fortran::lower::SymbolBox { return v; },
1064+
[](const auto &) -> Fortran::lower::SymbolBox { return {}; });
1065+
10551066
return {};
10561067
}
10571068
if (Fortran::lower::SymbolBox v = symMap->lookupSymbol(sym))
@@ -1070,7 +1081,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10701081
/// Find the symbol in one level up of symbol map such as for host-association
10711082
/// in OpenMP code or return null.
10721083
Fortran::lower::SymbolBox
1073-
lookupOneLevelUpSymbol(const Fortran::semantics::Symbol &sym) {
1084+
lookupOneLevelUpSymbol(const Fortran::semantics::Symbol &sym) override {
10741085
if (Fortran::lower::SymbolBox v = localSymbols.lookupOneLevelUpSymbol(sym))
10751086
return v;
10761087
return {};

0 commit comments

Comments
 (0)