Skip to content

Commit 00e71a1

Browse files
authored
Merge pull request #12926 from gottesmm/pr-7d7ad787aa26105e196576774cbf2188fdd8b1b0
2 parents aa7c766 + 1c33bc1 commit 00e71a1

File tree

2 files changed

+43
-0
lines changed
  • include/swift/SILOptimizer/Utils
  • lib/SILOptimizer/Utils

2 files changed

+43
-0
lines changed

include/swift/SILOptimizer/Utils/CFG.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ bool hasCriticalEdges(SILFunction &F, bool OnlyNonCondBr);
125125
bool splitAllCriticalEdges(SILFunction &F, bool OnlyNonCondBr,
126126
DominanceInfo *DT, SILLoopInfo *LI);
127127

128+
/// \brief Split all cond_br critical edges with non-trivial arguments in the
129+
/// function updating the dominator tree and loop information (if they are not
130+
/// set to null).
131+
///
132+
/// A current invariant of Ownership SIL is that cond_br can only have critical
133+
/// edges with non-trivial arguments. This simplifies computation.
134+
bool splitAllCondBrCriticalEdgesWithNonTrivialArgs(SILFunction &F,
135+
DominanceInfo *DT,
136+
SILLoopInfo *LI);
137+
128138
/// \brief Merge a basic block ending in a branch with its successor
129139
/// if possible. If dominance information or loop info is non null update it.
130140
/// Return true if block was merged.

lib/SILOptimizer/Utils/CFG.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,3 +930,36 @@ void swift::completeJointPostDominanceSet(
930930
// list. These are the remaining parts of our joint post-dominance closure.
931931
copy(MustVisitSuccessorBlocks, std::back_inserter(Result));
932932
}
933+
934+
bool swift::splitAllCondBrCriticalEdgesWithNonTrivialArgs(SILFunction &Fn,
935+
DominanceInfo *DT,
936+
SILLoopInfo *LI) {
937+
// Find our targets.
938+
llvm::SmallVector<std::pair<SILBasicBlock *, unsigned>, 8> Targets;
939+
for (auto &Block : Fn) {
940+
auto *CBI = dyn_cast<CondBranchInst>(Block.getTerminator());
941+
if (!CBI)
942+
continue;
943+
944+
// See if our true index is a critical edge. If so, add block to the list
945+
// and continue. If the false edge is also critical, we will handle it at
946+
// the same time.
947+
if (isCriticalEdge(CBI, CondBranchInst::TrueIdx)) {
948+
Targets.emplace_back(&Block, CondBranchInst::TrueIdx);
949+
}
950+
951+
if (!isCriticalEdge(CBI, CondBranchInst::FalseIdx)) {
952+
continue;
953+
}
954+
955+
Targets.emplace_back(&Block, CondBranchInst::FalseIdx);
956+
}
957+
958+
for (auto P : Targets) {
959+
SILBasicBlock *Block = P.first;
960+
unsigned Index = P.second;
961+
auto *Result = splitCriticalEdge(Block->getTerminator(), Index, DT, LI);
962+
(void)Result;
963+
assert(Result);
964+
}
965+
}

0 commit comments

Comments
 (0)