[llvm] r260605 - Revert "Add a new insert_as() method to DenseMap and use it for ConstantUniqueMap"
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 14:00:36 PST 2016
Author: mehdi_amini
Date: Thu Feb 11 16:00:36 2016
New Revision: 260605
URL: http://llvm.org/viewvc/llvm-project?rev=260605&view=rev
Log:
Revert "Add a new insert_as() method to DenseMap and use it for ConstantUniqueMap"
This reverts commit r260458.
It was backported on an internal branch and broke stage2 build. Since
this can lead to weird random crash I'm reverting upstream as well
while investigating.
From: Mehdi Amini <mehdi.amini at apple.com>
Modified:
llvm/trunk/include/llvm/ADT/DenseMap.h
llvm/trunk/lib/IR/ConstantsContext.h
Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=260605&r1=260604&r2=260605&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Thu Feb 11 16:00:36 2016
@@ -195,26 +195,6 @@ public:
true);
}
- /// Alternate version of insert() which allows a different, and possibly
- /// less expensive, key type.
- /// The DenseMapInfo is responsible for supplying methods
- /// getHashValue(LookupKeyT) and isEqual(LookupKeyT, KeyT) for each key
- /// type used.
- template <typename LookupKeyT>
- std::pair<iterator, bool> insert_as(std::pair<KeyT, ValueT> &&KV,
- const LookupKeyT &Val) {
- BucketT *TheBucket;
- if (LookupBucketFor(Val, TheBucket))
- return std::make_pair(iterator(TheBucket, getBucketsEnd(), *this, true),
- false); // Already in map.
-
- // Otherwise, insert the new element.
- TheBucket = InsertIntoBucket(std::move(KV.first), std::move(KV.second), Val,
- TheBucket);
- return std::make_pair(iterator(TheBucket, getBucketsEnd(), *this, true),
- true);
- }
-
/// insert - Range insertion of pairs.
template<typename InputIt>
void insert(InputIt I, InputIt E) {
@@ -419,7 +399,7 @@ private:
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
BucketT *TheBucket) {
- TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
+ TheBucket = InsertIntoBucketImpl(Key, TheBucket);
TheBucket->getFirst() = Key;
::new (&TheBucket->getSecond()) ValueT(Value);
@@ -428,7 +408,7 @@ private:
BucketT *InsertIntoBucket(const KeyT &Key, ValueT &&Value,
BucketT *TheBucket) {
- TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
+ TheBucket = InsertIntoBucketImpl(Key, TheBucket);
TheBucket->getFirst() = Key;
::new (&TheBucket->getSecond()) ValueT(std::move(Value));
@@ -436,26 +416,14 @@ private:
}
BucketT *InsertIntoBucket(KeyT &&Key, ValueT &&Value, BucketT *TheBucket) {
- TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
-
- TheBucket->getFirst() = std::move(Key);
- ::new (&TheBucket->getSecond()) ValueT(std::move(Value));
- return TheBucket;
- }
-
- template <typename LookupKeyT>
- BucketT *InsertIntoBucket(KeyT &&Key, ValueT &&Value, LookupKeyT &Lookup,
- BucketT *TheBucket) {
- TheBucket = InsertIntoBucketImpl(Key, Lookup, TheBucket);
+ TheBucket = InsertIntoBucketImpl(Key, TheBucket);
TheBucket->getFirst() = std::move(Key);
::new (&TheBucket->getSecond()) ValueT(std::move(Value));
return TheBucket;
}
- template <typename LookupKeyT>
- BucketT *InsertIntoBucketImpl(const KeyT &Key, const LookupKeyT &Lookup,
- BucketT *TheBucket) {
+ BucketT *InsertIntoBucketImpl(const KeyT &Key, BucketT *TheBucket) {
incrementEpoch();
// If the load of the hash table is more than 3/4, or if fewer than 1/8 of
@@ -471,12 +439,12 @@ private:
unsigned NumBuckets = getNumBuckets();
if (LLVM_UNLIKELY(NewNumEntries * 4 >= NumBuckets * 3)) {
this->grow(NumBuckets * 2);
- LookupBucketFor(Lookup, TheBucket);
+ LookupBucketFor(Key, TheBucket);
NumBuckets = getNumBuckets();
} else if (LLVM_UNLIKELY(NumBuckets-(NewNumEntries+getNumTombstones()) <=
NumBuckets/8)) {
this->grow(NumBuckets);
- LookupBucketFor(Lookup, TheBucket);
+ LookupBucketFor(Key, TheBucket);
}
assert(TheBucket);
Modified: llvm/trunk/lib/IR/ConstantsContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantsContext.h?rev=260605&r1=260604&r2=260605&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantsContext.h (original)
+++ llvm/trunk/lib/IR/ConstantsContext.h Thu Feb 11 16:00:36 2016
@@ -546,9 +546,6 @@ public:
typedef typename ConstantInfo<ConstantClass>::TypeClass TypeClass;
typedef std::pair<TypeClass *, ValType> LookupKey;
- /// Key and hash together, so that we compute the hash only once and reuse it.
- typedef std::pair<unsigned, LookupKey> LookupKeyHashed;
-
private:
struct MapInfo {
typedef DenseMapInfo<ConstantClass *> ConstantClassInfo;
@@ -568,9 +565,6 @@ private:
static unsigned getHashValue(const LookupKey &Val) {
return hash_combine(Val.first, Val.second.getHash());
}
- static unsigned getHashValue(const LookupKeyHashed &Val) {
- return Val.first;
- }
static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false;
@@ -578,9 +572,6 @@ private:
return false;
return LHS.second == RHS;
}
- static bool isEqual(const LookupKeyHashed &LHS, const ConstantClass *RHS) {
- return isEqual(LHS.second, RHS);
- }
};
public:
@@ -598,12 +589,13 @@ public:
// Asserts that use_empty().
delete I.first;
}
+
private:
- ConstantClass *create(TypeClass *Ty, ValType V, LookupKeyHashed &HashKey) {
+ ConstantClass *create(TypeClass *Ty, ValType V) {
ConstantClass *Result = V.create(Ty);
assert(Result->getType() == Ty && "Type specified is not correct!");
- Map.insert_as(std::make_pair(Result, '\0'), HashKey);
+ insert(Result);
return Result;
}
@@ -611,15 +603,12 @@ private:
public:
/// Return the specified constant from the map, creating it if necessary.
ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
- LookupKey Key(Ty, V);
- /// Hash once, and reuse it for the lookup and the insertion if needed.
- LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
-
+ LookupKey Lookup(Ty, V);
ConstantClass *Result = nullptr;
- auto I = Map.find_as(Lookup);
+ auto I = find(Lookup);
if (I == Map.end())
- Result = create(Ty, V, Lookup);
+ Result = create(Ty, V);
else
Result = I->first;
assert(Result && "Unexpected nullptr");
@@ -627,6 +616,14 @@ public:
return Result;
}
+ /// Find the constant by lookup key.
+ typename MapTy::iterator find(LookupKey Lookup) {
+ return Map.find_as(Lookup);
+ }
+
+ /// Insert the constant into its proper slot.
+ void insert(ConstantClass *CP) { Map[CP] = '\0'; }
+
/// Remove this constant from the map
void remove(ConstantClass *CP) {
typename MapTy::iterator I = Map.find(CP);
@@ -639,11 +636,8 @@ public:
ConstantClass *CP, Value *From,
Constant *To, unsigned NumUpdated = 0,
unsigned OperandNo = ~0u) {
- LookupKey Key(CP->getType(), ValType(Operands, CP));
- /// Hash once, and reuse it for the lookup and the insertion if needed.
- LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
-
- auto I = Map.find_as(Lookup);
+ LookupKey Lookup(CP->getType(), ValType(Operands, CP));
+ auto I = find(Lookup);
if (I != Map.end())
return I->first;
@@ -659,7 +653,7 @@ public:
if (CP->getOperand(I) == From)
CP->setOperand(I, To);
}
- Map.insert_as(std::make_pair(CP, '\0'), Lookup);
+ insert(CP);
return nullptr;
}
More information about the llvm-commits
mailing list