diff options
author | Mike Stump <mrs@apple.com> | 2009-07-21 01:27:50 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-07-21 01:27:50 +0000 |
commit | 8f9893a2beeacd5149bd2d3d4c6e130516915068 (patch) | |
tree | 64850261712384f7e6700c254e966e68adf1c11c /lib/Analysis/CFG.cpp | |
parent | fefb9f7009702befaf715e7a8debc9505c3c8634 (diff) |
Wire up CFG improvements for do { } while () when the condition is known.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CFG.cpp')
-rw-r--r-- | lib/Analysis/CFG.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 01cb6cb7f6..258f67e1d5 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1256,11 +1256,22 @@ CFGBlock* CFGBuilder::VisitObjCAtThrowStmt(ObjCAtThrowStmt* S) { } CFGBlock *CFGBuilder::VisitDoStmt(DoStmt* D) { - // "do...while" is a control-flow statement. Thus we stop processing the - // current block. + // See if this is a known constant. + bool KnownTrue = false; + bool KnownFalse = false; + Expr::EvalResult Result; + if (D->getCond()->Evaluate(Result, *Context) + && Result.Val.isInt()) { + if (Result.Val.getInt().getBoolValue()) + KnownTrue = true; + else + KnownFalse = true; + } CFGBlock* LoopSuccessor = NULL; + // "do...while" is a control-flow statement. Thus we stop processing the + // current block. if (Block) { if (!FinishBlock(Block)) return 0; @@ -1330,13 +1341,21 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt* D) { CFGBlock *LoopBackBlock = createBlock(); LoopBackBlock->setLoopTarget(D); - // Add the loop body entry as a successor to the condition. - ExitConditionBlock->addSuccessor(LoopBackBlock); + if (KnownFalse) + ExitConditionBlock->addSuccessor(0); + else { + // Add the loop body entry as a successor to the condition. + ExitConditionBlock->addSuccessor(LoopBackBlock); + } } - // Link up the condition block with the code that follows the loop. - // (the false branch). - ExitConditionBlock->addSuccessor(LoopSuccessor); + if (KnownTrue) + ExitConditionBlock->addSuccessor(0); + else { + // Link up the condition block with the code that follows the loop. (the + // false branch). + ExitConditionBlock->addSuccessor(LoopSuccessor); + } // There can be no more statements in the body block(s) since we loop back to // the body. NULL out Block to force lazy creation of another block. |