Skip to content

Commit bc48004

Browse files
Merge pull request #27876 from ravikandhadai/postdom-utility
[SIL Optimization][CFGOptUtils.h] Remove completeJointPostDominanceSet utility function
2 parents 5c05feb + 9824e87 commit bc48004

File tree

2 files changed

+0
-113
lines changed

2 files changed

+0
-113
lines changed

include/swift/SILOptimizer/Utils/CFGOptUtils.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,6 @@ bool mergeBasicBlockWithSuccessor(SILBasicBlock *bb, DominanceInfo *domInfo,
158158
/// quadratic.
159159
bool mergeBasicBlocks(SILFunction *f);
160160

161-
/// Given a list of \p UserBlocks and a list of \p DefBlocks, find a set of
162-
/// blocks that together with \p UserBlocks joint-postdominate \p
163-
/// DefBlocks. This is in a sense finding a set of blocks that "complete" \p
164-
/// UserBlocks with respect to \p DefBlocks. As an example, for the following
165-
/// CFG:
166-
///
167-
/// +-----+
168-
/// | Def |
169-
/// +-----+
170-
/// | |
171-
/// v v
172-
/// +-----+ +-----+
173-
/// | | | Use |
174-
/// +-----+ +-----+
175-
///
176-
/// the completion of the joint post-dominance set would be the empty
177-
/// block. This has two main uses:
178-
///
179-
/// 1. This can tell you the places where if you were to sink the Def one would
180-
/// need to insert "compensating code".
181-
///
182-
/// 2. It can be used to prove ownership correctness of @owned values by
183-
/// asserting that the set of UserBlocks has an empty completion, implying they
184-
/// jointly-post dominate the def.
185-
///
186-
/// *NOTE* This completion may not be unique.
187-
void completeJointPostDominanceSet(
188-
ArrayRef<SILBasicBlock *> userBlocks, ArrayRef<SILBasicBlock *> defBlocks,
189-
llvm::SmallVectorImpl<SILBasicBlock *> &completion);
190-
191161
/// Return true if we conservatively find all bb's that are non-failure exit
192162
/// basic blocks and place them in \p bbs. If we find something we don't
193163
/// understand, bail.

lib/SILOptimizer/Utils/CFGOptUtils.cpp

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -620,89 +620,6 @@ SILBasicBlock *swift::splitIfCriticalEdge(SILBasicBlock *from,
620620
llvm_unreachable("Destination block not found");
621621
}
622622

623-
void swift::completeJointPostDominanceSet(
624-
ArrayRef<SILBasicBlock *> userBlocks, ArrayRef<SILBasicBlock *> defBlocks,
625-
llvm::SmallVectorImpl<SILBasicBlock *> &result) {
626-
assert(!userBlocks.empty() && "Must have at least 1 user block");
627-
assert(!defBlocks.empty() && "Must have at least 1 def block");
628-
629-
// If we have only one def block and one user block and they are the same
630-
// block, then just return.
631-
if (defBlocks.size() == 1 && userBlocks.size() == 1
632-
&& userBlocks[0] == defBlocks[0]) {
633-
return;
634-
}
635-
636-
// Some notes on the algorithm:
637-
//
638-
// 1. Our VisitedBlocks set just states that a value has been added to the
639-
// worklist and should not be added to the worklist.
640-
// 2. Our targets of the CFG block are DefBlockSet.
641-
// 3. We find the missing post-domination blocks by finding successors of
642-
// blocks on our walk that we have not visited by the end of the walk. For
643-
// joint post-dominance to be true, no such successors should exist.
644-
645-
// Our set of target blocks where we stop walking.
646-
llvm::SmallPtrSet<SILBasicBlock *, 8> defBlockSet(defBlocks.begin(),
647-
defBlocks.end());
648-
649-
// The set of successor blocks of blocks that we visit. Any blocks still in
650-
// this set at the end of the walk act as a post-dominating closure around our
651-
// userBlock set.
652-
llvm::SmallSetVector<SILBasicBlock *, 16> mustVisitSuccessorBlocks;
653-
654-
// Add our user and def blocks to the visitedBlock set. We never want to find
655-
// these in our worklist.
656-
llvm::SmallPtrSet<SILBasicBlock *, 32> visitedBlocks(userBlocks.begin(),
657-
userBlocks.end());
658-
659-
// Finally setup our worklist by adding our user block predecessors. We only
660-
// add the predecessors to the worklist once.
661-
llvm::SmallVector<SILBasicBlock *, 32> worklist;
662-
for (auto *block : userBlocks) {
663-
llvm::copy_if(block->getPredecessorBlocks(), std::back_inserter(worklist),
664-
[&](SILBasicBlock *predBlock) -> bool {
665-
return visitedBlocks.insert(predBlock).second;
666-
});
667-
}
668-
669-
// Then until we reach a fix point.
670-
while (!worklist.empty()) {
671-
// Grab the next block from the worklist.
672-
auto *block = worklist.pop_back_val();
673-
assert(visitedBlocks.count(block)
674-
&& "All blocks from worklist should be "
675-
"in the visited blocks set.");
676-
677-
// Since we are visiting this block now, we know that this block can not be
678-
// apart of a the post-dominance closure of our UseBlocks.
679-
mustVisitSuccessorBlocks.remove(block);
680-
681-
// Then add each successor block of block that has not been visited yet to
682-
// the mustVisitSuccessorBlocks set.
683-
for (auto *succBlock : block->getSuccessorBlocks()) {
684-
if (!visitedBlocks.count(succBlock)) {
685-
mustVisitSuccessorBlocks.insert(succBlock);
686-
}
687-
}
688-
689-
// If this is a def block, then do not add its predecessors to the
690-
// worklist.
691-
if (defBlockSet.count(block))
692-
continue;
693-
694-
// Otherwise add all unvisited predecessors to the worklist.
695-
llvm::copy_if(block->getPredecessorBlocks(), std::back_inserter(worklist),
696-
[&](SILBasicBlock *block) -> bool {
697-
return visitedBlocks.insert(block).second;
698-
});
699-
}
700-
701-
// Now that we are done, add all remaining must visit blocks to our result
702-
// list. These are the remaining parts of our joint post-dominance closure.
703-
llvm::copy(mustVisitSuccessorBlocks, std::back_inserter(result));
704-
}
705-
706623
bool swift::splitAllCondBrCriticalEdgesWithNonTrivialArgs(
707624
SILFunction &fn, DominanceInfo *domInfo, SILLoopInfo *loopInfo) {
708625
// Find our targets.

0 commit comments

Comments
 (0)