[llvm] CycleInfo: Fix splitCriticalEdge (PR #68584)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 04:35:11 PDT 2023
================
@@ -368,17 +368,24 @@ void GenericCycleInfo<ContextT>::splitCriticalEdge(BlockT *Pred, BlockT *Succ,
BlockT *NewBlock) {
// Edge Pred-Succ is replaced by edges Pred-NewBlock and NewBlock-Succ, all
// cycles that had blocks Pred and Succ also get NewBlock.
- CycleT *Cycle = this->getCycle(Pred);
- if (Cycle && Cycle->contains(Succ)) {
- while (Cycle) {
- // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
- // printing cycle NewBlock is at the end of list but it should be in the
- // middle to represent actual traversal of a cycle.
- Cycle->appendBlock(NewBlock);
- BlockMap.try_emplace(NewBlock, Cycle);
- Cycle = Cycle->getParentCycle();
- }
+ CycleT *Cycle = getSmallestCommonCycle(getCycle(Pred), getCycle(Succ));
+ if (!Cycle)
+ return;
+
+ // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
+ // printing cycle NewBlock is at the end of list but it should be in the
+ // middle to represent actual traversal of a cycle.
+ Cycle->appendBlock(NewBlock);
+ BlockMap.try_emplace(NewBlock, Cycle);
+
+ CycleT *ParentCycle = Cycle->getParentCycle();
+ while (ParentCycle) {
+ Cycle = ParentCycle;
+ Cycle->appendBlock(NewBlock);
+ ParentCycle = Cycle->getParentCycle();
}
+
+ BlockMapTopLevel.try_emplace(NewBlock, Cycle);
----------------
ssahasra wrote:
With all these details to handle, I think we should have a separate function like CycleInfo::addBlockToCycle() or something.
https://github.com/llvm/llvm-project/pull/68584
More information about the llvm-commits
mailing list