[llvm] r344588 - [NFC] Move block throw check inside allLoopPathsLeadToBlock
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 16 00:50:14 PDT 2018
Author: mkazantsev
Date: Tue Oct 16 00:50:14 2018
New Revision: 344588
URL: http://llvm.org/viewvc/llvm-project?rev=344588&view=rev
Log:
[NFC] Move block throw check inside allLoopPathsLeadToBlock
Modified:
llvm/trunk/include/llvm/Analysis/MustExecute.h
llvm/trunk/lib/Analysis/MustExecute.cpp
Modified: llvm/trunk/include/llvm/Analysis/MustExecute.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MustExecute.h?rev=344588&r1=344587&r2=344588&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MustExecute.h (original)
+++ llvm/trunk/include/llvm/Analysis/MustExecute.h Tue Oct 16 00:50:14 2018
@@ -65,13 +65,16 @@ public:
/// abnormally.
bool headerMayThrow() const;
+ /// Returns true iff the block \p BB potentially may throw exception. It can
+ /// be false-positive in cases when we want to avoid complex analysis.
+ bool blockMayThrow(const BasicBlock *BB) const;
+
/// Returns true iff any block of the loop for which this info is contains an
/// instruction that may throw or otherwise exit abnormally.
bool anyBlockMayThrow() const;
/// Return true if we must reach the block \p BB under assumption that the
- /// loop \p CurLoop is entered and no instruction throws or otherwise exits
- /// abnormally.
+ /// loop \p CurLoop is entered.
bool allLoopPathsLeadToBlock(const Loop *CurLoop, const BasicBlock *BB,
const DominatorTree *DT) const;
Modified: llvm/trunk/lib/Analysis/MustExecute.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MustExecute.cpp?rev=344588&r1=344587&r2=344588&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MustExecute.cpp (original)
+++ llvm/trunk/lib/Analysis/MustExecute.cpp Tue Oct 16 00:50:14 2018
@@ -26,6 +26,11 @@ bool LoopSafetyInfo::headerMayThrow() co
return HeaderMayThrow;
}
+bool LoopSafetyInfo::blockMayThrow(const BasicBlock *BB) const {
+ (void)BB;
+ return anyBlockMayThrow();
+}
+
bool LoopSafetyInfo::anyBlockMayThrow() const {
return MayThrow;
}
@@ -148,7 +153,10 @@ bool LoopSafetyInfo::allLoopPathsLeadToB
// 3) Exit blocks which are not taken on 1st iteration.
// Memoize blocks we've already checked.
SmallPtrSet<const BasicBlock *, 4> CheckedSuccessors;
- for (auto *Pred : Predecessors)
+ for (auto *Pred : Predecessors) {
+ // Predecessor block may throw, so it has a side exit.
+ if (blockMayThrow(Pred))
+ return false;
for (auto *Succ : successors(Pred))
if (CheckedSuccessors.insert(Succ).second &&
Succ != BB && !Predecessors.count(Succ))
@@ -169,6 +177,7 @@ bool LoopSafetyInfo::allLoopPathsLeadToB
if (CurLoop->contains(Succ) ||
!CanProveNotTakenFirstIteration(Succ, DT, CurLoop))
return false;
+ }
// All predecessors can only lead us to BB.
return true;
@@ -194,11 +203,6 @@ bool LoopSafetyInfo::isGuaranteedToExecu
return !headerMayThrow() ||
Inst.getParent()->getFirstNonPHIOrDbg() == &Inst;
- // Somewhere in this loop there is an instruction which may throw and make us
- // exit the loop.
- if (anyBlockMayThrow())
- return false;
-
// If there is a path from header to exit or latch that doesn't lead to our
// instruction's block, return false.
if (!allLoopPathsLeadToBlock(CurLoop, Inst.getParent(), DT))
More information about the llvm-commits
mailing list