[Mlir-commits] [mlir] [mlir] Call hash_combine_range with ranges (NFC) (PR #136512)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Apr 20 14:56:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-vector

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/136512.diff


8 Files Affected:

- (modified) mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h (+1-1) 
- (modified) mlir/include/mlir/IR/BlockSupport.h (+1-1) 
- (modified) mlir/include/mlir/IR/TypeRange.h (+1-1) 
- (modified) mlir/lib/Dialect/Quant/IR/TypeDetail.h (+7-10) 
- (modified) mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp (+2-3) 
- (modified) mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp (+1-1) 
- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+1-1) 
- (modified) mlir/unittests/IR/OpPropertiesTest.cpp (+3-4) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
index 3f206cd1e545a..8d7f1436fdc60 100644
--- a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
+++ b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
@@ -260,7 +260,7 @@ class FloatPolynomial : public PolynomialBase<FloatPolynomial, FloatMonomial> {
 // Make Polynomials hashable.
 template <class D, typename T>
 inline ::llvm::hash_code hash_value(const PolynomialBase<D, T> &arg) {
-  return ::llvm::hash_combine_range(arg.terms.begin(), arg.terms.end());
+  return ::llvm::hash_combine_range(arg.terms);
 }
 
 template <class D, typename T>
diff --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h
index 292938e46c27e..41434269d555b 100644
--- a/mlir/include/mlir/IR/BlockSupport.h
+++ b/mlir/include/mlir/IR/BlockSupport.h
@@ -185,7 +185,7 @@ struct DenseMapInfo<mlir::SuccessorRange> {
     return mlir::SuccessorRange(pointer, 0);
   }
   static unsigned getHashValue(mlir::SuccessorRange value) {
-    return llvm::hash_combine_range(value.begin(), value.end());
+    return llvm::hash_combine_range(value);
   }
   static bool isEqual(mlir::SuccessorRange lhs, mlir::SuccessorRange rhs) {
     if (rhs.getBase() == getEmptyKey().getBase())
diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h
index 3fb58d78617c0..e098370ae6e58 100644
--- a/mlir/include/mlir/IR/TypeRange.h
+++ b/mlir/include/mlir/IR/TypeRange.h
@@ -72,7 +72,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
 
 /// Make TypeRange hashable.
 inline ::llvm::hash_code hash_value(TypeRange arg) {
-  return ::llvm::hash_combine_range(arg.begin(), arg.end());
+  return ::llvm::hash_combine_range(arg);
 }
 
 /// Emit a type range to the given output stream.
diff --git a/mlir/lib/Dialect/Quant/IR/TypeDetail.h b/mlir/lib/Dialect/Quant/IR/TypeDetail.h
index bb38b1a2a91e2..a43bce354c324 100644
--- a/mlir/lib/Dialect/Quant/IR/TypeDetail.h
+++ b/mlir/lib/Dialect/Quant/IR/TypeDetail.h
@@ -207,11 +207,10 @@ struct UniformQuantizedPerAxisTypeStorage : public QuantizedTypeStorage {
     unsigned getHashValue() const {
       int64_t *scalesCast = llvm::bit_cast<int64_t *>(scales.data());
       ArrayRef<int64_t> scalesBits(scalesCast, scales.size());
-      return llvm::hash_combine(
-          flags, storageType, expressedType,
-          llvm::hash_combine_range(scalesBits.begin(), scalesBits.end()),
-          llvm::hash_combine_range(zeroPoints.begin(), zeroPoints.end()),
-          storageTypeMin, storageTypeMax);
+      return llvm::hash_combine(flags, storageType, expressedType,
+                                llvm::hash_combine_range(scalesBits),
+                                llvm::hash_combine_range(zeroPoints),
+                                storageTypeMin, storageTypeMax);
     }
   };
 
@@ -318,11 +317,9 @@ struct UniformQuantizedSubChannelTypeStorage : public QuantizedTypeStorage {
       }
 
       // Hash the quantized dimensions and block sizes.
-      hash = llvm::hash_combine(
-          hash,
-          llvm::hash_combine_range(quantizedDimensions.begin(),
-                                   quantizedDimensions.end()),
-          llvm::hash_combine_range(blockSizes.begin(), blockSizes.end()));
+      hash = llvm::hash_combine(hash,
+                                llvm::hash_combine_range(quantizedDimensions),
+                                llvm::hash_combine_range(blockSizes));
 
       return hash;
     }
diff --git a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
index 1f708c2ae37ad..71122f8e20512 100644
--- a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
+++ b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
@@ -79,9 +79,8 @@ static llvm::hash_code computeHash(SymbolOpInterface symbolOp) {
         return attr.getName() != SymbolTable::getSymbolAttrName();
       });
 
-  return llvm::hash_combine(
-      symbolOp->getName(),
-      llvm::hash_combine_range(range.begin(), range.end()));
+  return llvm::hash_combine(symbolOp->getName(),
+                            llvm::hash_combine_range(range));
 }
 
 namespace mlir {
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp
index cb348b28c876a..dffb13c3a7923 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp
@@ -238,7 +238,7 @@ struct OffsetMapInfo {
   static SmallVector<int64_t> getTombstoneKey() { return {int64_t(-2)}; }
 
   static unsigned getHashValue(const SmallVector<int64_t> &v) {
-    return static_cast<unsigned>(llvm::hash_combine_range(v.begin(), v.end()));
+    return static_cast<unsigned>(llvm::hash_combine_range(v));
   }
 
   static bool isEqual(const SmallVector<int64_t> &lhs,
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index a56fca25e1697..962207059c8aa 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -106,7 +106,7 @@ struct ValueVectorMapInfo {
   static ValueVector getEmptyKey() { return ValueVector{Value()}; }
   static ValueVector getTombstoneKey() { return ValueVector{Value(), Value()}; }
   static ::llvm::hash_code getHashValue(const ValueVector &val) {
-    return ::llvm::hash_combine_range(val.begin(), val.end());
+    return ::llvm::hash_combine_range(val);
   }
   static bool isEqual(const ValueVector &LHS, const ValueVector &RHS) {
     return LHS == RHS;
diff --git a/mlir/unittests/IR/OpPropertiesTest.cpp b/mlir/unittests/IR/OpPropertiesTest.cpp
index b4a633a2c62e6..4759735d99605 100644
--- a/mlir/unittests/IR/OpPropertiesTest.cpp
+++ b/mlir/unittests/IR/OpPropertiesTest.cpp
@@ -96,10 +96,9 @@ inline llvm::hash_code computeHash(const TestProperties &prop) {
   // We hash `b` which is a float using its underlying array of char:
   unsigned char const *p = reinterpret_cast<unsigned char const *>(&prop.b);
   ArrayRef<unsigned char> bBytes{p, sizeof(prop.b)};
-  return llvm::hash_combine(
-      prop.a, llvm::hash_combine_range(bBytes.begin(), bBytes.end()),
-      llvm::hash_combine_range(prop.array.begin(), prop.array.end()),
-      StringRef(*prop.label));
+  return llvm::hash_combine(prop.a, llvm::hash_combine_range(bBytes),
+                            llvm::hash_combine_range(prop.array),
+                            StringRef(*prop.label));
 }
 
 /// A custom operation for the purpose of showcasing how to use "properties".

``````````

</details>


https://github.com/llvm/llvm-project/pull/136512


More information about the Mlir-commits mailing list