Skip to content

Commit 0cd7e8a

Browse files
authored
[MLIR][OpenMP] Assert on map translation functions, NFC (#137199)
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 30b0946 commit 0cd7e8a

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
@@ -3720,6 +3720,9 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers(
37203720
LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder,
37213721
llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo,
37223722
MapInfoData &mapData, uint64_t mapDataIndex, bool isTargetParams) {
3723+
assert(!ompBuilder.Config.isTargetDevice() &&
3724+
"function only supported for host device codegen");
3725+
37233726
// Map the first segment of our structure
37243727
combinedInfo.Types.emplace_back(
37253728
isTargetParams
@@ -3828,6 +3831,8 @@ static void processMapMembersWithParent(
38283831
llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo,
38293832
MapInfoData &mapData, uint64_t mapDataIndex,
38303833
llvm::omp::OpenMPOffloadMappingFlags memberOfFlag) {
3834+
assert(!ompBuilder.Config.isTargetDevice() &&
3835+
"function only supported for host device codegen");
38313836

38323837
auto parentClause =
38333838
llvm::cast<omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
@@ -3941,6 +3946,9 @@ static void processMapWithMembersOf(LLVM::ModuleTranslation &moduleTranslation,
39413946
DataLayout &dl, MapInfosTy &combinedInfo,
39423947
MapInfoData &mapData, uint64_t mapDataIndex,
39433948
bool isTargetParams) {
3949+
assert(!ompBuilder.Config.isTargetDevice() &&
3950+
"function only supported for host device codegen");
3951+
39443952
auto parentClause =
39453953
llvm::cast<omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);
39463954

@@ -3982,6 +3990,8 @@ static void
39823990
createAlteredByCaptureMap(MapInfoData &mapData,
39833991
LLVM::ModuleTranslation &moduleTranslation,
39843992
llvm::IRBuilderBase &builder) {
3993+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
3994+
"function only supported for host device codegen");
39853995
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
39863996
// if it's declare target, skip it, it's handled separately.
39873997
if (!mapData.IsDeclareTarget[i]) {
@@ -4046,6 +4056,9 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
40464056
LLVM::ModuleTranslation &moduleTranslation,
40474057
DataLayout &dl, MapInfosTy &combinedInfo,
40484058
MapInfoData &mapData, bool isTargetParams = false) {
4059+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
4060+
"function only supported for host device codegen");
4061+
40494062
// We wish to modify some of the methods in which arguments are
40504063
// passed based on their capture type by the target region, this can
40514064
// involve generating new loads and stores, which changes the
@@ -4057,8 +4070,7 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
40574070
// kernel arg structure. It primarily becomes relevant in cases like
40584071
// bycopy, or byref range'd arrays. In the default case, we simply
40594072
// pass thee pointer byref as both basePointer and pointer.
4060-
if (!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice())
4061-
createAlteredByCaptureMap(mapData, moduleTranslation, builder);
4073+
createAlteredByCaptureMap(mapData, moduleTranslation, builder);
40624074

40634075
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
40644076

@@ -4092,6 +4104,8 @@ emitUserDefinedMapper(Operation *declMapperOp, llvm::IRBuilderBase &builder,
40924104
static llvm::Expected<llvm::Function *>
40934105
getOrCreateUserDefinedMapperFunc(Operation *op, llvm::IRBuilderBase &builder,
40944106
LLVM::ModuleTranslation &moduleTranslation) {
4107+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
4108+
"function only supported for host device codegen");
40954109
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
40964110
std::string mapperFuncName =
40974111
moduleTranslation.getOpenMPBuilder()->createPlatformSpecificName(
@@ -4108,6 +4122,8 @@ static llvm::Expected<llvm::Function *>
41084122
emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
41094123
LLVM::ModuleTranslation &moduleTranslation,
41104124
llvm::StringRef mapperFuncName) {
4125+
assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
4126+
"function only supported for host device codegen");
41114127
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
41124128
auto declMapperInfoOp = declMapperOp.getDeclareMapperInfo();
41134129
DataLayout dl = DataLayout(declMapperOp->getParentOfType<ModuleOp>());
@@ -4597,6 +4613,8 @@ static void
45974613
handleDeclareTargetMapVar(MapInfoData &mapData,
45984614
LLVM::ModuleTranslation &moduleTranslation,
45994615
llvm::IRBuilderBase &builder, llvm::Function *func) {
4616+
assert(moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
4617+
"function only supported for target device codegen");
46004618
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
46014619
// In the case of declare target mapped variables, the basePointer is
46024620
// the reference pointer generated by the convertDeclareTargetAttr
@@ -4689,6 +4707,8 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg,
46894707
LLVM::ModuleTranslation &moduleTranslation,
46904708
llvm::IRBuilderBase::InsertPoint allocaIP,
46914709
llvm::IRBuilderBase::InsertPoint codeGenIP) {
4710+
assert(ompBuilder.Config.isTargetDevice() &&
4711+
"function only supported for target device codegen");
46924712
builder.restoreIP(allocaIP);
46934713

46944714
omp::VariableCaptureKind capture = omp::VariableCaptureKind::ByRef;

0 commit comments

Comments
 (0)