[PATCH] D52312: [DenseMapInfo] Add implementation for SmallVector of pointers.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 20 09:24:16 PDT 2018


fhahn created this revision.
Herald added a subscriber: dexonsmith.

https://reviews.llvm.org/D52312

Files:
  include/llvm/ADT/DenseMapInfo.h
  lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1089,38 +1089,13 @@
   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.begin(), V.end()));
-  }
-
-  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
@@ -4193,7 +4168,7 @@
   // 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>;
+      DenseMap<SmallVector<const SCEV *, 4>, size_t>;
 
   BestFormulaeTy BestFormulae;
 
Index: include/llvm/ADT/DenseMapInfo.h
===================================================================
--- include/llvm/ADT/DenseMapInfo.h
+++ include/llvm/ADT/DenseMapInfo.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
 #include <cassert>
 #include <cstddef>
@@ -269,6 +270,24 @@
   static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
 };
 
+template <class T, unsigned S> struct DenseMapInfo<SmallVector<T, S>> {
+    static SmallVector<T, S> getEmptyKey() {
+      return {reinterpret_cast<T>(-1)};
+    }
+
+    static SmallVector<T, S> getTombstoneKey() {
+      return {reinterpret_cast<T>(-2)};
+    }
+
+    static unsigned getHashValue(const SmallVector<T, S> &V) {
+      return static_cast<unsigned>(hash_combine_range(V.begin(), V.end()));
+    }
+
+    static bool isEqual(const SmallVector<T, S> &LHS,
+                        const SmallVector<T, S> &RHS) {
+      return LHS == RHS;
+    }
+  };
 } // end namespace llvm
 
 #endif // LLVM_ADT_DENSEMAPINFO_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52312.166313.patch
Type: text/x-patch
Size: 3159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180920/6a7d43b2/attachment.bin>


More information about the llvm-commits mailing list