diff options
author | Mike Stump <mrs@apple.com> | 2010-01-21 02:55:37 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2010-01-21 02:55:37 +0000 |
commit | 6bde1ae4b7e790691b3a8080a7f1a8fd8a943d3f (patch) | |
tree | 21bb67b5d129bbbec06c733f508aa6042ea88b97 | |
parent | b978a441c7d8bf59e7fede938e1f3b672573b443 (diff) |
When checking for unreachable blocks, we can trivially avoid extra
work, if we know we already marked all blocks as live.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94063 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7e86120b16..b0ee5ee59c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1310,25 +1310,31 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { New->setAccess(Old->getAccess()); } -static void MarkLive(CFGBlock *e, llvm::BitVector &live) { +// MarkLive - Mark all the blocks reachable from e as live. Returns the total +// number of blocks marked live. +static unsigned MarkLive(CFGBlock *e, llvm::BitVector &live) { + unsigned count = 0; std::queue<CFGBlock*> workq; // Prep work queue + live.set(e->getBlockID()); + ++count; workq.push(e); // Solve while (!workq.empty()) { CFGBlock *item = workq.front(); workq.pop(); - live.set(item->getBlockID()); for (CFGBlock::succ_iterator I=item->succ_begin(), E=item->succ_end(); I != E; ++I) { if ((*I) && !live[(*I)->getBlockID()]) { live.set((*I)->getBlockID()); + ++count; workq.push(*I); } } } + return count; } static SourceLocation GetUnreachableLoc(CFGBlock &b) { @@ -1432,7 +1438,9 @@ void Sema::CheckUnreachable(AnalysisContext &AC) { llvm::BitVector live(cfg->getNumBlockIDs()); // Mark all live things first. - MarkLive(&cfg->getEntry(), live); + if (MarkLive(&cfg->getEntry(), live) == cfg->getNumBlockIDs()) + // If there are no dead blocks, we're done. + return; llvm::SmallVector<SourceLocation, 24> lines; // First, give warnings for blocks with no predecessors, as they |