[Mlir-commits] [mlir] 7961511 - [mlir] MicroOptimize a few hot StorageUniquer code paths

River Riddle llvmlistbot at llvm.org
Wed Nov 10 18:06:43 PST 2021


Author: River Riddle
Date: 2021-11-11T02:02:24Z
New Revision: 7961511ed8eb6717d0943f2b3cdd2474111a6cd6

URL: https://github.com/llvm/llvm-project/commit/7961511ed8eb6717d0943f2b3cdd2474111a6cd6
DIFF: https://github.com/llvm/llvm-project/commit/7961511ed8eb6717d0943f2b3cdd2474111a6cd6.diff

LOG: [mlir] MicroOptimize a few hot StorageUniquer code paths

* Sprinkle `inline` on a few small and hot hashing/uniquing methods
* Use the faster DenseMapInfo hash functions instead of
   llvm::hash_value.

This provides a speed up of a few percent in workloads with lots of
attributes.

Added: 
    

Modified: 
    mlir/include/mlir/IR/Types.h
    mlir/include/mlir/Support/TypeID.h
    mlir/lib/Support/StorageUniquer.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index ade0a77b04e09..7d431366b039b 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -228,7 +228,7 @@ class TypeInterface : public detail::Interface<ConcreteType, Type, Traits, Type,
 
 // Make Type hashable.
 inline ::llvm::hash_code hash_value(Type arg) {
-  return ::llvm::hash_value(arg.impl);
+  return DenseMapInfo<const Type::ImplType *>::getHashValue(arg.impl);
 }
 
 template <typename U> bool Type::isa() const {

diff  --git a/mlir/include/mlir/Support/TypeID.h b/mlir/include/mlir/Support/TypeID.h
index 9bfeb33aad5a3..c966ba4ecd57b 100644
--- a/mlir/include/mlir/Support/TypeID.h
+++ b/mlir/include/mlir/Support/TypeID.h
@@ -60,10 +60,12 @@ class TypeID {
   TypeID() : TypeID(get<void>()) {}
 
   /// Comparison operations.
-  bool operator==(const TypeID &other) const {
+  inline bool operator==(const TypeID &other) const {
     return storage == other.storage;
   }
-  bool operator!=(const TypeID &other) const { return !(*this == other); }
+  inline bool operator!=(const TypeID &other) const {
+    return !(*this == other);
+  }
 
   /// Construct a type info object for the given type T.
   template <typename T>
@@ -94,7 +96,7 @@ class TypeID {
 
 /// Enable hashing TypeID.
 inline ::llvm::hash_code hash_value(TypeID id) {
-  return llvm::hash_value(id.storage);
+  return DenseMapInfo<const TypeID::Storage *>::getHashValue(id.storage);
 }
 
 namespace detail {
@@ -166,11 +168,11 @@ TypeID TypeID::get() {
 
 namespace llvm {
 template <> struct DenseMapInfo<mlir::TypeID> {
-  static mlir::TypeID getEmptyKey() {
+  static inline mlir::TypeID getEmptyKey() {
     void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
     return mlir::TypeID::getFromOpaquePointer(pointer);
   }
-  static mlir::TypeID getTombstoneKey() {
+  static inline mlir::TypeID getTombstoneKey() {
     void *pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
     return mlir::TypeID::getFromOpaquePointer(pointer);
   }

diff  --git a/mlir/lib/Support/StorageUniquer.cpp b/mlir/lib/Support/StorageUniquer.cpp
index e7805150e37d8..06978ce222217 100644
--- a/mlir/lib/Support/StorageUniquer.cpp
+++ b/mlir/lib/Support/StorageUniquer.cpp
@@ -47,23 +47,26 @@ class ParametricStorageUniquer {
   };
 
   /// Storage info for derived TypeStorage objects.
-  struct StorageKeyInfo : DenseMapInfo<HashedStorage> {
-    static HashedStorage getEmptyKey() {
+  struct StorageKeyInfo {
+    static inline HashedStorage getEmptyKey() {
       return HashedStorage(0, DenseMapInfo<BaseStorage *>::getEmptyKey());
     }
-    static HashedStorage getTombstoneKey() {
+    static inline HashedStorage getTombstoneKey() {
       return HashedStorage(0, DenseMapInfo<BaseStorage *>::getTombstoneKey());
     }
 
-    static unsigned getHashValue(const HashedStorage &key) {
+    static inline unsigned getHashValue(const HashedStorage &key) {
+      return key.hashValue;
+    }
+    static inline unsigned getHashValue(const LookupKey &key) {
       return key.hashValue;
     }
-    static unsigned getHashValue(LookupKey key) { return key.hashValue; }
 
-    static bool isEqual(const HashedStorage &lhs, const HashedStorage &rhs) {
+    static inline bool isEqual(const HashedStorage &lhs,
+                               const HashedStorage &rhs) {
       return lhs.storage == rhs.storage;
     }
-    static bool isEqual(const LookupKey &lhs, const HashedStorage &rhs) {
+    static inline bool isEqual(const LookupKey &lhs, const HashedStorage &rhs) {
       if (isEqual(rhs, getEmptyKey()) || isEqual(rhs, getTombstoneKey()))
         return false;
       // Invoke the equality function on the lookup key.


        


More information about the Mlir-commits mailing list