-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Add a specialization of DenseMapInfo for SmallVector #140380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] Add a specialization of DenseMapInfo for SmallVector #140380
Conversation
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-adt Author: Jon Chesterfield (JonChesterfield) ChangesEquivalent to the three existing uses I found which were all pointers. Implementing the general pattern so SmallVector<int> etc will work as well. Added to the SmallVector.h header as opposed to DenseMapInfo.h following the StringRef.h and SmallBitVector.h prior art. Noticed while writing an unrelated patch which currently wants a map from small vectors to other things and cleaner to generalise than add another specialisation to said patch. Full diff: https://github.com/llvm/llvm-project/pull/140380.diff 3 Files Affected:
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index bd3e887e36bce..fb9ec9abf111b 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -14,6 +14,7 @@
#ifndef LLVM_ADT_SMALLVECTOR_H
#define LLVM_ADT_SMALLVECTOR_H
+#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <cassert>
@@ -1319,6 +1320,26 @@ extern template class llvm::SmallVectorBase<uint32_t>;
extern template class llvm::SmallVectorBase<uint64_t>;
#endif
+// Provide DenseMapInfo for SmallVector of a type which has info.
+template <typename T, unsigned N> struct DenseMapInfo<llvm::SmallVector<T, N>> {
+ static SmallVector<T, N> getEmptyKey() {
+ return {DenseMapInfo<T>::getEmptyKey()};
+ }
+
+ static SmallVector<T, N> getTombstoneKey() {
+ return {DenseMapInfo<T>::getTombstoneKey()};
+ }
+
+ static unsigned getHashValue(const SmallVector<T, N> &V) {
+ return static_cast<unsigned>(hash_combine_range(V));
+ }
+
+ static bool isEqual(const SmallVector<T, N> &LHS,
+ const SmallVector<T, N> &RHS) {
+ return LHS == RHS;
+ }
+};
+
} // end namespace llvm
namespace std {
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 464e6e3b2ab97..33d6c77f61cfd 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1275,38 +1275,13 @@ struct LSRFixup {
void dump() const;
};
-/// A DenseMapInfo implementation for holding DenseMaps and DenseSets of sorted
-/// SmallVectors of const SCEV*.
-struct UniquifierDenseMapInfo {
- static SmallVector<const SCEV *, 4> getEmptyKey() {
- SmallVector<const SCEV *, 4> V;
- V.push_back(reinterpret_cast<const SCEV *>(-1));
- return V;
- }
-
- static SmallVector<const SCEV *, 4> getTombstoneKey() {
- SmallVector<const SCEV *, 4> V;
- V.push_back(reinterpret_cast<const SCEV *>(-2));
- return V;
- }
-
- static unsigned getHashValue(const SmallVector<const SCEV *, 4> &V) {
- return static_cast<unsigned>(hash_combine_range(V));
- }
-
- static bool isEqual(const SmallVector<const SCEV *, 4> &LHS,
- const SmallVector<const SCEV *, 4> &RHS) {
- return LHS == RHS;
- }
-};
-
/// This class holds the state that LSR keeps for each use in IVUsers, as well
/// as uses invented by LSR itself. It includes information about what kinds of
/// things can be folded into the user, information about the user itself, and
/// information about how the use may be satisfied. TODO: Represent multiple
/// users of the same expression in common?
class LSRUse {
- DenseSet<SmallVector<const SCEV *, 4>, UniquifierDenseMapInfo> Uniquifier;
+ DenseSet<SmallVector<const SCEV *, 4>> Uniquifier;
public:
/// An enum for a kind of use, indicating what types of scaled and immediate
@@ -4754,8 +4729,7 @@ void LSRInstance::FilterOutUndesirableDedicatedRegisters() {
// Collect the best formula for each unique set of shared registers. This
// is reset for each use.
- using BestFormulaeTy =
- DenseMap<SmallVector<const SCEV *, 4>, size_t, UniquifierDenseMapInfo>;
+ using BestFormulaeTy = DenseMap<SmallVector<const SCEV *, 4>, size_t>;
BestFormulaeTy BestFormulae;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanSLP.h b/llvm/lib/Transforms/Vectorize/VPlanSLP.h
index 2b927b93e24cf..157e78363e55f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanSLP.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanSLP.h
@@ -73,30 +73,8 @@ class VPInterleavedAccessInfo {
class VPlanSlp {
enum class OpMode { Failed, Load, Opcode };
- /// A DenseMapInfo implementation for using SmallVector<VPValue *, 4> as
- /// DenseMap keys.
- struct BundleDenseMapInfo {
- static SmallVector<VPValue *, 4> getEmptyKey() {
- return {reinterpret_cast<VPValue *>(-1)};
- }
-
- static SmallVector<VPValue *, 4> getTombstoneKey() {
- return {reinterpret_cast<VPValue *>(-2)};
- }
-
- static unsigned getHashValue(const SmallVector<VPValue *, 4> &V) {
- return static_cast<unsigned>(hash_combine_range(V));
- }
-
- static bool isEqual(const SmallVector<VPValue *, 4> &LHS,
- const SmallVector<VPValue *, 4> &RHS) {
- return LHS == RHS;
- }
- };
-
/// Mapping of values in the original VPlan to a combined VPInstruction.
- DenseMap<SmallVector<VPValue *, 4>, VPInstruction *, BundleDenseMapInfo>
- BundleToCombined;
+ DenseMap<SmallVector<VPValue *, 4>, VPInstruction *> BundleToCombined;
VPInterleavedAccessInfo &IAI;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/15358 Here is the relevant piece of the build log for the reference
|
Thanks for the quick review! An lld test failed after this landed, something about reading debug info. Checking the builder shows that test failing multiple times on previous builds and the revert before this also looks unrelated to lld. I think unrelated to this change. Will keep an eye on the other builders. |
Equivalent to the three existing uses I found which were all pointers. Implementing the general pattern so SmallVector<int> etc will work as well. Added to the SmallVector.h header as opposed to DenseMapInfo.h following the StringRef.h and SmallBitVector.h prior art. Noticed while writing an unrelated patch which currently wants a map from small vectors to other things and cleaner to generalise than add another specialisation to said patch.
Equivalent to the three existing uses I found which were all pointers. Implementing the general pattern so SmallVector etc will work as well.
Added to the SmallVector.h header as opposed to DenseMapInfo.h following the StringRef.h and SmallBitVector.h prior art.
Noticed while writing an unrelated patch which currently wants a map from small vectors to other things and cleaner to generalise than add another specialisation to said patch.