@@ -3551,7 +3551,8 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
3551
3551
3552
3552
static llvm::Expected<llvm::Function *>
3553
3553
emitUserDefinedMapper (Operation *declMapperOp, llvm::IRBuilderBase &builder,
3554
- LLVM::ModuleTranslation &moduleTranslation);
3554
+ LLVM::ModuleTranslation &moduleTranslation,
3555
+ llvm::StringRef mapperFuncName);
3555
3556
3556
3557
static llvm::Expected<llvm::Function *>
3557
3558
getOrCreateUserDefinedMapperFunc (Operation *op, llvm::IRBuilderBase &builder,
@@ -3560,27 +3561,23 @@ getOrCreateUserDefinedMapperFunc(Operation *op, llvm::IRBuilderBase &builder,
3560
3561
std::string mapperFuncName =
3561
3562
moduleTranslation.getOpenMPBuilder ()->createPlatformSpecificName (
3562
3563
{" omp_mapper" , declMapperOp.getSymName ()});
3564
+
3563
3565
if (auto *lookupFunc = moduleTranslation.lookupFunction (mapperFuncName))
3564
3566
return lookupFunc;
3565
3567
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);
3572
3570
}
3573
3571
3574
3572
static llvm::Expected<llvm::Function *>
3575
3573
emitUserDefinedMapper (Operation *op, llvm::IRBuilderBase &builder,
3576
- LLVM::ModuleTranslation &moduleTranslation) {
3574
+ LLVM::ModuleTranslation &moduleTranslation,
3575
+ llvm::StringRef mapperFuncName) {
3577
3576
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
3578
3577
auto declMapperInfoOp = declMapperOp.getDeclareMapperInfo ();
3579
3578
DataLayout dl = DataLayout (declMapperOp->getParentOfType <ModuleOp>());
3580
3579
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
3581
3580
llvm::Type *varType = moduleTranslation.convertType (declMapperOp.getType ());
3582
- std::string mapperName = ompBuilder->createPlatformSpecificName (
3583
- {" omp_mapper" , declMapperOp.getSymName ()});
3584
3581
SmallVector<Value> mapVars = declMapperInfoOp.getMapVars ();
3585
3582
3586
3583
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
@@ -3610,22 +3607,17 @@ emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
3610
3607
};
3611
3608
3612
3609
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);
3623
3614
};
3624
3615
3625
3616
llvm::Expected<llvm::Function *> newFn = ompBuilder->emitUserDefinedMapper (
3626
- genMapInfoCB, varType, mapperName , customMapperCB);
3617
+ genMapInfoCB, varType, mapperFuncName , customMapperCB);
3627
3618
if (!newFn)
3628
3619
return newFn.takeError ();
3620
+ moduleTranslation.mapFunction (mapperFuncName, *newFn);
3629
3621
return *newFn;
3630
3622
}
3631
3623
@@ -3844,16 +3836,11 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
3844
3836
3845
3837
auto customMapperCB =
3846
3838
[&](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);
3857
3844
};
3858
3845
3859
3846
llvm::OpenMPIRBuilder::LocationDescription ompLoc (builder);
@@ -4557,16 +4544,11 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
4557
4544
4558
4545
auto customMapperCB =
4559
4546
[&](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);
4570
4552
};
4571
4553
4572
4554
llvm::Value *ifCond = nullptr ;
@@ -4811,6 +4793,8 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
4811
4793
// was created in the region that handles their parent operation.
4812
4794
// `declare_reduction` will be used by reductions and is not
4813
4795
// converted directly, skip it.
4796
+ // `declare_mapper` and `declare_mapper.info` are handled whenever they
4797
+ // are referred to through a `map` clause.
4814
4798
// `critical.declare` is only used to declare names of critical
4815
4799
// sections which will be used by `critical` ops and hence can be
4816
4800
// ignored for lowering. The OpenMP IRBuilder will create unique
0 commit comments