summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-01-27 04:20:24 +0000
committerMatthias Braun <matze@braunis.de>2016-01-27 04:20:24 +0000
commit4962bd737feb27bb74d9ac6639a25719ec0f1f79 (patch)
tree59062fbaf01a11b39f792e6bfce1b15e54375154 /llvm
parent2a60c4424cf0c5269a4b21ab28c64db35347fcc4 (diff)
downloadbcm5719-llvm-4962bd737feb27bb74d9ac6639a25719ec0f1f79.tar.gz
bcm5719-llvm-4962bd737feb27bb74d9ac6639a25719ec0f1f79.zip
SmallPtrSet: Inline the part of insert_imp in the small case
Most of the time we only hit the small case, so it is beneficial to pull it out of the insert_imp() implementation. This improves compile time at least for non-LTO builds. Differential Revision: http://reviews.llvm.org/D16619 llvm-svn: 258908
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/SmallPtrSet.h20
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp17
2 files changed, 20 insertions, 17 deletions
diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
index 3d98e8fac43..7e126d4fdd8 100644
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
@@ -102,7 +102,23 @@ protected:
/// insert_imp - This returns true if the pointer was new to the set, false if
/// it was already in the set. This is hidden from the client so that the
/// derived class can check that the right type of pointer is passed in.
- std::pair<const void *const *, bool> insert_imp(const void *Ptr);
+ std::pair<const void *const *, bool> insert_imp(const void *Ptr) {
+ if (isSmall()) {
+ // Check to see if it is already in the set.
+ for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
+ APtr != E; ++APtr)
+ if (*APtr == Ptr)
+ return std::make_pair(APtr, false);
+
+ // Nope, there isn't. If we stay small, just 'pushback' now.
+ if (NumElements < CurArraySize) {
+ SmallArray[NumElements++] = Ptr;
+ return std::make_pair(SmallArray + (NumElements - 1), true);
+ }
+ // Otherwise, hit the big set case, which will call grow.
+ }
+ return insert_imp_big(Ptr);
+ }
/// erase_imp - If the set contains the specified pointer, remove it and
/// return true, otherwise return false. This is hidden from the client so
@@ -127,6 +143,8 @@ protected:
private:
bool isSmall() const { return CurArray == SmallArray; }
+ std::pair<const void *const *, bool> insert_imp_big(const void *Ptr);
+
const void * const *FindBucketFor(const void *Ptr) const;
void shrink_and_clear();
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index 358c8e8abbe..e674fc5948c 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -35,22 +35,7 @@ void SmallPtrSetImplBase::shrink_and_clear() {
}
std::pair<const void *const *, bool>
-SmallPtrSetImplBase::insert_imp(const void *Ptr) {
- if (isSmall()) {
- // Check to see if it is already in the set.
- for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
- APtr != E; ++APtr)
- if (*APtr == Ptr)
- return std::make_pair(APtr, false);
-
- // Nope, there isn't. If we stay small, just 'pushback' now.
- if (NumElements < CurArraySize) {
- SmallArray[NumElements++] = Ptr;
- return std::make_pair(SmallArray + (NumElements - 1), true);
- }
- // Otherwise, hit the big set case, which will call grow.
- }
-
+SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
if (LLVM_UNLIKELY(NumElements * 4 >= CurArraySize * 3)) {
// If more than 3/4 of the array is full, grow.
Grow(CurArraySize < 64 ? 128 : CurArraySize*2);
OpenPOWER on IntegriCloud