@@ -250,7 +250,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
250
250
checkAllocate (op, result);
251
251
checkDistSchedule (op, result);
252
252
checkOrder (op, result);
253
- checkPrivate (op, result);
254
253
})
255
254
.Case ([&](omp::OrderedRegionOp op) { checkParLevelSimd (op, result); })
256
255
.Case ([&](omp::SectionsOp op) {
@@ -4188,6 +4187,38 @@ convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
4188
4187
// DistributeOp has only one region associated with it.
4189
4188
builder.restoreIP (codeGenIP);
4190
4189
4190
+ // TODO This is a recurring pattern in almost all ops that need
4191
+ // privatization. Try to abstract it in a shared util/interface.
4192
+ MutableArrayRef<BlockArgument> privateBlockArgs =
4193
+ cast<omp::BlockArgOpenMPOpInterface>(*distributeOp)
4194
+ .getPrivateBlockArgs ();
4195
+ SmallVector<mlir::Value> mlirPrivateVars;
4196
+ SmallVector<llvm::Value *> llvmPrivateVars;
4197
+ SmallVector<omp::PrivateClauseOp> privateDecls;
4198
+ mlirPrivateVars.reserve (privateBlockArgs.size ());
4199
+ llvmPrivateVars.reserve (privateBlockArgs.size ());
4200
+ collectPrivatizationDecls (distributeOp, privateDecls);
4201
+
4202
+ for (mlir::Value privateVar : distributeOp.getPrivateVars ())
4203
+ mlirPrivateVars.push_back (privateVar);
4204
+
4205
+ llvm::Expected<llvm::BasicBlock *> afterAllocas = allocatePrivateVars (
4206
+ builder, moduleTranslation, privateBlockArgs, privateDecls,
4207
+ mlirPrivateVars, llvmPrivateVars, allocaIP);
4208
+ if (handleError (afterAllocas, opInst).failed ())
4209
+ return llvm::make_error<PreviouslyReportedError>();
4210
+
4211
+ if (handleError (initPrivateVars (builder, moduleTranslation,
4212
+ privateBlockArgs, privateDecls,
4213
+ mlirPrivateVars, llvmPrivateVars),
4214
+ opInst)
4215
+ .failed ())
4216
+ return llvm::make_error<PreviouslyReportedError>();
4217
+
4218
+ if (failed (copyFirstPrivateVars (builder, moduleTranslation, mlirPrivateVars,
4219
+ llvmPrivateVars, privateDecls)))
4220
+ return llvm::make_error<PreviouslyReportedError>();
4221
+
4191
4222
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
4192
4223
llvm::OpenMPIRBuilder::LocationDescription ompLoc (builder);
4193
4224
llvm::Expected<llvm::BasicBlock *> regionBlock =
@@ -4200,31 +4231,37 @@ convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
4200
4231
// Skip applying a workshare loop below when translating 'distribute
4201
4232
// parallel do' (it's been already handled by this point while translating
4202
4233
// the nested omp.wsloop).
4203
- if (isa_and_present<omp::WsloopOp>(distributeOp.getNestedWrapper ()))
4204
- return llvm::Error::success ();
4234
+ if (!isa_and_present<omp::WsloopOp>(distributeOp.getNestedWrapper ())) {
4235
+ // TODO: Add support for clauses which are valid for DISTRIBUTE
4236
+ // constructs. Static schedule is the default.
4237
+ auto schedule = omp::ClauseScheduleKind::Static;
4238
+ bool isOrdered = false ;
4239
+ std::optional<omp::ScheduleModifier> scheduleMod;
4240
+ bool isSimd = false ;
4241
+ llvm::omp::WorksharingLoopType workshareLoopType =
4242
+ llvm::omp::WorksharingLoopType::DistributeStaticLoop;
4243
+ bool loopNeedsBarrier = false ;
4244
+ llvm::Value *chunk = nullptr ;
4245
+
4246
+ llvm::CanonicalLoopInfo *loopInfo =
4247
+ findCurrentLoopInfo (moduleTranslation);
4248
+ llvm::OpenMPIRBuilder::InsertPointOrErrorTy wsloopIP =
4249
+ ompBuilder->applyWorkshareLoop (
4250
+ ompLoc.DL , loopInfo, allocaIP, loopNeedsBarrier,
4251
+ convertToScheduleKind (schedule), chunk, isSimd,
4252
+ scheduleMod == omp::ScheduleModifier::monotonic,
4253
+ scheduleMod == omp::ScheduleModifier::nonmonotonic, isOrdered,
4254
+ workshareLoopType);
4255
+
4256
+ if (!wsloopIP)
4257
+ return wsloopIP.takeError ();
4258
+ }
4259
+
4260
+ if (failed (cleanupPrivateVars (builder, moduleTranslation,
4261
+ distributeOp.getLoc (), llvmPrivateVars,
4262
+ privateDecls)))
4263
+ return llvm::make_error<PreviouslyReportedError>();
4205
4264
4206
- // TODO: Add support for clauses which are valid for DISTRIBUTE constructs.
4207
- // Static schedule is the default.
4208
- auto schedule = omp::ClauseScheduleKind::Static;
4209
- bool isOrdered = false ;
4210
- std::optional<omp::ScheduleModifier> scheduleMod;
4211
- bool isSimd = false ;
4212
- llvm::omp::WorksharingLoopType workshareLoopType =
4213
- llvm::omp::WorksharingLoopType::DistributeStaticLoop;
4214
- bool loopNeedsBarrier = false ;
4215
- llvm::Value *chunk = nullptr ;
4216
-
4217
- llvm::CanonicalLoopInfo *loopInfo = findCurrentLoopInfo (moduleTranslation);
4218
- llvm::OpenMPIRBuilder::InsertPointOrErrorTy wsloopIP =
4219
- ompBuilder->applyWorkshareLoop (
4220
- ompLoc.DL , loopInfo, allocaIP, loopNeedsBarrier,
4221
- convertToScheduleKind (schedule), chunk, isSimd,
4222
- scheduleMod == omp::ScheduleModifier::monotonic,
4223
- scheduleMod == omp::ScheduleModifier::nonmonotonic, isOrdered,
4224
- workshareLoopType);
4225
-
4226
- if (!wsloopIP)
4227
- return wsloopIP.takeError ();
4228
4265
return llvm::Error::success ();
4229
4266
};
4230
4267
0 commit comments