[llvm-branch-commits] [OpenMP][MLIR] Extend record member map support for omp dialect to LLVM-IR (PR #82852)
Sergio Afonso via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 23 07:21:33 PDT 2024
================
@@ -2210,42 +2287,68 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers(
// Fortran pointers and allocatables, the mapping of the pointed to
// data by the descriptor (which itself, is a structure containing
// runtime information on the dynamically allocated data).
- llvm::Value *lowAddr = builder.CreatePointerCast(
- mapData.Pointers[mapDataIndex], builder.getPtrTy());
- llvm::Value *highAddr = builder.CreatePointerCast(
- builder.CreateConstGEP1_32(mapData.BaseType[mapDataIndex],
- mapData.Pointers[mapDataIndex], 1),
- builder.getPtrTy());
+ auto parentClause =
+ mlir::dyn_cast<mlir::omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
+
+ llvm::Value *lowAddr, *highAddr;
+ if (!parentClause.getPartialMap()) {
+ lowAddr = builder.CreatePointerCast(mapData.Pointers[mapDataIndex],
+ builder.getPtrTy());
+ highAddr = builder.CreatePointerCast(
+ builder.CreateConstGEP1_32(mapData.BaseType[mapDataIndex],
+ mapData.Pointers[mapDataIndex], 1),
+ builder.getPtrTy());
+ combinedInfo.Pointers.emplace_back(mapData.Pointers[mapDataIndex]);
+ } else {
+ auto mapOp =
+ mlir::dyn_cast<mlir::omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
+ int firstMemberIdx = getMapDataMemberIdx(
+ mapData, getFirstOrLastMappedMemberPtr(mapOp, true));
+ lowAddr = builder.CreatePointerCast(mapData.Pointers[firstMemberIdx],
+ builder.getPtrTy());
+ int lastMemberIdx = getMapDataMemberIdx(
+ mapData, getFirstOrLastMappedMemberPtr(mapOp, false));
+ highAddr = builder.CreatePointerCast(
+ builder.CreateGEP(mapData.BaseType[lastMemberIdx],
+ mapData.Pointers[lastMemberIdx], builder.getInt64(1)),
+ builder.getPtrTy());
+ combinedInfo.Pointers.emplace_back(mapData.Pointers[firstMemberIdx]);
+ }
+
llvm::Value *size = builder.CreateIntCast(
builder.CreatePtrDiff(builder.getInt8Ty(), highAddr, lowAddr),
builder.getInt64Ty(),
/*isSigned=*/false);
combinedInfo.Sizes.push_back(size);
- // This creates the initial MEMBER_OF mapping that consists of
- // the parent/top level container (same as above effectively, except
- // with a fixed initial compile time size and seperate maptype which
- // indicates the true mape type (tofrom etc.) and that it is a part
- // of a larger mapping and indicating the link between it and it's
- // members that are also explicitly mapped).
+ // TODO: This will need expanded to include the whole host of logic for the
+ // map flags that Clang currently supports (e.g. it hsould take the map flag
+ // of the parent map flag, remove the OMP_MAP_TARGET_PARAM and do some further
+ // case specific flag modifications), for the moment it handles what we
+ // support as expected.
llvm::omp::OpenMPOffloadMappingFlags mapFlag =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
- if (isTargetParams)
- mapFlag &= ~llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM;
llvm::omp::OpenMPOffloadMappingFlags memberOfFlag =
ompBuilder.getMemberOfFlag(combinedInfo.BasePointers.size() - 1);
ompBuilder.setCorrectMemberOfFlag(mapFlag, memberOfFlag);
- combinedInfo.Types.emplace_back(mapFlag);
- combinedInfo.DevicePointers.emplace_back(
- llvm::OpenMPIRBuilder::DeviceInfoTy::None);
- combinedInfo.Names.emplace_back(LLVM::createMappingInformation(
- mapData.MapClause[mapDataIndex]->getLoc(), ompBuilder));
- combinedInfo.BasePointers.emplace_back(mapData.BasePointers[mapDataIndex]);
- combinedInfo.Pointers.emplace_back(mapData.Pointers[mapDataIndex]);
- combinedInfo.Sizes.emplace_back(mapData.Sizes[mapDataIndex]);
-
+ // This creates the initial MEMBER_OF mapping that consists of
+ // the parent/top level container (same as above effectively, except
+ // with a fixed initial compile time size and seperate maptype which
+ // indicates the true mape type (tofrom etc.). This parent mapping is
+ // only relevant if the structure in it's totality is being mapped,
----------------
skatrak wrote:
```suggestion
// only relevant if the structure in its totality is being mapped,
```
https://github.com/llvm/llvm-project/pull/82852
More information about the llvm-branch-commits
mailing list