[objc-arc] Track if we encountered an additive overflow while computing {TopDown,BottomUp}PathCounts and do nothing if it occured.

rdar://14590914

llvm-svn: 187941
This commit is contained in:
Michael Gottesman 2013-08-07 23:56:41 +00:00
parent 630805fc43
commit a8c38e944e
2 changed files with 1095 additions and 6 deletions

View File

@ -648,6 +648,8 @@ PtrState::Merge(const PtrState &Other, bool TopDown) {
namespace { namespace {
/// \brief Per-BasicBlock state. /// \brief Per-BasicBlock state.
class BBState { class BBState {
static const unsigned OverflowOccurredValue;
/// The number of unique control paths from the entry which can reach this /// The number of unique control paths from the entry which can reach this
/// block. /// block.
unsigned TopDownPathCount; unsigned TopDownPathCount;
@ -674,7 +676,7 @@ namespace {
SmallVector<BasicBlock *, 2> Succs; SmallVector<BasicBlock *, 2> Succs;
public: public:
BBState() : TopDownPathCount(0), BottomUpPathCount(0) {} BBState() : TopDownPathCount(0), BottomUpPathCount(0) { }
typedef MapTy::iterator ptr_iterator; typedef MapTy::iterator ptr_iterator;
typedef MapTy::const_iterator ptr_const_iterator; typedef MapTy::const_iterator ptr_const_iterator;
@ -745,8 +747,9 @@ namespace {
/// Returns true if overflow occured. Returns false if overflow did not /// Returns true if overflow occured. Returns false if overflow did not
/// occur. /// occur.
bool GetAllPathCountWithOverflow(unsigned &PathCount) const { bool GetAllPathCountWithOverflow(unsigned &PathCount) const {
assert(TopDownPathCount != 0); if (TopDownPathCount == OverflowOccurredValue ||
assert(BottomUpPathCount != 0); BottomUpPathCount == OverflowOccurredValue)
return false;
unsigned long long Product = unsigned long long Product =
(unsigned long long)TopDownPathCount*BottomUpPathCount; (unsigned long long)TopDownPathCount*BottomUpPathCount;
PathCount = Product; PathCount = Product;
@ -766,6 +769,8 @@ namespace {
bool isExit() const { return Succs.empty(); } bool isExit() const { return Succs.empty(); }
}; };
const unsigned BBState::OverflowOccurredValue = -1;
} }
void BBState::InitFromPred(const BBState &Other) { void BBState::InitFromPred(const BBState &Other) {
@ -781,13 +786,25 @@ void BBState::InitFromSucc(const BBState &Other) {
/// The top-down traversal uses this to merge information about predecessors to /// The top-down traversal uses this to merge information about predecessors to
/// form the initial state for a new block. /// form the initial state for a new block.
void BBState::MergePred(const BBState &Other) { void BBState::MergePred(const BBState &Other) {
if (TopDownPathCount == OverflowOccurredValue)
return;
// Other.TopDownPathCount can be 0, in which case it is either dead or a // Other.TopDownPathCount can be 0, in which case it is either dead or a
// loop backedge. Loop backedges are special. // loop backedge. Loop backedges are special.
TopDownPathCount += Other.TopDownPathCount; TopDownPathCount += Other.TopDownPathCount;
// In order to be consistent, we clear the top down pointers when by adding
// TopDownPathCount becomes OverflowOccurredValue even though "true" overflow
// has not occured.
if (TopDownPathCount == OverflowOccurredValue) {
clearTopDownPointers();
return;
}
// Check for overflow. If we have overflow, fall back to conservative // Check for overflow. If we have overflow, fall back to conservative
// behavior. // behavior.
if (TopDownPathCount < Other.TopDownPathCount) { if (TopDownPathCount < Other.TopDownPathCount) {
TopDownPathCount = OverflowOccurredValue;
clearTopDownPointers(); clearTopDownPointers();
return; return;
} }
@ -813,13 +830,25 @@ void BBState::MergePred(const BBState &Other) {
/// The bottom-up traversal uses this to merge information about successors to /// The bottom-up traversal uses this to merge information about successors to
/// form the initial state for a new block. /// form the initial state for a new block.
void BBState::MergeSucc(const BBState &Other) { void BBState::MergeSucc(const BBState &Other) {
if (BottomUpPathCount == OverflowOccurredValue)
return;
// Other.BottomUpPathCount can be 0, in which case it is either dead or a // Other.BottomUpPathCount can be 0, in which case it is either dead or a
// loop backedge. Loop backedges are special. // loop backedge. Loop backedges are special.
BottomUpPathCount += Other.BottomUpPathCount; BottomUpPathCount += Other.BottomUpPathCount;
// In order to be consistent, we clear the top down pointers when by adding
// BottomUpPathCount becomes OverflowOccurredValue even though "true" overflow
// has not occured.
if (BottomUpPathCount == OverflowOccurredValue) {
clearBottomUpPointers();
return;
}
// Check for overflow. If we have overflow, fall back to conservative // Check for overflow. If we have overflow, fall back to conservative
// behavior. // behavior.
if (BottomUpPathCount < Other.BottomUpPathCount) { if (BottomUpPathCount < Other.BottomUpPathCount) {
BottomUpPathCount = OverflowOccurredValue;
clearBottomUpPointers(); clearBottomUpPointers();
return; return;
} }

File diff suppressed because it is too large Load Diff