summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-02-23 16:41:36 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-02-23 16:41:36 +0000
commit654a85e2ee08367dfbd391440fe5e69d2b3cde4f (patch)
tree5164d0a6ca3e6a51a8f84ad6e4054c8e4bfd4af5 /llvm/lib/Support
parentf9e3462b69eec534c3af5b1e56c983df109ae57f (diff)
downloadbcm5719-llvm-654a85e2ee08367dfbd391440fe5e69d2b3cde4f.tar.gz
bcm5719-llvm-654a85e2ee08367dfbd391440fe5e69d2b3cde4f.zip
Sync the __builtin_expects for our 3 quadratically probed hash table implementations.
This assumes that a) finding the bucket containing the value is LIKELY b) finding an empty bucket is LIKELY c) growing the table is UNLIKELY I also switched the a) and b) cases for SmallPtrSet as we seem to use the set mostly more for insertion than for checking existence. In a simple benchmark consisting of 2^21 insertions of 2^20 unique pointers into a DenseMap or SmallPtrSet a few percent speedup on average, but nothing statistically significant. llvm-svn: 230232
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp19
-rw-r--r--llvm/lib/Support/StringMap.cpp5
2 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index c87ee7d106e..358c8e8abbe 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -50,11 +50,12 @@ SmallPtrSetImplBase::insert_imp(const void *Ptr) {
}
// Otherwise, hit the big set case, which will call grow.
}
-
- if (NumElements*4 >= CurArraySize*3) {
+
+ if (LLVM_UNLIKELY(NumElements * 4 >= CurArraySize * 3)) {
// If more than 3/4 of the array is full, grow.
Grow(CurArraySize < 64 ? 128 : CurArraySize*2);
- } else if (CurArraySize-(NumElements+NumTombstones) < CurArraySize/8) {
+ } else if (LLVM_UNLIKELY(CurArraySize - (NumElements + NumTombstones) <
+ CurArraySize / 8)) {
// If fewer of 1/8 of the array is empty (meaning that many are filled with
// tombstones), rehash.
Grow(CurArraySize);
@@ -107,16 +108,16 @@ const void * const *SmallPtrSetImplBase::FindBucketFor(const void *Ptr) const {
const void *const *Array = CurArray;
const void *const *Tombstone = nullptr;
while (1) {
- // Found Ptr's bucket?
- if (Array[Bucket] == Ptr)
- return Array+Bucket;
-
// If we found an empty bucket, the pointer doesn't exist in the set.
// Return a tombstone if we've seen one so far, or the empty bucket if
// not.
- if (Array[Bucket] == getEmptyMarker())
+ if (LLVM_LIKELY(Array[Bucket] == getEmptyMarker()))
return Tombstone ? Tombstone : Array+Bucket;
-
+
+ // Found Ptr's bucket?
+ if (LLVM_LIKELY(Array[Bucket] == Ptr))
+ return Array+Bucket;
+
// If this is a tombstone, remember it. If Ptr ends up not in the set, we
// prefer to return it than something that would require more probing.
if (Array[Bucket] == getTombstoneMarker() && !Tombstone)
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index ddb73494ff5..7be946642d9 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -188,9 +188,10 @@ unsigned StringMapImpl::RehashTable(unsigned BucketNo) {
// If the hash table is now more than 3/4 full, or if fewer than 1/8 of
// the buckets are empty (meaning that many are filled with tombstones),
// grow/rehash the table.
- if (NumItems*4 > NumBuckets*3) {
+ if (LLVM_UNLIKELY(NumItems * 4 > NumBuckets * 3)) {
NewSize = NumBuckets*2;
- } else if (NumBuckets-(NumItems+NumTombstones) <= NumBuckets/8) {
+ } else if (LLVM_UNLIKELY(NumBuckets - (NumItems + NumTombstones) <=
+ NumBuckets / 8)) {
NewSize = NumBuckets;
} else {
return BucketNo;
OpenPOWER on IntegriCloud