diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-01-05 07:42:17 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-01-05 07:42:17 +0000 |
commit | 59eb733af1a640f1fc5eba20705f4657906c33e5 (patch) | |
tree | cbe63f9bdd5bd8074ce9fb5dd74dd1581415377f /llvm/lib | |
parent | 2fa8651a8f8df602f62b7074168dfb4b1d1a3fde (diff) | |
download | bcm5719-llvm-59eb733af1a640f1fc5eba20705f4657906c33e5.tar.gz bcm5719-llvm-59eb733af1a640f1fc5eba20705f4657906c33e5.zip |
[SimplifyCFG] Further improve our ability to remove redundant catchpads
In r256814, we managed to remove catchpads which were trivially redudant
because they were the same SSA value. We can do better using the same
algorithm but with a smarter datastructure by hashing the SSA values
within the catchpad and comparing them structurally.
llvm-svn: 256815
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 3845ca2e7e5..3f46c5ebf45 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1324,12 +1324,36 @@ static bool markAliveBlocks(Function &F, } } else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) { // Remove catchpads which cannot be reached. - SmallPtrSet<BasicBlock *, 4> HandlersSeen; + struct CatchPadDenseMapInfo { + static CatchPadInst *getEmptyKey() { + return DenseMapInfo<CatchPadInst *>::getEmptyKey(); + } + static CatchPadInst *getTombstoneKey() { + return DenseMapInfo<CatchPadInst *>::getTombstoneKey(); + } + static unsigned getHashValue(CatchPadInst *CatchPad) { + return static_cast<unsigned>(hash_combine_range( + CatchPad->value_op_begin(), CatchPad->value_op_end())); + } + static bool isEqual(CatchPadInst *LHS, CatchPadInst *RHS) { + if (LHS == getEmptyKey() || LHS == getTombstoneKey() || + RHS == getEmptyKey() || RHS == getTombstoneKey()) + return LHS == RHS; + return LHS->isIdenticalTo(RHS); + } + }; + + // Set of unique CatchPads. + SmallDenseMap<CatchPadInst *, detail::DenseSetEmpty, 4, + CatchPadDenseMapInfo, detail::DenseSetPair<CatchPadInst *>> + HandlerSet; + detail::DenseSetEmpty Empty; for (CatchSwitchInst::handler_iterator I = CatchSwitch->handler_begin(), E = CatchSwitch->handler_end(); I != E; ++I) { BasicBlock *HandlerBB = *I; - if (!HandlersSeen.insert(HandlerBB).second) { + auto *CatchPad = cast<CatchPadInst>(HandlerBB->getFirstNonPHI()); + if (!HandlerSet.insert({CatchPad, Empty}).second) { CatchSwitch->removeHandler(I); --I; --E; |