[Mlir-commits] [mlir] Extending UniformQuantizedType with interface-based support for new storage types in Quant dialect (PR #152966)

Zoran Zomborat llvmlistbot at llvm.org
Mon Feb 9 01:34:02 PST 2026


================
@@ -558,6 +648,45 @@ def Builtin_Integer : Builtin_Type<"Integer", "integer",
     /// Integer representation maximal bitwidth.
     /// Note: This is aligned with the maximum width of llvm::IntegerType.
     static constexpr unsigned kMaxWidth = (1 << 24) - 1;
+
+    /// QuantStorageTypeInterface method implementations
+    /// Whether the storage type should default to signed when used in quantization.
+    /// Returns true if this is a signed or signless integer type.
+    bool shouldDefaultToSigned() const { return !isUnsigned(); }
+    /// Get the bit width of this integer type.
+    unsigned getStorageWidth() const { return getWidth(); }
+    
+    /// Get default maximum value for this integer type.
+    int64_t getDefaultMaximum(bool isSigned) const {
+      if (isSigned) {
+        return llvm::maxIntN(getWidth());
+      }
+      return llvm::maxUIntN(getWidth());
+    }
+    /// Get default minimum value for this integer type.
+    int64_t getDefaultMinimum(bool isSigned) const {
+      if (isSigned) {
+        return llvm::minIntN(getWidth());
+      }
+      return 0;
+    }
+
+    /// Get the storage type as a string.
+    std::string getStorageTypeName(bool isSigned) const {
+      return (isSigned ? "i" : "u") + std::to_string(getWidth());
+    }
+
+    /// Check if this integer type uses packed representation.
+    bool isPacked() const { return false; }
----------------
ZoranZomborat wrote:

Shouldn't this be based on the integer bitwidth, true for < 8bit, false for >= 8bit ?

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


More information about the Mlir-commits mailing list