[cfe-commits] r64069 - in /cfe/trunk/lib/CodeGen: CodeGenFunction.cpp CodeGenFunction.h
Anders Carlsson
andersca at mac.com
Sat Feb 7 19:55:35 PST 2009
Author: andersca
Date: Sat Feb 7 21:55:35 2009
New Revision: 64069
URL: http://llvm.org/viewvc/llvm-project?rev=64069&view=rev
Log:
Split some functions up
Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=64069&r1=64068&r2=64069&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Feb 7 21:55:35 2009
@@ -531,34 +531,22 @@
EmitCleanupBlock();
}
-void CodeGenFunction::EmitCleanupBlock()
+void CodeGenFunction::FixupBranches(llvm::BasicBlock *CleanupBlock,
+ const BlockVector& Blocks,
+ BranchFixupsVector& BranchFixups)
{
- CleanupEntry &CE = CleanupEntries.back();
-
- 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);
-
if (!CleanupEntries.empty()) {
// Check if any branch fixups pointed to the scope we just popped. If so,
// we can remove them.
for (size_t i = 0, e = BranchFixups.size(); i != e; ++i) {
llvm::BasicBlock *Dest = BranchFixups[i]->getSuccessor(0);
BlockScopeMap::iterator I = BlockScopes.find(Dest);
-
+
if (I == BlockScopes.end())
continue;
assert(I->second <= CleanupEntries.size() && "Invalid branch fixup!");
-
+
if (I->second == CleanupEntries.size()) {
// We don't need to do this branch fixup.
BranchFixups[i] = BranchFixups.back();
@@ -569,7 +557,7 @@
}
}
}
-
+
if (!BranchFixups.empty()) {
llvm::BasicBlock *CleanupEnd = createBasicBlock("cleanup.end");
@@ -588,12 +576,12 @@
// Store the jump destination before the branch instruction.
llvm::ConstantInt *DI =
- llvm::ConstantInt::get(llvm::Type::Int32Ty, i + 1);
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, i + 1);
new llvm::StoreInst(DI, DestCodePtr, BI);
// Fixup the branch instruction to point to the cleanup block.
BI->setSuccessor(0, CleanupBlock);
-
+
if (CleanupEntries.empty()) {
SI->addCase(DI, Dest);
} else {
@@ -603,7 +591,7 @@
// Create the pad block.
llvm::BasicBlock *CleanupPad = createBasicBlock("cleanup.pad", CurFn);
-
+
// Add it as the destination.
SI->addCase(DI, CleanupPad);
@@ -616,7 +604,7 @@
}
}
}
-
+
// Remove all blocks from the block scope map.
for (size_t i = 0, e = Blocks.size(); i != e; ++i) {
assert(BlockScopes.count(Blocks[i]) &&
@@ -626,6 +614,34 @@
}
}
+llvm::BasicBlock *
+CodeGenFunction::PopCleanupBlock(BlockVector& Blocks,
+ BranchFixupsVector& BranchFixups)
+{
+ CleanupEntry &CE = CleanupEntries.back();
+
+ llvm::BasicBlock *CleanupBlock = CE.CleanupBlock;
+
+ std::swap(Blocks, CE.Blocks);
+ std::swap(BranchFixups, CE.BranchFixups);
+
+ CleanupEntries.pop_back();
+
+ return CleanupBlock;
+}
+
+void CodeGenFunction::EmitCleanupBlock()
+{
+ BlockVector Blocks;
+ BranchFixupsVector BranchFixups;
+
+ llvm::BasicBlock *CleanupBlock = PopCleanupBlock(Blocks, BranchFixups);
+
+ EmitBlock(CleanupBlock);
+
+ FixupBranches(CleanupBlock, Blocks, BranchFixups);
+}
+
void CodeGenFunction::AddBranchFixup(llvm::BranchInst *BI)
{
assert(!CleanupEntries.empty() &&
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=64069&r1=64068&r2=64069&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Feb 7 21:55:35 2009
@@ -249,16 +249,19 @@
/// label.
void EmitStackUpdate(const LabelStmt &S);
+ typedef std::vector<llvm::BasicBlock *> BlockVector;
+ typedef std::vector<llvm::BranchInst *> BranchFixupsVector;
+
struct CleanupEntry {
/// CleanupBlock - The block of code that does the actual cleanup.
llvm::BasicBlock *CleanupBlock;
/// Blocks - Basic blocks that were emitted in the current cleanup scope.
- std::vector<llvm::BasicBlock *> Blocks;
+ BlockVector Blocks;
/// BranchFixups - Branch instructions to basic blocks that haven't been
/// inserted into the current function yet.
- std::vector<llvm::BranchInst*> BranchFixups;
+ BranchFixupsVector BranchFixups;
explicit CleanupEntry(llvm::BasicBlock *cb)
: CleanupBlock(cb) {}
@@ -267,7 +270,6 @@
assert(Blocks.empty() && "Did not empty blocks!");
assert(BranchFixups.empty() && "Did not empty branch fixups!");
}
-
};
/// CleanupEntries - Stack of cleanup entries.
@@ -789,6 +791,13 @@
/// EmitCleanupBlock - emits a single cleanup block.
void EmitCleanupBlock();
+ llvm::BasicBlock *PopCleanupBlock(BlockVector& Blocks,
+ BranchFixupsVector& BranchFixups);
+
+ void FixupBranches(llvm::BasicBlock *CleanupBlock,
+ const BlockVector& Blocks,
+ BranchFixupsVector& BranchFixups);
+
/// AddBranchFixup - adds a branch instruction to the list of fixups for the
/// current cleanup scope.
void AddBranchFixup(llvm::BranchInst *BI);
More information about the cfe-commits
mailing list