Skip to content

[SIL Optimization][CFGOptUtils.h] Remove completeJointPostDominanceSet utility function #27876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions include/swift/SILOptimizer/Utils/CFGOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,6 @@ bool mergeBasicBlockWithSuccessor(SILBasicBlock *bb, DominanceInfo *domInfo,
/// quadratic.
bool mergeBasicBlocks(SILFunction *f);

/// Given a list of \p UserBlocks and a list of \p DefBlocks, find a set of
/// blocks that together with \p UserBlocks joint-postdominate \p
/// DefBlocks. This is in a sense finding a set of blocks that "complete" \p
/// UserBlocks with respect to \p DefBlocks. As an example, for the following
/// CFG:
///
/// +-----+
/// | Def |
/// +-----+
/// | |
/// v v
/// +-----+ +-----+
/// | | | Use |
/// +-----+ +-----+
///
/// the completion of the joint post-dominance set would be the empty
/// block. This has two main uses:
///
/// 1. This can tell you the places where if you were to sink the Def one would
/// need to insert "compensating code".
///
/// 2. It can be used to prove ownership correctness of @owned values by
/// asserting that the set of UserBlocks has an empty completion, implying they
/// jointly-post dominate the def.
///
/// *NOTE* This completion may not be unique.
void completeJointPostDominanceSet(
ArrayRef<SILBasicBlock *> userBlocks, ArrayRef<SILBasicBlock *> defBlocks,
llvm::SmallVectorImpl<SILBasicBlock *> &completion);

/// Return true if we conservatively find all bb's that are non-failure exit
/// basic blocks and place them in \p bbs. If we find something we don't
/// understand, bail.
Expand Down
83 changes: 0 additions & 83 deletions lib/SILOptimizer/Utils/CFGOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,89 +620,6 @@ SILBasicBlock *swift::splitIfCriticalEdge(SILBasicBlock *from,
llvm_unreachable("Destination block not found");
}

void swift::completeJointPostDominanceSet(
ArrayRef<SILBasicBlock *> userBlocks, ArrayRef<SILBasicBlock *> defBlocks,
llvm::SmallVectorImpl<SILBasicBlock *> &result) {
assert(!userBlocks.empty() && "Must have at least 1 user block");
assert(!defBlocks.empty() && "Must have at least 1 def block");

// If we have only one def block and one user block and they are the same
// block, then just return.
if (defBlocks.size() == 1 && userBlocks.size() == 1
&& userBlocks[0] == defBlocks[0]) {
return;
}

// Some notes on the algorithm:
//
// 1. Our VisitedBlocks set just states that a value has been added to the
// worklist and should not be added to the worklist.
// 2. Our targets of the CFG block are DefBlockSet.
// 3. We find the missing post-domination blocks by finding successors of
// blocks on our walk that we have not visited by the end of the walk. For
// joint post-dominance to be true, no such successors should exist.

// Our set of target blocks where we stop walking.
llvm::SmallPtrSet<SILBasicBlock *, 8> defBlockSet(defBlocks.begin(),
defBlocks.end());

// The set of successor blocks of blocks that we visit. Any blocks still in
// this set at the end of the walk act as a post-dominating closure around our
// userBlock set.
llvm::SmallSetVector<SILBasicBlock *, 16> mustVisitSuccessorBlocks;

// Add our user and def blocks to the visitedBlock set. We never want to find
// these in our worklist.
llvm::SmallPtrSet<SILBasicBlock *, 32> visitedBlocks(userBlocks.begin(),
userBlocks.end());

// Finally setup our worklist by adding our user block predecessors. We only
// add the predecessors to the worklist once.
llvm::SmallVector<SILBasicBlock *, 32> worklist;
for (auto *block : userBlocks) {
llvm::copy_if(block->getPredecessorBlocks(), std::back_inserter(worklist),
[&](SILBasicBlock *predBlock) -> bool {
return visitedBlocks.insert(predBlock).second;
});
}

// Then until we reach a fix point.
while (!worklist.empty()) {
// Grab the next block from the worklist.
auto *block = worklist.pop_back_val();
assert(visitedBlocks.count(block)
&& "All blocks from worklist should be "
"in the visited blocks set.");

// Since we are visiting this block now, we know that this block can not be
// apart of a the post-dominance closure of our UseBlocks.
mustVisitSuccessorBlocks.remove(block);

// Then add each successor block of block that has not been visited yet to
// the mustVisitSuccessorBlocks set.
for (auto *succBlock : block->getSuccessorBlocks()) {
if (!visitedBlocks.count(succBlock)) {
mustVisitSuccessorBlocks.insert(succBlock);
}
}

// If this is a def block, then do not add its predecessors to the
// worklist.
if (defBlockSet.count(block))
continue;

// Otherwise add all unvisited predecessors to the worklist.
llvm::copy_if(block->getPredecessorBlocks(), std::back_inserter(worklist),
[&](SILBasicBlock *block) -> bool {
return visitedBlocks.insert(block).second;
});
}

// Now that we are done, add all remaining must visit blocks to our result
// list. These are the remaining parts of our joint post-dominance closure.
llvm::copy(mustVisitSuccessorBlocks, std::back_inserter(result));
}

bool swift::splitAllCondBrCriticalEdgesWithNonTrivialArgs(
SILFunction &fn, DominanceInfo *domInfo, SILLoopInfo *loopInfo) {
// Find our targets.
Expand Down