[cfe-commits] r94063 - /cfe/trunk/lib/Sema/SemaDecl.cpp
Chris Lattner
clattner at apple.com
Wed Jan 20 22:03:20 PST 2010
On Jan 20, 2010, at 6:55 PM, Mike Stump wrote:
> Author: mrs
> Date: Wed Jan 20 20:55:37 2010
> New Revision: 94063
>
> URL: http://llvm.org/viewvc/llvm-project?rev=94063&view=rev
> Log:
> When checking for unreachable blocks, we can trivially avoid extra
> work, if we know we already marked all blocks as live.
>
Nice, thanks Mike!
-Chris
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=94063&r1=94062&r2=94063&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan 20 20:55:37 2010
> @@ -1310,25 +1310,31 @@
> 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 @@
>
> 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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list