Skip to content

Commit 54727b3

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 337d778 commit 54727b3

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
@@ -314,6 +314,8 @@ class AbstractConverter {
314314
mangleName(const Fortran::semantics::DerivedTypeSpec &) = 0;
315315
/// Unique a compiler generated name (add a containing scope specific prefix)
316316
virtual std::string mangleName(std::string &) = 0;
317+
/// Unique a compiler generated name (add a provided scope specific prefix)
318+
virtual std::string mangleName(std::string &, const semantics::Scope &) = 0;
317319
/// Return the field name for a derived type component inside a fir.record
318320
/// type.
319321
virtual std::string

flang/lib/Lower/Bridge.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10481048
return Fortran::lower::mangle::mangleName(name, getCurrentScope(),
10491049
scopeBlockIdMap);
10501050
}
1051+
std::string
1052+
mangleName(std::string &name,
1053+
const Fortran::semantics::Scope &myScope) override final {
1054+
return Fortran::lower::mangle::mangleName(name, myScope, scopeBlockIdMap);
1055+
}
10511056
std::string getRecordTypeFieldName(
10521057
const Fortran::semantics::Symbol &component) override final {
10531058
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
@@ -3132,52 +3132,37 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
31323132
"Expected derived type");
31333133

31343134
std::string mapperNameStr;
3135-
if (mapperName.has_value())
3135+
if (mapperName.has_value()) {
31363136
mapperNameStr = mapperName->ToString();
3137-
else
31383137
mapperNameStr =
3139-
"default_" + varType.declTypeSpec->derivedTypeSpec().name().ToString();
3138+
converter.mangleName(mapperNameStr, mapperName->symbol->owner());
3139+
} else {
3140+
mapperNameStr =
3141+
varType.declTypeSpec->derivedTypeSpec().name().ToString() + ".default";
3142+
mapperNameStr = converter.mangleName(
3143+
mapperNameStr, *varType.declTypeSpec->derivedTypeSpec().GetScope());
3144+
}
3145+
3146+
// Save insert point just after the DeclMapperOp.
3147+
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
3148+
3149+
firOpBuilder.setInsertionPointToStart(converter.getModuleOp().getBody());
31403150
auto mlirType = converter.genType(varType.declTypeSpec->derivedTypeSpec());
31413151
auto declMapperOp = firOpBuilder.create<mlir::omp::DeclareMapperOp>(
31423152
loc, mapperNameStr, mlirType);
3153+
converter.getMLIRSymbolTable()->insert(declMapperOp);
31433154
auto &region = declMapperOp.getRegion();
3144-
3145-
// Save insert point just after the DeclMapperOp.
3146-
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
31473155
firOpBuilder.createBlock(&region);
3148-
auto varVal =
3149-
firOpBuilder.createTemporaryAlloc(loc, mlirType, varName.ToString());
3156+
auto varVal = region.addArgument(firOpBuilder.getRefType(mlirType), loc);
31503157
converter.bindSymbol(*varName.symbol, varVal);
31513158

3152-
// Insert dummy instruction to remember the insertion position. The
3153-
// marker will be deleted by clean up passes since there are no uses.
3154-
// Remembering the position for further insertion is important since
3155-
// there are hlfir.declares inserted above while setting block arguments
3156-
// and new code from the body should be inserted after that.
3157-
mlir::Value undefMarker =
3158-
firOpBuilder.create<fir::UndefOp>(loc, firOpBuilder.getIndexType());
3159-
3160-
// Create blocks for unstructured regions. This has to be done since
3161-
// blocks are initially allocated with the function as the parent region.
3162-
if (eval.lowerAsUnstructured()) {
3163-
lower::createEmptyRegionBlocks<mlir::omp::TerminatorOp, mlir::omp::YieldOp>(
3164-
firOpBuilder, eval.getNestedEvaluations());
3165-
}
3166-
3167-
firOpBuilder.create<mlir::omp::TerminatorOp>(loc);
3168-
3169-
// Set the insertion point after the marker.
3170-
firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
3171-
genNestedEvaluations(converter, eval);
3172-
31733159
// Populate the declareMapper region with the map information.
31743160
mlir::omp::DeclareMapperInfoOperands clauseOps;
31753161
const auto *clauseList{
31763162
parser::Unwrap<parser::OmpClauseList>(declareMapperConstruct.t)};
31773163
List<Clause> clauses = makeClauses(*clauseList, semaCtx);
31783164
ClauseProcessor cp(converter, semaCtx, clauses);
31793165
cp.processMap(loc, stmtCtx, clauseOps);
3180-
31813166
firOpBuilder.create<mlir::omp::DeclareMapperInfoOp>(loc, clauseOps.mapVars);
31823167

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

0 commit comments

Comments
 (0)