@@ -346,56 +346,35 @@ std::pair<BasicBlock *, bool> ControlFlowHub::finalize(
346346 return {FirstGuardBlock, true };
347347}
348348
349- // Check if the given cycle is disjoint with the cycle of the given basic block.
350- // If the basic block does not belong to any cycle, this is regarded as
351- // disjoint, too.
352- static bool disjointWithBlock (CycleInfo *CI, Cycle *C, BasicBlock *BB) {
353- Cycle *CC = CI->getCycle (BB);
354- if (!CC)
355- return true ;
356- Cycle *CommonC = CI->getSmallestCommonCycle (C, CC);
357- return CommonC != C && CommonC != CC;
358- }
359-
360- // Check if the given loop is disjoint with the loop of the given basic block.
361- // If the basic block does not belong to any loop, this is regarded as
362- // disjoint, too.
363- static bool disjointWithBlock (LoopInfo *LI, Loop *L, BasicBlock *BB) {
364- Loop *LL = LI->getLoopFor (BB);
365- return LL && !L->contains (LL) && !LL->contains (L);
366- }
367-
368349template <typename TI, typename T>
369- static void updateCycleLoopInfo (TI *LCI, bool AttachToCallBr,
370- BasicBlock *CallBrBlock,
350+ static bool updateCycleLoopInfo (TI *LCI, BasicBlock *CallBrBlock,
371351 BasicBlock *CallBrTarget, BasicBlock *Succ) {
372352 static_assert (std::is_same_v<TI, CycleInfo> || std::is_same_v<TI, LoopInfo>,
373353 " type must be CycleInfo or LoopInfo" );
374354 if (!LCI)
375- return ;
355+ return false ;
376356
377357 T *LC;
378358 if constexpr (std::is_same_v<TI, CycleInfo>)
379- LC = LCI->getCycle (AttachToCallBr ? CallBrBlock : Succ);
359+ LC = LCI->getSmallestCommonCycle ( CallBrBlock, Succ);
380360 else
381- LC = LCI->getLoopFor (AttachToCallBr ? CallBrBlock : Succ);
361+ LC = LCI->getSmallestCommonLoop ( CallBrBlock, Succ);
382362 if (!LC)
383- return ;
384-
385- // Check if the cycles/loops are disjoint. In that case, we do not add the
386- // intermediate target to any cycle/loop.
387- if (AttachToCallBr && disjointWithBlock (LCI, LC, Succ))
388- return ;
363+ return false ;
389364
390365 if constexpr (std::is_same_v<TI, CycleInfo>)
391366 LCI->addBlockToCycle (CallBrTarget, LC);
392367 else
393368 LC->addBasicBlockToLoop (CallBrTarget, *LCI);
369+
370+ return true ;
394371}
395372
396- BasicBlock *ControlFlowHub::createCallBrTarget (
397- CallBrInst *CallBr, BasicBlock *Succ, unsigned SuccIdx, bool AttachToCallBr,
398- CycleInfo *CI, DomTreeUpdater *DTU, LoopInfo *LI) {
373+ BasicBlock *ControlFlowHub::createCallBrTarget (CallBrInst *CallBr,
374+ BasicBlock *Succ,
375+ unsigned SuccIdx, CycleInfo *CI,
376+ DomTreeUpdater *DTU,
377+ LoopInfo *LI, bool *UpdatedLI) {
399378 BasicBlock *CallBrBlock = CallBr->getParent ();
400379 BasicBlock *CallBrTarget =
401380 BasicBlock::Create (CallBrBlock->getContext (),
@@ -406,10 +385,11 @@ BasicBlock *ControlFlowHub::createCallBrTarget(
406385 CallBr->setSuccessor (SuccIdx, CallBrTarget);
407386 // Jump from the new target block to the original successor.
408387 BranchInst::Create (Succ, CallBrTarget);
409- updateCycleLoopInfo<LoopInfo, Loop>(LI, AttachToCallBr, CallBrBlock,
410- CallBrTarget, Succ);
411- updateCycleLoopInfo<CycleInfo, Cycle>(CI, AttachToCallBr, CallBrBlock,
412- CallBrTarget, Succ);
388+ bool Updated =
389+ updateCycleLoopInfo<LoopInfo, Loop>(LI, CallBrBlock, CallBrTarget, Succ);
390+ if (UpdatedLI)
391+ *UpdatedLI = Updated;
392+ updateCycleLoopInfo<CycleInfo, Cycle>(CI, CallBrBlock, CallBrTarget, Succ);
413393 if (DTU) {
414394 DTU->applyUpdates ({{DominatorTree::Insert, CallBrBlock, CallBrTarget}});
415395 if (DTU->getDomTree ().dominates (CallBrBlock, Succ))
0 commit comments