@@ -3551,7 +3551,8 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
35513551
35523552static llvm::Expected<llvm::Function *>
35533553emitUserDefinedMapper (Operation *declMapperOp, llvm::IRBuilderBase &builder,
3554- LLVM::ModuleTranslation &moduleTranslation);
3554+ LLVM::ModuleTranslation &moduleTranslation,
3555+ llvm::StringRef mapperFuncName);
35553556
35563557static llvm::Expected<llvm::Function *>
35573558getOrCreateUserDefinedMapperFunc (Operation *op, llvm::IRBuilderBase &builder,
@@ -3560,27 +3561,23 @@ getOrCreateUserDefinedMapperFunc(Operation *op, llvm::IRBuilderBase &builder,
35603561 std::string mapperFuncName =
35613562 moduleTranslation.getOpenMPBuilder ()->createPlatformSpecificName (
35623563 {" omp_mapper" , declMapperOp.getSymName ()});
3564+
35633565 if (auto *lookupFunc = moduleTranslation.lookupFunction (mapperFuncName))
35643566 return lookupFunc;
35653567
3566- llvm::Expected<llvm::Function *> mapperFunc =
3567- emitUserDefinedMapper (declMapperOp, builder, moduleTranslation);
3568- if (!mapperFunc)
3569- return mapperFunc.takeError ();
3570- moduleTranslation.mapFunction (mapperFuncName, *mapperFunc);
3571- return mapperFunc;
3568+ return emitUserDefinedMapper (declMapperOp, builder, moduleTranslation,
3569+ mapperFuncName);
35723570}
35733571
35743572static llvm::Expected<llvm::Function *>
35753573emitUserDefinedMapper (Operation *op, llvm::IRBuilderBase &builder,
3576- LLVM::ModuleTranslation &moduleTranslation) {
3574+ LLVM::ModuleTranslation &moduleTranslation,
3575+ llvm::StringRef mapperFuncName) {
35773576 auto declMapperOp = cast<omp::DeclareMapperOp>(op);
35783577 auto declMapperInfoOp = declMapperOp.getDeclareMapperInfo ();
35793578 DataLayout dl = DataLayout (declMapperOp->getParentOfType <ModuleOp>());
35803579 llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
35813580 llvm::Type *varType = moduleTranslation.convertType (declMapperOp.getType ());
3582- std::string mapperName = ompBuilder->createPlatformSpecificName (
3583- {" omp_mapper" , declMapperOp.getSymName ()});
35843581 SmallVector<Value> mapVars = declMapperInfoOp.getMapVars ();
35853582
35863583 using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
@@ -3610,22 +3607,17 @@ emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
36103607 };
36113608
36123609 auto customMapperCB = [&](unsigned i) -> llvm::Expected<llvm::Function *> {
3613- llvm::Function *mapperFunc = nullptr ;
3614- if (combinedInfo.Mappers [i]) {
3615- // Call the corresponding mapper function.
3616- llvm::Expected<llvm::Function *> newFn = getOrCreateUserDefinedMapperFunc (
3617- combinedInfo.Mappers [i], builder, moduleTranslation);
3618- if (!newFn)
3619- return newFn.takeError ();
3620- mapperFunc = *newFn;
3621- }
3622- return mapperFunc;
3610+ if (!combinedInfo.Mappers [i])
3611+ return nullptr ;
3612+ return getOrCreateUserDefinedMapperFunc (combinedInfo.Mappers [i], builder,
3613+ moduleTranslation);
36233614 };
36243615
36253616 llvm::Expected<llvm::Function *> newFn = ompBuilder->emitUserDefinedMapper (
3626- genMapInfoCB, varType, mapperName , customMapperCB);
3617+ genMapInfoCB, varType, mapperFuncName , customMapperCB);
36273618 if (!newFn)
36283619 return newFn.takeError ();
3620+ moduleTranslation.mapFunction (mapperFuncName, *newFn);
36293621 return *newFn;
36303622}
36313623
@@ -3844,16 +3836,11 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
38443836
38453837 auto customMapperCB =
38463838 [&](unsigned int i) -> llvm::Expected<llvm::Function *> {
3847- llvm::Function *mapperFunc = nullptr ;
3848- if (combinedInfo.Mappers [i]) {
3849- info.HasMapper = true ;
3850- llvm::Expected<llvm::Function *> newFn = getOrCreateUserDefinedMapperFunc (
3851- combinedInfo.Mappers [i], builder, moduleTranslation);
3852- if (!newFn)
3853- return newFn.takeError ();
3854- mapperFunc = *newFn;
3855- }
3856- return mapperFunc;
3839+ if (!combinedInfo.Mappers [i])
3840+ return nullptr ;
3841+ info.HasMapper = true ;
3842+ return getOrCreateUserDefinedMapperFunc (combinedInfo.Mappers [i], builder,
3843+ moduleTranslation);
38573844 };
38583845
38593846 llvm::OpenMPIRBuilder::LocationDescription ompLoc (builder);
@@ -4557,16 +4544,11 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
45574544
45584545 auto customMapperCB =
45594546 [&](unsigned int i) -> llvm::Expected<llvm::Function *> {
4560- llvm::Function *mapperFunc = nullptr ;
4561- if (combinedInfos.Mappers [i]) {
4562- info.HasMapper = true ;
4563- llvm::Expected<llvm::Function *> newFn = getOrCreateUserDefinedMapperFunc (
4564- combinedInfos.Mappers [i], builder, moduleTranslation);
4565- if (!newFn)
4566- return newFn.takeError ();
4567- mapperFunc = *newFn;
4568- }
4569- return mapperFunc;
4547+ if (!combinedInfos.Mappers [i])
4548+ return nullptr ;
4549+ info.HasMapper = true ;
4550+ return getOrCreateUserDefinedMapperFunc (combinedInfos.Mappers [i], builder,
4551+ moduleTranslation);
45704552 };
45714553
45724554 llvm::Value *ifCond = nullptr ;
@@ -4811,6 +4793,8 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
48114793 // was created in the region that handles their parent operation.
48124794 // `declare_reduction` will be used by reductions and is not
48134795 // converted directly, skip it.
4796+ // `declare_mapper` and `declare_mapper.info` are handled whenever they
4797+ // are referred to through a `map` clause.
48144798 // `critical.declare` is only used to declare names of critical
48154799 // sections which will be used by `critical` ops and hence can be
48164800 // ignored for lowering. The OpenMP IRBuilder will create unique
0 commit comments