aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-02-08 22:46:50 +0000
committerAnders Carlsson <andersca@mac.com>2009-02-08 22:46:50 +0000
commitcc8992021caf316a282116d509d2a4fb54349341 (patch)
tree7b236f9534348e289293b61c9e208e75d2eb2787 /lib/CodeGen/CodeGenFunction.cpp
parentad9d00e371f4f4e63a540f4e4c501797db2a43de (diff)
Reuse case destinations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 09316e974f..5e005b4c55 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -594,16 +594,28 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
llvm::BranchInst *BI = BranchFixups[i];
llvm::BasicBlock *Dest = BI->getSuccessor(0);
- // Store the jump destination before the branch instruction.
- llvm::ConstantInt *DI =
- 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);
+ llvm::ConstantInt *ID;
+
+ // Check if we already have a destination for this block.
+ if (Dest == SI->getDefaultDest())
+ ID = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+ else {
+ ID = SI->findCaseDest(Dest);
+ if (!ID) {
+ // No code found, get a new unique one by using the number of
+ // switch successors.
+ ID = llvm::ConstantInt::get(llvm::Type::Int32Ty,
+ SI->getNumSuccessors());
+ SI->addCase(ID, Dest);
+ }
+ }
+
+ // Store the jump destination before the branch instruction.
+ new llvm::StoreInst(ID, DestCodePtr, BI);
} else {
// We need to jump through another cleanup block. Create a pad block
// with a branch instruction that jumps to the final destination and
@@ -611,9 +623,16 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
// Create the pad block.
llvm::BasicBlock *CleanupPad = createBasicBlock("cleanup.pad", CurFn);
-
+
+ // Create a unique case ID.
+ llvm::ConstantInt *ID = llvm::ConstantInt::get(llvm::Type::Int32Ty,
+ SI->getNumSuccessors());
+
+ // Store the jump destination before the branch instruction.
+ new llvm::StoreInst(ID, DestCodePtr, BI);
+
// Add it as the destination.
- SI->addCase(DI, CleanupPad);
+ SI->addCase(ID, CleanupPad);
// Create the branch to the final destination.
llvm::BranchInst *BI = llvm::BranchInst::Create(Dest);