Skip to content

Commit 7e504c8

Browse files
committed
Add required changes to hoist DeclareMapperOp to the ModuleOp's region.
Add a new name mangling method which accepts a user supplied scope to mangle the name, in addition to the existing function which always used the currentScope.
1 parent b1c1a89 commit 7e504c8

File tree

4 files changed

+65
-82
lines changed

4 files changed

+65
-82
lines changed

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class AbstractConverter {
305305
mangleName(const Fortran::semantics::DerivedTypeSpec &) = 0;
306306
/// Unique a compiler generated name (add a containing scope specific prefix)
307307
virtual std::string mangleName(std::string &) = 0;
308+
/// Unique a compiler generated name (add a provided scope specific prefix)
309+
virtual std::string mangleName(std::string &, const semantics::Scope &) = 0;
308310
/// Return the field name for a derived type component inside a fir.record
309311
/// type.
310312
virtual std::string

flang/lib/Lower/Bridge.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10471047
return Fortran::lower::mangle::mangleName(name, getCurrentScope(),
10481048
scopeBlockIdMap);
10491049
}
1050+
std::string
1051+
mangleName(std::string &name,
1052+
const Fortran::semantics::Scope &myScope) override final {
1053+
return Fortran::lower::mangle::mangleName(name, myScope, scopeBlockIdMap);
1054+
}
10501055
std::string getRecordTypeFieldName(
10511056
const Fortran::semantics::Symbol &component) override final {
10521057
return Fortran::lower::mangle::getRecordTypeFieldName(component,

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,52 +2625,37 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
26252625
"Expected derived type");
26262626

26272627
std::string mapperNameStr;
2628-
if (mapperName.has_value())
2628+
if (mapperName.has_value()) {
26292629
mapperNameStr = mapperName->ToString();
2630-
else
26312630
mapperNameStr =
2632-
"default_" + varType.declTypeSpec->derivedTypeSpec().name().ToString();
2631+
converter.mangleName(mapperNameStr, mapperName->symbol->owner());
2632+
} else {
2633+
mapperNameStr =
2634+
varType.declTypeSpec->derivedTypeSpec().name().ToString() + ".default";
2635+
mapperNameStr = converter.mangleName(
2636+
mapperNameStr, *varType.declTypeSpec->derivedTypeSpec().GetScope());
2637+
}
2638+
2639+
// Save insert point just after the DeclMapperOp.
2640+
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
2641+
2642+
firOpBuilder.setInsertionPointToStart(converter.getModuleOp().getBody());
26332643
auto mlirType = converter.genType(varType.declTypeSpec->derivedTypeSpec());
26342644
auto declMapperOp = firOpBuilder.create<mlir::omp::DeclareMapperOp>(
26352645
loc, mapperNameStr, mlirType);
2646+
converter.getMLIRSymbolTable()->insert(declMapperOp);
26362647
auto &region = declMapperOp.getRegion();
2637-
2638-
// Save insert point just after the DeclMapperOp.
2639-
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
26402648
firOpBuilder.createBlock(&region);
2641-
auto varVal =
2642-
firOpBuilder.createTemporaryAlloc(loc, mlirType, varName.ToString());
2649+
auto varVal = region.addArgument(firOpBuilder.getRefType(mlirType), loc);
26432650
converter.bindSymbol(*varName.symbol, varVal);
26442651

2645-
// Insert dummy instruction to remember the insertion position. The
2646-
// marker will be deleted by clean up passes since there are no uses.
2647-
// Remembering the position for further insertion is important since
2648-
// there are hlfir.declares inserted above while setting block arguments
2649-
// and new code from the body should be inserted after that.
2650-
mlir::Value undefMarker =
2651-
firOpBuilder.create<fir::UndefOp>(loc, firOpBuilder.getIndexType());
2652-
2653-
// Create blocks for unstructured regions. This has to be done since
2654-
// blocks are initially allocated with the function as the parent region.
2655-
if (eval.lowerAsUnstructured()) {
2656-
lower::createEmptyRegionBlocks<mlir::omp::TerminatorOp, mlir::omp::YieldOp>(
2657-
firOpBuilder, eval.getNestedEvaluations());
2658-
}
2659-
2660-
firOpBuilder.create<mlir::omp::TerminatorOp>(loc);
2661-
2662-
// Set the insertion point after the marker.
2663-
firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
2664-
genNestedEvaluations(converter, eval);
2665-
26662652
// Populate the declareMapper region with the map information.
26672653
mlir::omp::DeclareMapperInfoOperands clauseOps;
26682654
const auto *clauseList{
26692655
parser::Unwrap<parser::OmpClauseList>(declareMapperConstruct.t)};
26702656
List<Clause> clauses = makeClauses(*clauseList, semaCtx);
26712657
ClauseProcessor cp(converter, semaCtx, clauses);
26722658
cp.processMap(loc, stmtCtx, clauseOps);
2673-
26742659
firOpBuilder.create<mlir::omp::DeclareMapperInfoOp>(loc, clauseOps.mapVars);
26752660

26762661
// Restore the insert point to just after the DeclareMapperOp.

0 commit comments

Comments
 (0)