@@ -2295,7 +2295,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createSections(
22952295 return LoopInfo.takeError ();
22962296
22972297 InsertPointOrErrorTy WsloopIP =
2298- applyStaticWorkshareLoop (Loc.DL , *LoopInfo, AllocaIP, !IsNowait);
2298+ applyStaticWorkshareLoop (Loc.DL , *LoopInfo, AllocaIP,
2299+ WorksharingLoopType::ForStaticLoop, !IsNowait);
22992300 if (!WsloopIP)
23002301 return WsloopIP.takeError ();
23012302 InsertPointTy AfterIP = *WsloopIP;
@@ -4145,10 +4146,9 @@ static FunctionCallee getKmpcForStaticInitForType(Type *Ty, Module &M,
41454146 llvm_unreachable (" unknown OpenMP loop iterator bitwidth" );
41464147}
41474148
4148- OpenMPIRBuilder::InsertPointOrErrorTy
4149- OpenMPIRBuilder::applyStaticWorkshareLoop (DebugLoc DL, CanonicalLoopInfo *CLI,
4150- InsertPointTy AllocaIP,
4151- bool NeedsBarrier) {
4149+ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop (
4150+ DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
4151+ WorksharingLoopType LoopType, bool NeedsBarrier) {
41524152 assert (CLI->isValid () && " Requires a valid canonical loop" );
41534153 assert (!isConflictIP (AllocaIP, CLI->getPreheaderIP ()) &&
41544154 " Require dedicated allocate IP" );
@@ -4191,8 +4191,12 @@ OpenMPIRBuilder::applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
41914191
41924192 Value *ThreadNum = getOrCreateThreadID (SrcLoc);
41934193
4194- Constant *SchedulingType = ConstantInt::get (
4195- I32Type, static_cast <int >(OMPScheduleType::UnorderedStatic));
4194+ OMPScheduleType SchedType =
4195+ (LoopType == WorksharingLoopType::DistributeStaticLoop)
4196+ ? OMPScheduleType::OrderedDistribute
4197+ : OMPScheduleType::UnorderedStatic;
4198+ Constant *SchedulingType =
4199+ ConstantInt::get (I32Type, static_cast <int >(SchedType));
41964200
41974201 // Call the "init" function and update the trip count of the loop with the
41984202 // value it produced.
@@ -4452,6 +4456,7 @@ static void createTargetLoopWorkshareCall(
44524456 RealArgs.push_back (TripCount);
44534457 if (LoopType == WorksharingLoopType::DistributeStaticLoop) {
44544458 RealArgs.push_back (ConstantInt::get (TripCountTy, 0 ));
4459+ Builder.restoreIP ({InsertBlock, std::prev (InsertBlock->end ())});
44554460 Builder.CreateCall (RTLFn, RealArgs);
44564461 return ;
44574462 }
@@ -4645,7 +4650,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyWorkshareLoop(
46454650 return applyDynamicWorkshareLoop (DL, CLI, AllocaIP, EffectiveScheduleType,
46464651 NeedsBarrier, ChunkSize);
46474652 // FIXME: Monotonicity ignored?
4648- return applyStaticWorkshareLoop (DL, CLI, AllocaIP, NeedsBarrier);
4653+ return applyStaticWorkshareLoop (DL, CLI, AllocaIP, LoopType, NeedsBarrier);
46494654
46504655 case OMPScheduleType::BaseStaticChunked:
46514656 if (IsOrdered)
@@ -9275,6 +9280,44 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
92759280 return Builder.saveIP ();
92769281}
92779282
9283+ OpenMPIRBuilder::InsertPointOrErrorTy
9284+ OpenMPIRBuilder::createDistribute (const LocationDescription &Loc,
9285+ InsertPointTy OuterAllocaIP,
9286+ BodyGenCallbackTy BodyGenCB) {
9287+ if (!updateToLocation (Loc))
9288+ return InsertPointTy ();
9289+
9290+ BasicBlock *OuterAllocaBB = OuterAllocaIP.getBlock ();
9291+
9292+ if (OuterAllocaBB == Builder.GetInsertBlock ()) {
9293+ BasicBlock *BodyBB =
9294+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.entry" );
9295+ Builder.SetInsertPoint (BodyBB, BodyBB->begin ());
9296+ }
9297+ BasicBlock *ExitBB =
9298+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.exit" );
9299+ BasicBlock *BodyBB =
9300+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.body" );
9301+ BasicBlock *AllocaBB =
9302+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.alloca" );
9303+
9304+ // Generate the body of distribute clause
9305+ InsertPointTy AllocaIP (AllocaBB, AllocaBB->begin ());
9306+ InsertPointTy CodeGenIP (BodyBB, BodyBB->begin ());
9307+ if (Error Err = BodyGenCB (AllocaIP, CodeGenIP))
9308+ return Err;
9309+
9310+ OutlineInfo OI;
9311+ OI.OuterAllocaBB = OuterAllocaIP.getBlock ();
9312+ OI.EntryBB = AllocaBB;
9313+ OI.ExitBB = ExitBB;
9314+
9315+ addOutlineInfo (std::move (OI));
9316+ Builder.SetInsertPoint (ExitBB, ExitBB->begin ());
9317+
9318+ return Builder.saveIP ();
9319+ }
9320+
92789321GlobalVariable *
92799322OpenMPIRBuilder::createOffloadMapnames (SmallVectorImpl<llvm::Constant *> &Names,
92809323 std::string VarName) {
0 commit comments