@@ -1254,13 +1254,13 @@ static LogicalResult allocAndInitializeReductionVars(
1254
1254
// / Allocate delayed private variables. Returns the basic block which comes
1255
1255
// / after all of these allocations. llvm::Value * for each of these private
1256
1256
// / variables are populated in llvmPrivateVars.
1257
- template <class OP >
1258
1257
static llvm::Expected<llvm::BasicBlock *>
1259
- allocatePrivateVars (OP opInst, llvm::IRBuilderBase &builder,
1258
+ allocatePrivateVars (llvm::IRBuilderBase &builder,
1260
1259
LLVM::ModuleTranslation &moduleTranslation,
1261
1260
MutableArrayRef<BlockArgument> privateBlockArgs,
1262
1261
MutableArrayRef<omp::PrivateClauseOp> privateDecls,
1263
- llvm::SmallVector<llvm::Value *> &llvmPrivateVars,
1262
+ MutableArrayRef<mlir::Value> mlirPrivateVars,
1263
+ llvm::SmallVectorImpl<llvm::Value *> &llvmPrivateVars,
1264
1264
const llvm::OpenMPIRBuilder::InsertPointTy &allocaIP) {
1265
1265
// Allocate private vars
1266
1266
llvm::BranchInst *allocaTerminator =
@@ -1285,19 +1285,18 @@ allocatePrivateVars(OP opInst, llvm::IRBuilderBase &builder,
1285
1285
llvm::BasicBlock *privAllocBlock = nullptr ;
1286
1286
if (!privateBlockArgs.empty ())
1287
1287
privAllocBlock = splitBB (builder, true , " omp.private.latealloc" );
1288
- for (unsigned i = 0 ; i < privateBlockArgs.size (); ++i) {
1289
- Region &allocRegion = privateDecls[i].getAllocRegion ();
1288
+ for (auto [privDecl, mlirPrivVar, blockArg] :
1289
+ llvm::zip_equal (privateDecls, mlirPrivateVars, privateBlockArgs)) {
1290
+ Region &allocRegion = privDecl.getAllocRegion ();
1290
1291
1291
1292
// map allocation region block argument
1292
- llvm::Value *nonPrivateVar =
1293
- moduleTranslation.lookupValue (opInst.getPrivateVars ()[i]);
1293
+ llvm::Value *nonPrivateVar = moduleTranslation.lookupValue (mlirPrivVar);
1294
1294
assert (nonPrivateVar);
1295
- moduleTranslation.mapValue (privateDecls[i].getAllocMoldArg (),
1296
- nonPrivateVar);
1295
+ moduleTranslation.mapValue (privDecl.getAllocMoldArg (), nonPrivateVar);
1297
1296
1298
1297
// in-place convert the private allocation region
1299
1298
SmallVector<llvm::Value *, 1 > phis;
1300
- if (privateDecls[i] .getAllocMoldArg ().getUses ().empty ()) {
1299
+ if (privDecl .getAllocMoldArg ().getUses ().empty ()) {
1301
1300
// TODO this should use
1302
1301
// allocaIP.getBlock()->getFirstNonPHIOrDbgOrAlloca() so it goes before
1303
1302
// the code for fetching the thread id. Not doing this for now to avoid
@@ -1313,7 +1312,7 @@ allocatePrivateVars(OP opInst, llvm::IRBuilderBase &builder,
1313
1312
1314
1313
assert (phis.size () == 1 && " expected one allocation to be yielded" );
1315
1314
1316
- moduleTranslation.mapValue (privateBlockArgs[i] , phis[0 ]);
1315
+ moduleTranslation.mapValue (blockArg , phis[0 ]);
1317
1316
llvmPrivateVars.push_back (phis[0 ]);
1318
1317
1319
1318
// clear alloc region block argument mapping in case it needs to be
@@ -1561,11 +1560,14 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
1561
1560
// Collect delayed privatisation declarations
1562
1561
MutableArrayRef<BlockArgument> privateBlockArgs =
1563
1562
cast<omp::BlockArgOpenMPOpInterface>(*taskOp).getPrivateBlockArgs ();
1563
+ SmallVector<mlir::Value> mlirPrivateVars;
1564
1564
SmallVector<llvm::Value *> llvmPrivateVars;
1565
1565
SmallVector<omp::PrivateClauseOp> privateDecls;
1566
+ mlirPrivateVars.reserve (privateBlockArgs.size ());
1566
1567
llvmPrivateVars.reserve (privateBlockArgs.size ());
1567
- privateDecls.reserve (privateBlockArgs.size ());
1568
1568
collectPrivatizationDecls (taskOp, privateDecls);
1569
+ for (mlir::Value privateVar : taskOp.getPrivateVars ())
1570
+ mlirPrivateVars.push_back (privateVar);
1569
1571
1570
1572
auto bodyCB = [&](InsertPointTy allocaIP,
1571
1573
InsertPointTy codegenIP) -> llvm::Error {
@@ -1575,8 +1577,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
1575
1577
moduleTranslation, allocaIP);
1576
1578
1577
1579
llvm::Expected<llvm::BasicBlock *> afterAllocas = allocatePrivateVars (
1578
- taskOp, builder, moduleTranslation, privateBlockArgs, privateDecls,
1579
- llvmPrivateVars, allocaIP);
1580
+ builder, moduleTranslation, privateBlockArgs, privateDecls,
1581
+ mlirPrivateVars, llvmPrivateVars, allocaIP);
1580
1582
if (handleError (afterAllocas, *taskOp).failed ())
1581
1583
return llvm::make_error<PreviouslyReportedError>();
1582
1584
@@ -1879,11 +1881,14 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
1879
1881
// Collect delayed privatization declarations
1880
1882
MutableArrayRef<BlockArgument> privateBlockArgs =
1881
1883
cast<omp::BlockArgOpenMPOpInterface>(*opInst).getPrivateBlockArgs ();
1884
+ SmallVector<mlir::Value> mlirPrivateVars;
1882
1885
SmallVector<llvm::Value *> llvmPrivateVars;
1883
1886
SmallVector<omp::PrivateClauseOp> privateDecls;
1887
+ mlirPrivateVars.reserve (privateBlockArgs.size ());
1884
1888
llvmPrivateVars.reserve (privateBlockArgs.size ());
1885
- privateDecls.reserve (privateBlockArgs.size ());
1886
1889
collectPrivatizationDecls (opInst, privateDecls);
1890
+ for (mlir::Value privateVar : opInst.getPrivateVars ())
1891
+ mlirPrivateVars.push_back (privateVar);
1887
1892
1888
1893
// Collect reduction declarations
1889
1894
SmallVector<omp::DeclareReductionOp> reductionDecls;
@@ -1895,8 +1900,8 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
1895
1900
auto bodyGenCB = [&](InsertPointTy allocaIP,
1896
1901
InsertPointTy codeGenIP) -> llvm::Error {
1897
1902
llvm::Expected<llvm::BasicBlock *> afterAllocas = allocatePrivateVars (
1898
- opInst, builder, moduleTranslation, privateBlockArgs, privateDecls,
1899
- llvmPrivateVars, allocaIP);
1903
+ builder, moduleTranslation, privateBlockArgs, privateDecls,
1904
+ mlirPrivateVars, llvmPrivateVars, allocaIP);
1900
1905
if (handleError (afterAllocas, *opInst).failed ())
1901
1906
return llvm::make_error<PreviouslyReportedError>();
1902
1907
0 commit comments