Skip to content

Commit 6b7f89c

Browse files
committed
[OpenMP][MLIR] Descriptor explicit member map lowering changes
This is one of 3 PRs in a PR stack that aims to add support for explicit mapping of allocatable members in derived types. The primary changes in this PR are the OpenMPToLLVMIRTranslation.cpp changes, which are small and seek to alter the current member mapping to add an additional map insertion for pointers. Effectively, if the member is a pointer (currently indicated by having a varPtrPtr field) we add an additional map for the pointer and then alter the subsequent mapping of the member (the data) to utilise the member rather than the parents base pointer. This appears to be necessary in certain cases when mapping pointer data within record types to avoid segfaulting on device (due to incorrect data mapping). In general this record type mapping may be simplifiable in the future. There are also additions of tests which should help to showcase the affect of the changes above. Pull Request: llvm#96265
1 parent 65a943d commit 6b7f89c

File tree

3 files changed

+405
-34
lines changed

3 files changed

+405
-34
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

+31-3
Original file line numberDiff line numberDiff line change
@@ -2299,10 +2299,13 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers(
22992299
mlir::dyn_cast<mlir::omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
23002300
int firstMemberIdx = getMapDataMemberIdx(
23012301
mapData, getFirstOrLastMappedMemberPtr(mapOp, true));
2302-
lowAddr = builder.CreatePointerCast(mapData.Pointers[firstMemberIdx],
2303-
builder.getPtrTy());
23042302
int lastMemberIdx = getMapDataMemberIdx(
23052303
mapData, getFirstOrLastMappedMemberPtr(mapOp, false));
2304+
2305+
// NOTE/TODO: Should perhaps use OriginalValue here instead of Pointers to
2306+
// avoid offset or any manipulations interfering with the calculation.
2307+
lowAddr = builder.CreatePointerCast(mapData.Pointers[firstMemberIdx],
2308+
builder.getPtrTy());
23062309
highAddr = builder.CreatePointerCast(
23072310
builder.CreateGEP(mapData.BaseType[lastMemberIdx],
23082311
mapData.Pointers[lastMemberIdx], builder.getInt64(1)),
@@ -2385,6 +2388,24 @@ static void processMapMembersWithParent(
23852388

23862389
assert(memberDataIdx >= 0 && "could not find mapped member of structure");
23872390

2391+
if (checkIfPointerMap(memberClause)) {
2392+
auto mapFlag = llvm::omp::OpenMPOffloadMappingFlags(
2393+
memberClause.getMapType().value());
2394+
mapFlag &= ~llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM;
2395+
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF;
2396+
ompBuilder.setCorrectMemberOfFlag(mapFlag, memberOfFlag);
2397+
combinedInfo.Types.emplace_back(mapFlag);
2398+
combinedInfo.DevicePointers.emplace_back(
2399+
llvm::OpenMPIRBuilder::DeviceInfoTy::None);
2400+
combinedInfo.Names.emplace_back(
2401+
LLVM::createMappingInformation(memberClause.getLoc(), ompBuilder));
2402+
combinedInfo.BasePointers.emplace_back(
2403+
mapData.BasePointers[mapDataIndex]);
2404+
combinedInfo.Pointers.emplace_back(mapData.BasePointers[memberDataIdx]);
2405+
combinedInfo.Sizes.emplace_back(builder.getInt64(
2406+
moduleTranslation.getLLVMModule()->getDataLayout().getPointerSize()));
2407+
}
2408+
23882409
// Same MemberOfFlag to indicate its link with parent and other members
23892410
// of.
23902411
auto mapFlag =
@@ -2400,7 +2421,14 @@ static void processMapMembersWithParent(
24002421
llvm::OpenMPIRBuilder::DeviceInfoTy::None);
24012422
combinedInfo.Names.emplace_back(
24022423
LLVM::createMappingInformation(memberClause.getLoc(), ompBuilder));
2403-
combinedInfo.BasePointers.emplace_back(mapData.BasePointers[mapDataIndex]);
2424+
2425+
if (checkIfPointerMap(memberClause))
2426+
combinedInfo.BasePointers.emplace_back(
2427+
mapData.BasePointers[memberDataIdx]);
2428+
else
2429+
combinedInfo.BasePointers.emplace_back(
2430+
mapData.BasePointers[mapDataIndex]);
2431+
24042432
combinedInfo.Pointers.emplace_back(mapData.Pointers[memberDataIdx]);
24052433
combinedInfo.Sizes.emplace_back(mapData.Sizes[memberDataIdx]);
24062434
}

0 commit comments

Comments
 (0)