diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-10-02 22:46:45 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-10-02 22:46:45 +0000 |
commit | 5c5b3cf5b8af06b8e9347f3f45e8c67438ffd446 (patch) | |
tree | 8d0f5ecadba9f4350cceb812320fd71d8ddb0971 /include | |
parent | 5d37976090df34f003e5128e39593b763be0ca71 (diff) | |
download | external_llvm-5c5b3cf5b8af06b8e9347f3f45e8c67438ffd446.zip external_llvm-5c5b3cf5b8af06b8e9347f3f45e8c67438ffd446.tar.gz external_llvm-5c5b3cf5b8af06b8e9347f3f45e8c67438ffd446.tar.bz2 |
Teach the new SROA to handle cases where an alloca that has already been
scheduled for processing on the worklist eventually gets deleted while
we are processing another alloca, fixing the original test case in
PR13990.
To facilitate this, add a remove_if helper to the SetVector abstraction.
It's not easy to use the standard abstractions for this because of the
specifics of SetVectors types and implementation.
Finally, a nice small test case is included. Thanks to Benjamin for the
fantastic reduced test case here! All I had to do was delete some empty
basic blocks!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165065 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/SetVector.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h index acc4daf..e8d63ed 100644 --- a/include/llvm/ADT/SetVector.h +++ b/include/llvm/ADT/SetVector.h @@ -126,6 +126,32 @@ public: return false; } + /// \brief Remove items from the set vector based on a predicate function. + /// + /// This is intended to be equivalent to the following code, if we could + /// write it: + /// + /// \code + /// V.erase(std::remove_if(V.begin(), V.end(), P), V.end()); + /// \endcode + /// + /// However, SetVector doesn't expose non-const iterators, making any + /// algorithm like remove_if impossible to use. + /// + /// \returns true if any element is removed. + template <typename UnaryPredicate> + bool remove_if(UnaryPredicate P) { + typename vector_type::iterator B = std::remove_if(vector_.begin(), + vector_.end(), P), + E = vector_.end(); + if (B == E) + return false; + for (typename vector_type::iterator I = B; I != E; ++I) + set_.erase(*I); + vector_.erase(B, E); + return true; + } + /// \brief Count the number of elements of a given key in the SetVector. /// \returns 0 if the element is not in the SetVector, 1 if it is. |