@@ -2295,7 +2295,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createSections(
2295
2295
return LoopInfo.takeError ();
2296
2296
2297
2297
InsertPointOrErrorTy WsloopIP =
2298
- applyStaticWorkshareLoop (Loc.DL , *LoopInfo, AllocaIP, !IsNowait);
2298
+ applyStaticWorkshareLoop (Loc.DL , *LoopInfo, AllocaIP,
2299
+ WorksharingLoopType::ForStaticLoop, !IsNowait);
2299
2300
if (!WsloopIP)
2300
2301
return WsloopIP.takeError ();
2301
2302
InsertPointTy AfterIP = *WsloopIP;
@@ -4145,10 +4146,9 @@ static FunctionCallee getKmpcForStaticInitForType(Type *Ty, Module &M,
4145
4146
llvm_unreachable (" unknown OpenMP loop iterator bitwidth" );
4146
4147
}
4147
4148
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) {
4152
4152
assert (CLI->isValid () && " Requires a valid canonical loop" );
4153
4153
assert (!isConflictIP (AllocaIP, CLI->getPreheaderIP ()) &&
4154
4154
" Require dedicated allocate IP" );
@@ -4191,8 +4191,12 @@ OpenMPIRBuilder::applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
4191
4191
4192
4192
Value *ThreadNum = getOrCreateThreadID (SrcLoc);
4193
4193
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));
4196
4200
4197
4201
// Call the "init" function and update the trip count of the loop with the
4198
4202
// value it produced.
@@ -4452,6 +4456,7 @@ static void createTargetLoopWorkshareCall(
4452
4456
RealArgs.push_back (TripCount);
4453
4457
if (LoopType == WorksharingLoopType::DistributeStaticLoop) {
4454
4458
RealArgs.push_back (ConstantInt::get (TripCountTy, 0 ));
4459
+ Builder.restoreIP ({InsertBlock, std::prev (InsertBlock->end ())});
4455
4460
Builder.CreateCall (RTLFn, RealArgs);
4456
4461
return ;
4457
4462
}
@@ -4645,7 +4650,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyWorkshareLoop(
4645
4650
return applyDynamicWorkshareLoop (DL, CLI, AllocaIP, EffectiveScheduleType,
4646
4651
NeedsBarrier, ChunkSize);
4647
4652
// FIXME: Monotonicity ignored?
4648
- return applyStaticWorkshareLoop (DL, CLI, AllocaIP, NeedsBarrier);
4653
+ return applyStaticWorkshareLoop (DL, CLI, AllocaIP, LoopType, NeedsBarrier);
4649
4654
4650
4655
case OMPScheduleType::BaseStaticChunked:
4651
4656
if (IsOrdered)
@@ -9275,6 +9280,44 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
9275
9280
return Builder.saveIP ();
9276
9281
}
9277
9282
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
+
9278
9321
GlobalVariable *
9279
9322
OpenMPIRBuilder::createOffloadMapnames (SmallVectorImpl<llvm::Constant *> &Names,
9280
9323
std::string VarName) {
0 commit comments