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 | 02230ab7a6162aa581197557dfa6103123642edf (patch) | |
tree | 6a95d265de88d348edbdb42bc79f18263f6e607c /clang/lib/Sema/SemaDecl.cpp | |
parent | 6bf1c08e99c6607f9d5461259307fb2e7b198901 (diff) | |
download | bcm5719-llvm-02230ab7a6162aa581197557dfa6103123642edf.tar.gz bcm5719-llvm-02230ab7a6162aa581197557dfa6103123642edf.zip |
When checking for unreachable blocks, we can trivially avoid extra
work, if we know we already marked all blocks as live.
llvm-svn: 94063
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7e86120b169..b0ee5ee59cf 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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 |