@@ -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 ®ion = declMapperOp.getRegion ();
2637-
2638- // Save insert point just after the DeclMapperOp.
2639- mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint ();
26402648 firOpBuilder.createBlock (®ion);
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