Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 549896a

Browse files
committed
[ADT] Add a much simpler loop to DenseMap::clear when the types are
POD-like and we can just splat the empty key across memory. Sadly we can't optimize the normal loop well enough because we can't turn the conditional store into an unconditional store according to the memory model. This loop actually showed up in a profile of code that was calling clear as a serious source of time. =[ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310189 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 96fa222 commit 549896a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

include/llvm/ADT/DenseMap.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,23 @@ class DenseMapBase : public DebugEpochBase {
107107
}
108108

109109
const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
110-
unsigned NumEntries = getNumEntries();
111-
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
112-
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
113-
if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
114-
P->getSecond().~ValueT();
115-
--NumEntries;
116-
}
110+
if (isPodLike<KeyT>::value && isPodLike<ValueT>::value) {
111+
// Use a simpler loop when these are trivial types.
112+
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P)
117113
P->getFirst() = EmptyKey;
114+
} else {
115+
unsigned NumEntries = getNumEntries();
116+
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
117+
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
118+
if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
119+
P->getSecond().~ValueT();
120+
--NumEntries;
121+
}
122+
P->getFirst() = EmptyKey;
123+
}
118124
}
125+
assert(NumEntries == 0 && "Node count imbalance!");
119126
}
120-
assert(NumEntries == 0 && "Node count imbalance!");
121127
setNumEntries(0);
122128
setNumTombstones(0);
123129
}

0 commit comments

Comments
 (0)