@@ -250,7 +250,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
250250 checkAllocate (op, result);
251251 checkDistSchedule (op, result);
252252 checkOrder (op, result);
253- checkPrivate (op, result);
254253 })
255254 .Case ([&](omp::OrderedRegionOp op) { checkParLevelSimd (op, result); })
256255 .Case ([&](omp::SectionsOp op) {
@@ -4188,6 +4187,38 @@ convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
41884187 // DistributeOp has only one region associated with it.
41894188 builder.restoreIP (codeGenIP);
41904189
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+
41914222 llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
41924223 llvm::OpenMPIRBuilder::LocationDescription ompLoc (builder);
41934224 llvm::Expected<llvm::BasicBlock *> regionBlock =
@@ -4200,31 +4231,37 @@ convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
42004231 // Skip applying a workshare loop below when translating 'distribute
42014232 // parallel do' (it's been already handled by this point while translating
42024233 // 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>();
42054264
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 ();
42284265 return llvm::Error::success ();
42294266 };
42304267
0 commit comments