[cfe-commits] r64053 - in /cfe/trunk/lib/CodeGen: CGStmt.cpp CodeGenFunction.cpp CodeGenFunction.h

Anders Carlsson andersca at mac.com
Sat Feb 7 16:16:35 PST 2009


Author: andersca
Date: Sat Feb  7 18:16:35 2009
New Revision: 64053

URL: http://llvm.org/viewvc/llvm-project?rev=64053&view=rev
Log:
When emitting blocks, keep track of which cleanup scope they have. Minor fixes and cleanup.

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=64053&r1=64052&r2=64053&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Feb  7 18:16:35 2009
@@ -188,6 +188,12 @@
     return;
   }
 
+  // If necessary, associate the block with the cleanup stack size.
+  if (!CleanupEntries.empty()) {
+    BlockScopes[BB] = CleanupEntries.size() - 1;
+    CleanupEntries.back().Blocks.push_back(BB);
+  }
+  
   CurFn->getBasicBlockList().push_back(BB);
   Builder.SetInsertPoint(BB);
 }

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=64053&r1=64052&r2=64053&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Feb  7 18:16:35 2009
@@ -119,7 +119,11 @@
 
   assert(BreakContinueStack.empty() &&
          "mismatched push/pop in break/continue stack!");
-
+  assert(BlockScopes.empty() &&
+         "did not remove all blocks from block scope map!");
+  assert(CleanupEntries.empty() &&
+         "mismatched push/pop in cleanup stack!");
+  
   // Emit function epilog (to return). 
   EmitReturnBlock();
 
@@ -537,8 +541,22 @@
   
   llvm::BasicBlock *CleanupBlock = CE.CleanupBlock;
   
+  std::vector<llvm::BasicBlock *> Blocks;
+  std::swap(Blocks, CE.Blocks);
+
+  std::vector<llvm::BranchInst *> BranchFixups;
+  std::swap(BranchFixups, CE.BranchFixups);
+  
   CleanupEntries.pop_back();
   
   EmitBlock(CleanupBlock);
+  
+  // Remove all blocks from the block scope map.
+  for (size_t i = 0, e = Blocks.size(); i != e; ++i) {
+    assert(BlockScopes.count(Blocks[i]) &&
+           "Did not find block in scope map!");
+    
+    BlockScopes.erase(Blocks[i]);
+  }
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=64053&r1=64052&r2=64053&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Feb  7 18:16:35 2009
@@ -253,11 +253,22 @@
 
     explicit CleanupEntry(llvm::BasicBlock *cb)
       : CleanupBlock(cb) {}
+    
+    ~CleanupEntry() {
+      assert(Blocks.empty() && "Did not empty blocks!");
+      assert(BranchFixups.empty() && "Did not empty branch fixups!");
+    }
+    
   };
   
   /// CleanupEntries - Stack of cleanup entries.
   llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
 
+  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
+
+  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
+  BlockScopeMap BlockScopes;
+  
 public:
   CodeGenFunction(CodeGenModule &cgm);
   





More information about the cfe-commits mailing list