summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-01-05 06:27:50 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-01-05 06:27:50 +0000
commit2fa8651a8f8df602f62b7074168dfb4b1d1a3fde (patch)
tree35b992eb273f796dfe9352ff6e49ce80f617534a /llvm/lib/Transforms/Utils/Local.cpp
parent905042774df1c784ff898154553b5cca40c46822 (diff)
downloadbcm5719-llvm-2fa8651a8f8df602f62b7074168dfb4b1d1a3fde.tar.gz
bcm5719-llvm-2fa8651a8f8df602f62b7074168dfb4b1d1a3fde.zip
[SimplifyCFG] Remove redundant catchpads
Remove duplicate catchpad handlers from a catchswitch. llvm-svn: 256814
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index e75163f323d..3845ca2e7e5 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1305,8 +1305,9 @@ static bool markAliveBlocks(Function &F,
}
}
- // Turn invokes that call 'nounwind' functions into ordinary calls.
- if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
+ TerminatorInst *Terminator = BB->getTerminator();
+ if (auto *II = dyn_cast<InvokeInst>(Terminator)) {
+ // Turn invokes that call 'nounwind' functions into ordinary calls.
Value *Callee = II->getCalledValue();
if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) {
changeToUnreachable(II, true);
@@ -1321,6 +1322,20 @@ static bool markAliveBlocks(Function &F,
changeToCall(II);
Changed = true;
}
+ } else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
+ // Remove catchpads which cannot be reached.
+ SmallPtrSet<BasicBlock *, 4> HandlersSeen;
+ for (CatchSwitchInst::handler_iterator I = CatchSwitch->handler_begin(),
+ E = CatchSwitch->handler_end();
+ I != E; ++I) {
+ BasicBlock *HandlerBB = *I;
+ if (!HandlersSeen.insert(HandlerBB).second) {
+ CatchSwitch->removeHandler(I);
+ --I;
+ --E;
+ Changed = true;
+ }
+ }
}
Changed |= ConstantFoldTerminator(BB, true);
OpenPOWER on IntegriCloud