@@ -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)
@@ -9245,6 +9250,44 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
9245
9250
return Builder.saveIP ();
9246
9251
}
9247
9252
9253
+ OpenMPIRBuilder::InsertPointOrErrorTy
9254
+ OpenMPIRBuilder::createDistribute (const LocationDescription &Loc,
9255
+ InsertPointTy OuterAllocaIP,
9256
+ BodyGenCallbackTy BodyGenCB) {
9257
+ if (!updateToLocation (Loc))
9258
+ return InsertPointTy ();
9259
+
9260
+ BasicBlock *OuterAllocaBB = OuterAllocaIP.getBlock ();
9261
+
9262
+ if (OuterAllocaBB == Builder.GetInsertBlock ()) {
9263
+ BasicBlock *BodyBB =
9264
+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.entry" );
9265
+ Builder.SetInsertPoint (BodyBB, BodyBB->begin ());
9266
+ }
9267
+ BasicBlock *ExitBB =
9268
+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.exit" );
9269
+ BasicBlock *BodyBB =
9270
+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.body" );
9271
+ BasicBlock *AllocaBB =
9272
+ splitBB (Builder, /* CreateBranch=*/ true , " distribute.alloca" );
9273
+
9274
+ // Generate the body of distribute clause
9275
+ InsertPointTy AllocaIP (AllocaBB, AllocaBB->begin ());
9276
+ InsertPointTy CodeGenIP (BodyBB, BodyBB->begin ());
9277
+ if (Error Err = BodyGenCB (AllocaIP, CodeGenIP))
9278
+ return Err;
9279
+
9280
+ OutlineInfo OI;
9281
+ OI.OuterAllocaBB = OuterAllocaIP.getBlock ();
9282
+ OI.EntryBB = AllocaBB;
9283
+ OI.ExitBB = ExitBB;
9284
+
9285
+ addOutlineInfo (std::move (OI));
9286
+ Builder.SetInsertPoint (ExitBB, ExitBB->begin ());
9287
+
9288
+ return Builder.saveIP ();
9289
+ }
9290
+
9248
9291
GlobalVariable *
9249
9292
OpenMPIRBuilder::createOffloadMapnames (SmallVectorImpl<llvm::Constant *> &Names,
9250
9293
std::string VarName) {
0 commit comments