@@ -477,58 +477,6 @@ class MapInfoFinalizationPass
477477 return false ;
478478 }
479479
480- mlir::omp::MapInfoOp genBoxcharMemberMap (mlir::omp::MapInfoOp op,
481- fir::FirOpBuilder &builder) {
482- if (!op.getMembers ().empty ())
483- return op;
484- mlir::Location loc = op.getVarPtr ().getLoc ();
485- mlir::Value boxChar = op.getVarPtr ();
486-
487- if (mlir::isa<fir::ReferenceType>(op.getVarPtr ().getType ()))
488- boxChar = fir::LoadOp::create (builder, loc, op.getVarPtr ());
489-
490- fir::BoxCharType boxCharType =
491- mlir::dyn_cast<fir::BoxCharType>(boxChar.getType ());
492- mlir::Value boxAddr = fir::BoxOffsetOp::create (
493- builder, loc, op.getVarPtr (), fir::BoxFieldAttr::base_addr);
494-
495- mlir::ArrayAttr newMembersAttr;
496- llvm::SmallVector<llvm::SmallVector<int64_t >> memberIdx = {{0 }};
497- newMembersAttr = builder.create2DI64ArrayAttr (memberIdx);
498-
499- mlir::Value varPtr = op.getVarPtr ();
500- mlir::omp::MapInfoOp memberMapInfoOp = mlir::omp::MapInfoOp::create (
501- builder, op.getLoc (), varPtr.getType (), varPtr,
502- mlir::TypeAttr::get (boxCharType.getEleTy ()),
503- builder.getAttr <mlir::omp::ClauseMapFlagsAttr>(
504- mlir::omp::ClauseMapFlags::to |
505- mlir::omp::ClauseMapFlags::implicit),
506- builder.getAttr <mlir::omp::VariableCaptureKindAttr>(
507- mlir::omp::VariableCaptureKind::ByRef),
508- /* varPtrPtr=*/ boxAddr,
509- /* members=*/ llvm::SmallVector<mlir::Value>{},
510- /* member_index=*/ mlir::ArrayAttr{},
511- /* bounds=*/ op.getBounds (),
512- /* mapperId=*/ mlir::FlatSymbolRefAttr (), /* name=*/ op.getNameAttr (),
513- builder.getBoolAttr (false ));
514-
515- mlir::omp::MapInfoOp newMapInfoOp = mlir::omp::MapInfoOp::create (
516- builder, op.getLoc (), op.getResult ().getType (), varPtr,
517- mlir::TypeAttr::get (
518- llvm::cast<mlir::omp::PointerLikeType>(varPtr.getType ())
519- .getElementType ()),
520- op.getMapTypeAttr (), op.getMapCaptureTypeAttr (),
521- /* varPtrPtr=*/ mlir::Value{},
522- /* members=*/ llvm::SmallVector<mlir::Value>{memberMapInfoOp},
523- /* member_index=*/ newMembersAttr,
524- /* bounds=*/ llvm::SmallVector<mlir::Value>{},
525- /* mapperId=*/ mlir::FlatSymbolRefAttr (), op.getNameAttr (),
526- /* partial_map=*/ builder.getBoolAttr (false ));
527- op.replaceAllUsesWith (newMapInfoOp.getResult ());
528- op->erase ();
529- return newMapInfoOp;
530- }
531-
532480 // Expand mappings of type(C_PTR) to map their `__address` field explicitly
533481 // as a single pointer-sized member (USM-gated at callsite). This helps in
534482 // USM scenarios to ensure the pointer-sized mapping is used.
@@ -956,6 +904,14 @@ class MapInfoFinalizationPass
956904 baseAddr.erase ();
957905 }
958906
907+ static bool hasADescriptor (mlir::Operation *varOp, mlir::Type varType) {
908+ if (fir::isTypeWithDescriptor (varType) ||
909+ mlir::isa<fir::BoxCharType>(varType) ||
910+ mlir::isa_and_present<fir::BoxAddrOp>(varOp))
911+ return true ;
912+ return false ;
913+ }
914+
959915 // This pass executes on omp::MapInfoOp's containing descriptor based types
960916 // (allocatables, pointers, assumed shape etc.) and expanding them into
961917 // multiple omp::MapInfoOp's for each pointer member contained within the
@@ -1209,36 +1165,6 @@ class MapInfoFinalizationPass
12091165 return mlir::WalkResult::advance ();
12101166 });
12111167
1212- func->walk ([&](mlir::omp::MapInfoOp op) {
1213- if (!op.getMembers ().empty ())
1214- return ;
1215-
1216- if (!mlir::isa<fir::BoxCharType>(fir::unwrapRefType (op.getVarType ())))
1217- return ;
1218-
1219- // POSSIBLE_HACK_ALERT: If the boxchar has been implicitly mapped then
1220- // it is likely that the underlying pointer to the data
1221- // (!fir.ref<fir.char<k,?>>) has already been mapped. So, skip such
1222- // boxchars. We are primarily interested in boxchars that were mapped
1223- // by passes such as MapsForPrivatizedSymbols that map boxchars that
1224- // are privatized. At present, such boxchar maps are not marked
1225- // implicit. Should they be? I don't know. If they should be then
1226- // we need to change this check for early return OR live with
1227- // over-mapping.
1228- bool hasImplicitMap =
1229- (op.getMapType () & mlir::omp::ClauseMapFlags::implicit) ==
1230- mlir::omp::ClauseMapFlags::implicit;
1231- if (hasImplicitMap)
1232- return ;
1233-
1234- assert (llvm::hasSingleElement (op->getUsers ()) &&
1235- " OMPMapInfoFinalization currently only supports single users "
1236- " of a MapInfoOp" );
1237-
1238- builder.setInsertionPoint (op);
1239- genBoxcharMemberMap (op, builder);
1240- });
1241-
12421168 // Expand type(C_PTR) only when unified_shared_memory is required,
12431169 // to ensure device-visible pointer size/behavior in USM scenarios
12441170 // without changing default expectations elsewhere.
@@ -1266,9 +1192,8 @@ class MapInfoFinalizationPass
12661192 " OMPMapInfoFinalization currently only supports single users "
12671193 " of a MapInfoOp" );
12681194
1269- if (fir::isTypeWithDescriptor (op.getVarType ()) ||
1270- mlir::isa_and_present<fir::BoxAddrOp>(
1271- op.getVarPtr ().getDefiningOp ())) {
1195+ if (hasADescriptor (op.getVarPtr ().getDefiningOp (),
1196+ fir::unwrapRefType (op.getVarType ()))) {
12721197 builder.setInsertionPoint (op);
12731198 mlir::Operation *targetUser = getFirstTargetUser (op);
12741199 assert (targetUser && " expected user of map operation was not found" );
0 commit comments