From 9824e876e3e3e68e88c3b2d6c688e468dd0cd3e6 Mon Sep 17 00:00:00 2001 From: Ravi Kandhadai Date: Thu, 24 Oct 2019 19:06:30 -0700 Subject: [PATCH] [SIL Optimization][CFGOptUtils.h] Remove the completeJointPostDominanceSet utility which is completely subsumed by ValueLifetimeAnalysis. --- .../swift/SILOptimizer/Utils/CFGOptUtils.h | 30 ------- lib/SILOptimizer/Utils/CFGOptUtils.cpp | 83 ------------------- 2 files changed, 113 deletions(-) diff --git a/include/swift/SILOptimizer/Utils/CFGOptUtils.h b/include/swift/SILOptimizer/Utils/CFGOptUtils.h index 9c3f8189ff73b..120d19ec9eb9e 100644 --- a/include/swift/SILOptimizer/Utils/CFGOptUtils.h +++ b/include/swift/SILOptimizer/Utils/CFGOptUtils.h @@ -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 userBlocks, ArrayRef defBlocks, - llvm::SmallVectorImpl &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. diff --git a/lib/SILOptimizer/Utils/CFGOptUtils.cpp b/lib/SILOptimizer/Utils/CFGOptUtils.cpp index b88c096c5a229..a2e13e9c3f2f2 100644 --- a/lib/SILOptimizer/Utils/CFGOptUtils.cpp +++ b/lib/SILOptimizer/Utils/CFGOptUtils.cpp @@ -620,89 +620,6 @@ SILBasicBlock *swift::splitIfCriticalEdge(SILBasicBlock *from, llvm_unreachable("Destination block not found"); } -void swift::completeJointPostDominanceSet( - ArrayRef userBlocks, ArrayRef defBlocks, - llvm::SmallVectorImpl &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 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 mustVisitSuccessorBlocks; - - // Add our user and def blocks to the visitedBlock set. We never want to find - // these in our worklist. - llvm::SmallPtrSet 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 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.