Skip to content

Commit b70cbfa

Browse files
committed
[MLIR][OpenMP] Assert on map translation functions, NFC
This patch adds assertions to map-related MLIR to LLVM IR translation functions and utils to explicitly document whether they are intended for host or device compilation only. Over time, map-related handling has increased in complexity. This is compounded by the fact that some handling is device-specific and some is host-specific. By explicitly asserting on these functions on the expected compilation pass, the flow should become slighlty easier to follow.
1 parent de00b77 commit b70cbfa

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,9 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers(
35633563
LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder,
35643564
llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo,
35653565
MapInfoData &mapData, uint64_t mapDataIndex, bool isTargetParams) {
3566+
assert(!ompBuilder.Config.isTargetDevice() &&
3567+
"function only supported for host device codegen");
3568+
35663569
// Map the first segment of our structure
35673570
combinedInfo.Types.emplace_back(
35683571
isTargetParams
@@ -3671,6 +3674,8 @@ static void processMapMembersWithParent(
36713674
llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo,
36723675
MapInfoData &mapData, uint64_t mapDataIndex,
36733676
llvm::omp::OpenMPOffloadMappingFlags memberOfFlag) {
3677+
assert(!ompBuilder.Config.isTargetDevice() &&
3678+
"function only supported for host device codegen");
36743679

36753680
auto parentClause =
36763681
llvm::cast<omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
@@ -3784,6 +3789,9 @@ static void processMapWithMembersOf(LLVM::ModuleTranslation &moduleTranslation,
37843789
DataLayout &dl, MapInfosTy &combinedInfo,
37853790
MapInfoData &mapData, uint64_t mapDataIndex,
37863791
bool isTargetParams) {
3792+
assert(!ompBuilder.Config.isTargetDevice() &&
3793+
"function only supported for host device codegen");
3794+
37873795
auto parentClause =
37883796
llvm::cast<omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
37893797

@@ -3825,6 +3833,8 @@ static void
38253833
createAlteredByCaptureMap(MapInfoData &mapData,
38263834
LLVM::ModuleTranslation &moduleTranslation,
38273835
llvm::IRBuilderBase &builder) {
3836+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
3837+
"function only supported for host device codegen");
38283838
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
38293839
// if it's declare target, skip it, it's handled separately.
38303840
if (!mapData.IsDeclareTarget[i]) {
@@ -3889,6 +3899,9 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
38893899
LLVM::ModuleTranslation &moduleTranslation,
38903900
DataLayout &dl, MapInfosTy &combinedInfo,
38913901
MapInfoData &mapData, bool isTargetParams = false) {
3902+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
3903+
"function only supported for host device codegen");
3904+
38923905
// We wish to modify some of the methods in which arguments are
38933906
// passed based on their capture type by the target region, this can
38943907
// involve generating new loads and stores, which changes the
@@ -3900,8 +3913,7 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
39003913
// kernel arg structure. It primarily becomes relevant in cases like
39013914
// bycopy, or byref range'd arrays. In the default case, we simply
39023915
// pass thee pointer byref as both basePointer and pointer.
3903-
if (!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice())
3904-
createAlteredByCaptureMap(mapData, moduleTranslation, builder);
3916+
createAlteredByCaptureMap(mapData, moduleTranslation, builder);
39053917

39063918
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
39073919

@@ -3935,6 +3947,8 @@ emitUserDefinedMapper(Operation *declMapperOp, llvm::IRBuilderBase &builder,
39353947
static llvm::Expected<llvm::Function *>
39363948
getOrCreateUserDefinedMapperFunc(Operation *op, llvm::IRBuilderBase &builder,
39373949
LLVM::ModuleTranslation &moduleTranslation) {
3950+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
3951+
"function only supported for host device codegen");
39383952
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
39393953
std::string mapperFuncName =
39403954
moduleTranslation.getOpenMPBuilder()->createPlatformSpecificName(
@@ -3951,6 +3965,8 @@ static llvm::Expected<llvm::Function *>
39513965
emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
39523966
LLVM::ModuleTranslation &moduleTranslation,
39533967
llvm::StringRef mapperFuncName) {
3968+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
3969+
"function only supported for host device codegen");
39543970
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
39553971
auto declMapperInfoOp = declMapperOp.getDeclareMapperInfo();
39563972
DataLayout dl = DataLayout(declMapperOp->getParentOfType<ModuleOp>());
@@ -4440,6 +4456,8 @@ static void
44404456
handleDeclareTargetMapVar(MapInfoData &mapData,
44414457
LLVM::ModuleTranslation &moduleTranslation,
44424458
llvm::IRBuilderBase &builder, llvm::Function *func) {
4459+
assert(moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
4460+
"function only supported for target device codegen");
44434461
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
44444462
// In the case of declare target mapped variables, the basePointer is
44454463
// the reference pointer generated by the convertDeclareTargetAttr
@@ -4532,6 +4550,8 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg,
45324550
LLVM::ModuleTranslation &moduleTranslation,
45334551
llvm::IRBuilderBase::InsertPoint allocaIP,
45344552
llvm::IRBuilderBase::InsertPoint codeGenIP) {
4553+
assert(ompBuilder.Config.isTargetDevice() &&
4554+
"function only supported for target device codegen");
45354555
builder.restoreIP(allocaIP);
45364556

45374557
omp::VariableCaptureKind capture = omp::VariableCaptureKind::ByRef;

0 commit comments

Comments
 (0)