diff options
author | Mike Stump <mrs@apple.com> | 2009-07-21 00:38:52 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-07-21 00:38:52 +0000 |
commit | 23a443bea772b5cce13a193a2aa1824a906bfb25 (patch) | |
tree | 00025024465703c2b4288aa9ce0e3833d90eb0d5 /clang/lib/Analysis/CFG.cpp | |
parent | d571c37b54f6330dc15685021060beb6a92a0184 (diff) | |
download | bcm5719-llvm-23a443bea772b5cce13a193a2aa1824a906bfb25.tar.gz bcm5719-llvm-23a443bea772b5cce13a193a2aa1824a906bfb25.zip |
Wire up CFG improvements for while when the condition is known.
llvm-svn: 76522
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r-- | clang/lib/Analysis/CFG.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 11deec4a232..3dc364292e7 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -701,7 +701,7 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(Decl* D) { } CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) { - // See if this is a known constant first. + // See if this is a known constant. bool KnownTrue = false; bool KnownFalse = false; Expr::EvalResult Result; @@ -1102,6 +1102,18 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) { // "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 (W->getCond()->Evaluate(Result, *Context) + && Result.Val.isInt()) { + if (Result.Val.getInt().getBoolValue()) + KnownTrue = true; + else + KnownFalse = true; + } + CFGBlock* LoopSuccessor = NULL; if (Block) { @@ -1170,13 +1182,21 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) { return 0; } - // Add the loop body entry as a successor to the condition. - ExitConditionBlock->addSuccessor(BodyBlock); + if (KnownFalse) + ExitConditionBlock->addSuccessor(0); + else { + // Add the loop body entry as a successor to the condition. + ExitConditionBlock->addSuccessor(BodyBlock); + } } - // 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 condition block since we loop back // to this block. NULL out Block to force lazy creation of another block. |