[Mlir-commits] [mlir] QuantileType bytecode patch (PR #203495)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jun 12 03:26:39 PDT 2026


https://github.com/vsimion26 created https://github.com/llvm/llvm-project/pull/203495

None

>From d6eddaa0991ca07e5e0e8960e1df5adbd1492daf Mon Sep 17 00:00:00 2001
From: vsimion26 <vlad.simion at intel.com>
Date: Fri, 12 Jun 2026 10:00:57 +0100
Subject: [PATCH 1/2] Added ByteCode support for QuantileType

---
 .../Dialect/Quant/IR/QuantDialectBytecode.td  | 17 +++++++++++++-
 .../Dialect/Quant/IR/QuantDialectBytecode.cpp | 23 +++++++++++++++++++
 mlir/test/Dialect/Quant/Bytecode/types.mlir   | 16 +++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td b/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
index 8c74dbef5d94a..21b70e7004f5f 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
@@ -23,6 +23,12 @@ def DoubleAPFloat:
   WithType   <"double">>>>;
 def DoubleAPFloatList : List<DoubleAPFloat>;
 
+def OptionalSignedVarInt:
+  WithParser <"succeeded(readOptionalSignedVarInt($_reader, $_var))",
+  WithBuilder<"$_args",
+  WithPrinter<"writeOptionalSignedVarInt($_writer, $_getter)",
+  WithType   <"std::optional<int64_t>">>>>;
+
 let cType = "AnyQuantizedType" in {
 
 def AnyQuantizedType: DialectType<(type
@@ -97,6 +103,14 @@ def UniformQuantizedSubChannelType
   }];
 }
 
+def QuantileType : DialectType<(type
+  Type:$storageType,
+  Type:$quantileType,
+  Array<DoubleAPFloatList>:$quantiles,
+  OptionalSignedVarInt:$storageMin,
+  OptionalSignedVarInt:$storageMax
+)>;
+
 /// This enum contains marker codes used to indicate which attribute is
 /// currently being decoded, and how it should be decoded. The order of these
 /// codes should generally be unchanged, as any changes will inevitably break
@@ -106,7 +120,8 @@ def QuantDialectTypes : DialectTypes<"Quant"> {
   let elems = [ReservedOrDead, AnyQuantizedType,
                AnyQuantizedTypeWithExpressedType, CalibratedQuantizedType,
                UniformQuantizedType, UniformQuantizedPerAxisType,
-               UniformQuantizedSubChannelType];
+               UniformQuantizedSubChannelType,
+               QuantileQuantizedType, QuantileQuantizedPerAxisType];
 }
 
 #endif // QUANT_BYTECODE
diff --git a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
index 1b3cc5a43f460..870f13d4fb8c2 100644
--- a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
+++ b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
@@ -30,6 +30,29 @@ static LogicalResult readDoubleAPFloat(DialectBytecodeReader &reader,
   return success();
 }
 
+static LogicalResult readOptionalSignedVarInt(DialectBytecodeReader &reader,
+                                              std::optional<int64_t> &val) {
+  bool hasValue;
+  if (failed(reader.readBool(hasValue)))
+    return failure();
+  if (hasValue) {
+    int64_t v;
+    if (failed(reader.readSignedVarInt(v)))
+      return failure();
+    val = v;
+  } else {
+    val = std::nullopt;
+  }
+  return success();
+}
+
+static void writeOptionalSignedVarInt(DialectBytecodeWriter &writer,
+                                      std::optional<int64_t> val) {
+  writer.writeOwnedBool(val.has_value());
+  if (val.has_value())
+    writer.writeSignedVarInt(*val);
+}
+
 #include "mlir/Dialect/Quant/IR/QuantDialectBytecode.cpp.inc"
 
 /// This class implements the bytecode interface for the Quant dialect.
diff --git a/mlir/test/Dialect/Quant/Bytecode/types.mlir b/mlir/test/Dialect/Quant/Bytecode/types.mlir
index 4b03548a5ad11..44de3eb1849ea 100644
--- a/mlir/test/Dialect/Quant/Bytecode/types.mlir
+++ b/mlir/test/Dialect/Quant/Bytecode/types.mlir
@@ -85,3 +85,19 @@ module @parseUniformSubChannel attributes {
   // CHECK: !quant.uniform<i8:f32:{0:1, 1:2}, {{\{}}{2.000000e+00:10, 3.000000e+00:20}, {4.000000e+00:30, 5.000000e+00:40}}>
   bytecode.test = !quant.uniform<i8:f32:{0:1, 1:2}, {{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>
 } {}
+
+//===----------------------------------------------------------------------===//
+// QuantileType
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: parseQuantileNoStorageBounds
+module @parseQuantileNoStorageBounds attributes {
+  // CHECK: !quant.quantile<ui4:f16, {-1.000000e+00,-8.750000e-01,-7.500000e-01,-6.250000e-01,-5.000000e-01,-3.750000e-01,-2.500000e-01,-1.250000e-01,1.250000e-01,2.500000e-01,3.750000e-01,5.000000e-01,6.250000e-01,7.500000e-01,8.750000e-01,1.000000e+00}>
+  bytecode.test = !quant.quantile<ui4:f16, {-1.0,-0.875,-0.75,-0.625,-0.5,-0.375,-0.25,-0.125,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0}>
+} {}
+
+// CHECK-LABEL: parseQuantileWithStorageBounds
+module @parseQuantileWithStorageBounds attributes {
+  // CHECK: !quant.quantile<ui4:f16, {-1.000000e+00,-5.000000e-01,2.500000e-01,7.500000e-01,1.000000e+00}, <-2:2>>
+  bytecode.test = !quant.quantile<ui4:f16, {-1.0,-0.5,0.25,0.75,1.0}, <-2:2>>
+} {}
\ No newline at end of file

>From 7dc07e07e4a38a79bc9ebd6ffd79f65d33239a00 Mon Sep 17 00:00:00 2001
From: vsimion26 <vlad.simion at intel.com>
Date: Fri, 12 Jun 2026 10:41:35 +0100
Subject: [PATCH 2/2] Forward declaration and type declaration added

---
 mlir/include/mlir/Dialect/Quant/IR/Quant.h      |  1 +
 mlir/include/mlir/Dialect/Quant/IR/QuantBase.td | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Quant/IR/Quant.h b/mlir/include/mlir/Dialect/Quant/IR/Quant.h
index 11a969a3ee519..eb207e8054c9b 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/Quant.h
+++ b/mlir/include/mlir/Dialect/Quant/IR/Quant.h
@@ -27,6 +27,7 @@ namespace quant {
 class QuantizedType;
 class UniformQuantizedType;
 class UniformQuantizedPerAxisType;
+class QuantileType;
 
 } // namespace quant
 } // namespace mlir
diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td b/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
index 23bf5cf15e256..b129e4b57e353 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
@@ -402,6 +402,16 @@ class quant_ScalarOrTensorOf<Type etype> :
 def quant_QuantizedType :
     Type<CPred<"::llvm::isa<mlir::quant::QuantizedType>($_self)">, "quantized type">;
 
+// QuantileType
+def quant_QuantileType :
+    DialectType<Quant_Dialect,
+    CPred<"::llvm::isa<::mlir::quant::QuantileType>($_self)">,
+    "QuantileType">;
+
+// Predicate for detecting a scalar or tensor of QuantileType.
+def quant_QuantileValueType :
+    quant_ScalarOrTensorOf<quant_QuantileType>;
+
 def quant_ScalarType :
     Type<Or<[
       AnySignlessInteger.predicate,



More information about the Mlir-commits mailing list