diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-09-24 18:45:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-09-24 18:45:41 +0000 |
commit | 6c2497248bc4f7fd8e5fb0a206d20abbf0e16645 (patch) | |
tree | 661fbbbb59d8cf2b4d1b6d66e5323000df226fe3 /lib/Analysis/CFG.cpp | |
parent | 584425c301325cf6af714eb76554cceabfab626c (diff) |
When building CFGs, no longer reverse the statements in the CFGBlock. Instead
have the iterators and operator[] handle the traversal of statements, as they
are stored in reverse order. Tests show this has no real performance impact, but
it does simply the CFG construction logic and will make it slightly easier to
change the allocation strategy for CFGBlocks (as we have fewer copies).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82702 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CFG.cpp')
-rw-r--r-- | lib/Analysis/CFG.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index d5fde0a819..82472338ae 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -270,14 +270,12 @@ CFGBlock* CFGBuilder::createBlock(bool add_successor) { return B; } -/// FinishBlock - When the last statement has been added to the block, we must -/// reverse the statements because they have been inserted in reverse order. +/// FinishBlock - "Finalize" the block by checking if we have a bad CFG. bool CFGBuilder::FinishBlock(CFGBlock* B) { if (badCFG) return false; assert(B); - B->reverseStmts(); return true; } @@ -699,9 +697,8 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) { // first statement we are processing. In either case, we create a new basic // block. First, we create the blocks for the then...else statements, and // then we create the block containing the if statement. If we were in the - // middle of a block, we stop processing that block and reverse its - // statements. That block is then the implicit successor for the "then" and - // "else" clauses. + // middle of a block, we stop processing that block. That block is then the + // implicit successor for the "then" and "else" clauses. // The block we were proccessing is now finished. Make it the successor // block. @@ -772,14 +769,14 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) { CFGBlock* CFGBuilder::VisitReturnStmt(ReturnStmt* R) { - // If we were in the middle of a block we stop processing that block and - // reverse its statements. + // If we were in the middle of a block we stop processing that block. // // NOTE: If a "return" appears in the middle of a block, this means that the // code afterwards is DEAD (unreachable). We still keep a basic block // for that code; a simple "mark-and-sweep" from the entry block will be // able to report such dead blocks. - if (Block) FinishBlock(Block); + if (Block) + FinishBlock(Block); // Create the new block. Block = createBlock(false); @@ -1183,8 +1180,7 @@ CFGBlock* CFGBuilder::VisitObjCAtThrowStmt(ObjCAtThrowStmt* S) { // FIXME: This isn't complete. We basically treat @throw like a return // statement. - // If we were in the middle of a block we stop processing that block and - // reverse its statements. + // If we were in the middle of a block we stop processing that block. if (Block && !FinishBlock(Block)) return 0; @@ -1200,8 +1196,7 @@ CFGBlock* CFGBuilder::VisitObjCAtThrowStmt(ObjCAtThrowStmt* S) { } CFGBlock* CFGBuilder::VisitCXXThrowExpr(CXXThrowExpr* T) { - // If we were in the middle of a block we stop processing that block and - // reverse its statements. + // If we were in the middle of a block we stop processing that block. if (Block && !FinishBlock(Block)) return 0; @@ -1518,9 +1513,6 @@ CFG* CFG::buildCFG(Stmt* Statement, ASTContext *C) { return Builder.buildCFG(Statement, C); } -/// reverseStmts - Reverses the orders of statements within a CFGBlock. -void CFGBlock::reverseStmts() { std::reverse(Stmts.begin(),Stmts.end()); } - //===----------------------------------------------------------------------===// // CFG: Queries for BlkExprs. //===----------------------------------------------------------------------===// |