[cfe-commits] r76522 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/dead-stores.c
Ted Kremenek
kremenek at apple.com
Tue Jul 21 14:10:22 PDT 2009
Thanks Mike!
On Jul 20, 2009, at 5:38 PM, Mike Stump wrote:
> Author: mrs
> Date: Mon Jul 20 19:38:52 2009
> New Revision: 76522
>
> URL: http://llvm.org/viewvc/llvm-project?rev=76522&view=rev
> Log:
> Wire up CFG improvements for while when the condition is known.
>
> Modified:
> cfe/trunk/lib/Analysis/CFG.cpp
> cfe/trunk/test/Analysis/dead-stores.c
>
> Modified: cfe/trunk/lib/Analysis/CFG.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=76522&r1=76521&r2=76522&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
> +++ cfe/trunk/lib/Analysis/CFG.cpp Mon Jul 20 19:38:52 2009
> @@ -701,7 +701,7 @@
> }
>
> 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 @@
> // "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 @@
> 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.
>
> Modified: cfe/trunk/test/Analysis/dead-stores.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=76522&r1=76521&r2=76522&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/test/Analysis/dead-stores.c (original)
> +++ cfe/trunk/test/Analysis/dead-stores.c Mon Jul 20 19:38:52 2009
> @@ -199,6 +199,8 @@
> int y8 = 4;
> int y9 = 4;
> int y10 = 4;
> + int y11 = 4;
> + int y12 = 4;
>
> ++x; // expected-warning{{never read}}
> ++y1;
> @@ -211,6 +213,8 @@
> ++y8;
> ++y9;
> ++y10;
> + ++y11;
> + ++y12;
>
> switch (j) {
> case 1:
> @@ -265,5 +269,18 @@
> case 9:
> (void)(1 || x);
> (void)y10;
> + break;
> + case 10:
> + while (1) {
> + (void)y11;
> + }
> + (void)x;
> + break;
> + case 11:
> + while (0) {
> + (void)x;
> + }
> + (void)y12;
> + break;
> }
> }
>
>
> _______________________________________________
> 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