[Mlir-commits] [flang] [llvm] [mlir] [flang][OpenMP] Implicitly map allocatable record fields (PR #117867)
Leandro Lupori
llvmlistbot at llvm.org
Tue Dec 3 05:37:34 PST 2024
================
@@ -486,6 +490,157 @@ class MapInfoFinalizationPass
// iterations from previous function scopes.
localBoxAllocas.clear();
+ // First, walk `omp.map.info` ops to see if any record members should be
+ // implicitly mapped.
+ func->walk([&](mlir::omp::MapInfoOp op) {
+ mlir::Type underlyingType =
+ fir::unwrapRefType(op.getVarPtr().getType());
+
+ if (!fir::isRecordWithAllocatableMember(underlyingType))
+ return mlir::WalkResult::advance();
+
+ // TODO For now, only consider `omp.target` ops. Other ops that support
+ // `map` clauses will follow later.
+ mlir::omp::TargetOp target =
+ mlir::dyn_cast_if_present<mlir::omp::TargetOp>(
+ getFirstTargetUser(op));
+
+ if (!target)
+ return mlir::WalkResult::advance();
+
+ auto mapClauseOwner =
+ llvm::dyn_cast<mlir::omp::MapClauseOwningOpInterface>(*target);
+
+ int64_t mapVarIdx = mapClauseOwner.getOperandIndexForMap(op);
+ assert(mapVarIdx >= 0 &&
+ mapVarIdx <
+ static_cast<int64_t>(mapClauseOwner.getMapVars().size()));
+
+ auto argIface =
+ llvm::dyn_cast<mlir::omp::BlockArgOpenMPOpInterface>(*target);
+ // TODO How should `map` block argument that correspond to: `private`,
+ // `use_device_addr`, `use_device_ptr`, be handled?
+ mlir::BlockArgument opBlockArg = argIface.getMapBlockArgs()[mapVarIdx];
+ llvm::SetVector<mlir::Operation *> mapVarForwardSlice;
+ mlir::getForwardSlice(opBlockArg, &mapVarForwardSlice);
+
+ mapVarForwardSlice.remove_if([&](mlir::Operation *sliceOp) {
+ // TODO Support coordinate_of ops.
+ //
+ // TODO Support call ops by recursively examining the forward slice of
+ // the corresponding paramemter to the field in the called function.
----------------
luporl wrote:
```suggestion
// the corresponding parameter to the field in the called function.
```
https://github.com/llvm/llvm-project/pull/117867
More information about the Mlir-commits
mailing list