@@ -39,90 +39,6 @@ namespace flangomp {
3939#define DEBUG_TYPE " do-concurrent-conversion"
4040#define DBGS () (llvm::dbgs() << " [" DEBUG_TYPE << " ]: " )
4141
42- namespace Fortran {
43- namespace lower {
44- namespace omp {
45- namespace internal {
46- mlir::Value mapTemporaryValue (fir::FirOpBuilder &builder,
47- mlir::omp::TargetOp targetOp, mlir::Value val,
48- llvm::StringRef name) {
49- mlir::OpBuilder::InsertionGuard guard (builder);
50- builder.setInsertionPointAfterValue (val);
51- auto copyVal = builder.createTemporary (val.getLoc (), val.getType ());
52- builder.createStoreWithConvert (copyVal.getLoc (), val, copyVal);
53-
54- llvm::SmallVector<mlir::Value> bounds;
55- builder.setInsertionPoint (targetOp);
56- mlir::Value mapOp = Fortran::common::openmp::createMapInfoOp (
57- builder, copyVal.getLoc (), copyVal,
58- /* varPtrPtr=*/ mlir::Value{}, name.str (), bounds,
59- /* members=*/ llvm::SmallVector<mlir::Value>{},
60- /* membersIndex=*/ mlir::ArrayAttr{},
61- static_cast <std::underlying_type_t <llvm::omp::OpenMPOffloadMappingFlags>>(
62- llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT),
63- mlir::omp::VariableCaptureKind::ByCopy, copyVal.getType ());
64-
65- mlir::Region &targetRegion = targetOp.getRegion ();
66-
67- auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp);
68- unsigned insertIndex =
69- argIface.getMapBlockArgsStart () + argIface.numMapBlockArgs ();
70- targetOp.getMapVarsMutable ().append (mlir::ValueRange{mapOp});
71- mlir::Value clonedValArg =
72- targetRegion.insertArgument (insertIndex, mapOp.getType (), mapOp.getLoc ());
73-
74- mlir::Block *targetEntryBlock = &targetRegion.getBlocks ().front ();
75- builder.setInsertionPointToStart (targetEntryBlock);
76- auto loadOp =
77- builder.create <fir::LoadOp>(clonedValArg.getLoc (), clonedValArg);
78- return loadOp.getResult ();
79- }
80-
81- // / Check if cloning the bounds introduced any dependency on the outer region.
82- // / If so, then either clone them as well if they are MemoryEffectFree, or else
83- // / copy them to a new temporary and add them to the map and block_argument
84- // / lists and replace their uses with the new temporary.
85- // /
86- // / TODO: similar to the above functions, this is copied from OpenMP lowering
87- // / (in this case, from `genBodyOfTargetOp`). Once we move to a common lib for
88- // / these utils this will move as well.
89- void cloneOrMapRegionOutsiders (fir::FirOpBuilder &builder,
90- mlir::omp::TargetOp targetOp) {
91- mlir::Region &targetRegion = targetOp.getRegion ();
92- mlir::Block *targetEntryBlock = &targetRegion.getBlocks ().front ();
93- llvm::SetVector<mlir::Value> valuesDefinedAbove;
94- mlir::getUsedValuesDefinedAbove (targetRegion, valuesDefinedAbove);
95-
96- while (!valuesDefinedAbove.empty ()) {
97- for (mlir::Value val : valuesDefinedAbove) {
98- mlir::Operation *valOp = val.getDefiningOp ();
99- assert (valOp != nullptr );
100- if (mlir::isMemoryEffectFree (valOp)) {
101- mlir::Operation *clonedOp = valOp->clone ();
102- targetEntryBlock->push_front (clonedOp);
103- assert (clonedOp->getNumResults () == 1 );
104- val.replaceUsesWithIf (
105- clonedOp->getResult (0 ), [targetEntryBlock](mlir::OpOperand &use) {
106- return use.getOwner ()->getBlock () == targetEntryBlock;
107- });
108- } else {
109- mlir::Value mappedTemp = mapTemporaryValue (builder, targetOp, val,
110- /* name=*/ llvm::StringRef{});
111- val.replaceUsesWithIf (
112- mappedTemp, [targetEntryBlock](mlir::OpOperand &use) {
113- return use.getOwner ()->getBlock () == targetEntryBlock;
114- });
115- }
116- }
117- valuesDefinedAbove.clear ();
118- mlir::getUsedValuesDefinedAbove (targetRegion, valuesDefinedAbove);
119- }
120- }
121- } // namespace internal
122- } // namespace omp
123- } // namespace lower
124- } // namespace Fortran
125-
12642namespace {
12743namespace looputils {
12844// / Stores info needed about the induction/iteration variable for each `do
@@ -699,7 +615,12 @@ class DoConcurrentConversion
699615 mapper.lookup (loopNestClauseOps.loopSteps [i]);
700616 }
701617
702- Fortran::lower::omp::internal::cloneOrMapRegionOutsiders (builder, targetOp);
618+ // Check if cloning the bounds introduced any dependency on the outer
619+ // region. If so, then either clone them as well if they are
620+ // MemoryEffectFree, or else copy them to a new temporary and add them to
621+ // the map and block_argument lists and replace their uses with the new
622+ // temporary.
623+ Fortran::common::openmp::cloneOrMapRegionOutsiders (builder, targetOp);
703624 rewriter.setInsertionPoint (
704625 rewriter.create <mlir::omp::TerminatorOp>(targetOp.getLoc ()));
705626
@@ -732,11 +653,11 @@ class DoConcurrentConversion
732653 llvm::zip_equal (targetShapeCreationInfo.startIndices ,
733654 targetShapeCreationInfo.extents )) {
734655 shapeShiftOperands.push_back (
735- Fortran::lower::omp::internal ::mapTemporaryValue (
656+ Fortran::common::openmp ::mapTemporaryValue (
736657 builder, targetOp, startIndex,
737658 liveInName + " .start_idx.dim" + std::to_string (shapeIdx)));
738659 shapeShiftOperands.push_back (
739- Fortran::lower::omp::internal ::mapTemporaryValue (
660+ Fortran::common::openmp ::mapTemporaryValue (
740661 builder, targetOp, extent,
741662 liveInName + " .extent.dim" + std::to_string (shapeIdx)));
742663 ++shapeIdx;
@@ -751,10 +672,9 @@ class DoConcurrentConversion
751672 llvm::SmallVector<mlir::Value> shapeOperands;
752673 size_t shapeIdx = 0 ;
753674 for (auto extent : targetShapeCreationInfo.extents ) {
754- shapeOperands.push_back (
755- Fortran::lower::omp::internal::mapTemporaryValue (
756- builder, targetOp, extent,
757- liveInName + " .extent.dim" + std::to_string (shapeIdx)));
675+ shapeOperands.push_back (Fortran::common::openmp::mapTemporaryValue (
676+ builder, targetOp, extent,
677+ liveInName + " .extent.dim" + std::to_string (shapeIdx)));
758678 ++shapeIdx;
759679 }
760680
0 commit comments