@@ -520,59 +520,6 @@ class MapInfoFinalizationPass
520520 return false ;
521521 }
522522
523- mlir::omp::MapInfoOp genBoxcharMemberMap (mlir::omp::MapInfoOp op,
524- fir::FirOpBuilder &builder) {
525- if (!op.getMembers ().empty ())
526- return op;
527- mlir::Location loc = op.getVarPtr ().getLoc ();
528- mlir::Value boxChar = op.getVarPtr ();
529-
530- if (mlir::isa<fir::ReferenceType>(op.getVarPtr ().getType ()))
531- boxChar = fir::LoadOp::create (builder, loc, op.getVarPtr ());
532-
533- fir::BoxCharType boxCharType =
534- mlir::dyn_cast<fir::BoxCharType>(boxChar.getType ());
535- mlir::Value boxAddr = fir::BoxOffsetOp::create (
536- builder, loc, op.getVarPtr (), fir::BoxFieldAttr::base_addr);
537-
538- mlir::ArrayAttr newMembersAttr;
539- llvm::SmallVector<llvm::SmallVector<int64_t >> memberIdx = {{0 }};
540- newMembersAttr = builder.create2DI64ArrayAttr (memberIdx);
541-
542- mlir::Value varPtr = op.getVarPtr ();
543- mlir::omp::MapInfoOp memberMapInfoOp = mlir::omp::MapInfoOp::create (
544- builder, op.getLoc (), varPtr.getType (), varPtr,
545- mlir::TypeAttr::get (boxCharType.getEleTy ()), op.getMapTypeAttr (),
546- builder.getAttr <mlir::omp::VariableCaptureKindAttr>(
547- mlir::omp::VariableCaptureKind::ByRef),
548- /* varPtrPtr=*/ boxAddr,
549- /* members=*/ llvm::SmallVector<mlir::Value>{},
550- /* member_index=*/ mlir::ArrayAttr{},
551- /* bounds=*/ op.getBounds (),
552- /* mapperId=*/ mlir::FlatSymbolRefAttr (), /* name=*/ op.getNameAttr (),
553- builder.getBoolAttr (false ));
554-
555- mlir::omp::MapInfoOp newMapInfoOp = mlir::omp::MapInfoOp::create (
556- builder, op.getLoc (), op.getResult ().getType (), varPtr,
557- mlir::TypeAttr::get (
558- llvm::cast<mlir::omp::PointerLikeType>(varPtr.getType ())
559- .getElementType ()),
560- builder.getAttr <mlir::omp::ClauseMapFlagsAttr>(
561- mlir::omp::ClauseMapFlags::attach | mlir::omp::ClauseMapFlags::to |
562- mlir::omp::ClauseMapFlags::always |
563- mlir::omp::ClauseMapFlags::descriptor),
564- op.getMapCaptureTypeAttr (),
565- /* varPtrPtr=*/ mlir::Value{},
566- /* members=*/ llvm::SmallVector<mlir::Value>{memberMapInfoOp},
567- /* member_index=*/ newMembersAttr,
568- /* bounds=*/ llvm::SmallVector<mlir::Value>{},
569- /* mapperId=*/ mlir::FlatSymbolRefAttr (), op.getNameAttr (),
570- /* partial_map=*/ builder.getBoolAttr (false ));
571- op.replaceAllUsesWith (newMapInfoOp.getResult ());
572- op->erase ();
573- return newMapInfoOp;
574- }
575-
576523 // Expand mappings of type(C_PTR) to map their `__address` field explicitly
577524 // as a single pointer-sized member (USM-gated at callsite). This helps in
578525 // USM scenarios to ensure the pointer-sized mapping is used.
@@ -988,6 +935,14 @@ class MapInfoFinalizationPass
988935 baseAddr.erase ();
989936 }
990937
938+ static bool hasADescriptor (mlir::Operation *varOp, mlir::Type varType) {
939+ if (fir::isTypeWithDescriptor (varType) ||
940+ mlir::isa<fir::BoxCharType>(varType) ||
941+ mlir::isa_and_present<fir::BoxAddrOp>(varOp))
942+ return true ;
943+ return false ;
944+ }
945+
991946 // This pass executes on omp::MapInfoOp's containing descriptor based types
992947 // (allocatables, pointers, assumed shape etc.) and expanding them into
993948 // multiple omp::MapInfoOp's for each pointer member contained within the
@@ -1241,36 +1196,6 @@ class MapInfoFinalizationPass
12411196 op.setPartialMap (true );
12421197 });
12431198
1244- func->walk ([&](mlir::omp::MapInfoOp op) {
1245- if (!op.getMembers ().empty ())
1246- return ;
1247-
1248- if (!mlir::isa<fir::BoxCharType>(fir::unwrapRefType (op.getVarType ())))
1249- return ;
1250-
1251- // POSSIBLE_HACK_ALERT: If the boxchar has been implicitly mapped then
1252- // it is likely that the underlying pointer to the data
1253- // (!fir.ref<fir.char<k,?>>) has already been mapped. So, skip such
1254- // boxchars. We are primarily interested in boxchars that were mapped
1255- // by passes such as MapsForPrivatizedSymbols that map boxchars that
1256- // are privatized. At present, such boxchar maps are not marked
1257- // implicit. Should they be? I don't know. If they should be then
1258- // we need to change this check for early return OR live with
1259- // over-mapping.
1260- bool hasImplicitMap =
1261- (op.getMapType () & mlir::omp::ClauseMapFlags::implicit) ==
1262- mlir::omp::ClauseMapFlags::implicit;
1263- if (hasImplicitMap)
1264- return ;
1265-
1266- assert (llvm::hasSingleElement (op->getUsers ()) &&
1267- " OMPMapInfoFinalization currently only supports single users "
1268- " of a MapInfoOp" );
1269-
1270- builder.setInsertionPoint (op);
1271- genBoxcharMemberMap (op, builder);
1272- });
1273-
12741199 // Expand type(C_PTR) only when unified_shared_memory is required,
12751200 // to ensure device-visible pointer size/behavior in USM scenarios
12761201 // without changing default expectations elsewhere.
@@ -1298,9 +1223,8 @@ class MapInfoFinalizationPass
12981223 " OMPMapInfoFinalization currently only supports single users "
12991224 " of a MapInfoOp" );
13001225
1301- if (fir::isTypeWithDescriptor (op.getVarType ()) ||
1302- mlir::isa_and_present<fir::BoxAddrOp>(
1303- op.getVarPtr ().getDefiningOp ())) {
1226+ if (hasADescriptor (op.getVarPtr ().getDefiningOp (),
1227+ fir::unwrapRefType (op.getVarType ()))) {
13041228 builder.setInsertionPoint (op);
13051229 mlir::Operation *targetUser = getFirstTargetUser (op);
13061230 assert (targetUser && " expected user of map operation was not found" );
0 commit comments