9 #ifndef MLIR_DIALECT_QUANT_QUANTTYPES_H
10 #define MLIR_DIALECT_QUANT_QUANTTYPES_H
18 #include "llvm/Support/MathExtras.h"
33 namespace QuantizationFlags {
58 unsigned flags,
Type storageType,
59 Type expressedType, int64_t storageTypeMin,
60 int64_t storageTypeMax);
68 unsigned integralWidth) {
70 return llvm::minIntN(integralWidth);
78 unsigned integralWidth) {
80 return llvm::maxIntN(integralWidth);
82 return llvm::maxUIntN(integralWidth);
196 detail::AnyQuantizedTypeStorage> {
199 using Base::getChecked;
201 static constexpr StringLiteral
name =
"quant.any";
206 Type expressedType, int64_t storageTypeMin,
207 int64_t storageTypeMax);
213 Type storageType,
Type expressedType, int64_t storageTypeMin,
214 int64_t storageTypeMax);
218 unsigned flags,
Type storageType,
219 Type expressedType, int64_t storageTypeMin,
220 int64_t storageTypeMax);
257 detail::UniformQuantizedTypeStorage> {
260 using Base::getChecked;
262 static constexpr StringLiteral
name =
"quant.uniform";
267 Type expressedType,
double scale,
268 int64_t zeroPoint, int64_t storageTypeMin,
269 int64_t storageTypeMax);
275 Type storageType,
Type expressedType,
double scale,
276 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
280 unsigned flags,
Type storageType,
281 Type expressedType,
double scale,
282 int64_t zeroPoint, int64_t storageTypeMin,
283 int64_t storageTypeMax);
316 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
317 detail::UniformQuantizedPerAxisTypeStorage> {
320 using Base::getChecked;
322 static constexpr StringLiteral
name =
"quant.uniform_per_axis";
327 get(
unsigned flags,
Type storageType,
Type expressedType,
329 int32_t quantizedDimension, int64_t storageTypeMin,
330 int64_t storageTypeMax);
338 int64_t storageTypeMin, int64_t storageTypeMax);
342 unsigned flags,
Type storageType,
345 int32_t quantizedDimension,
346 int64_t storageTypeMin, int64_t storageTypeMax);
387 detail::CalibratedQuantizedTypeStorage> {
390 using Base::getChecked;
392 static constexpr StringLiteral
name =
"quant.calibrated";
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
This class represents a diagnostic that is inflight and set to be reported.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isInteger() const
Return true if this is an integer type (with the specified width).
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
A quantized type that maps storage to/from expressed types in an unspecified way.
static AnyQuantizedType get(unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Gets an instance of the type with all parameters specified but not checked.
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Verifies construction invariants and issues errors/warnings.
static constexpr StringLiteral name
static AnyQuantizedType getChecked(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Gets an instance of the type with all specified parameters checked.
A quantized type that infers its range from given min/max values.
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type expressedType, double min, double max)
Verifies construction invariants and issues errors/warnings.
static constexpr StringLiteral name
static CalibratedQuantizedType get(Type expressedType, double min, double max)
Gets an instance of the type with all parameters specified but not checked.
static CalibratedQuantizedType getChecked(function_ref< InFlightDiagnostic()> emitError, Type expressedType, double min, double max)
Gets an instance of the type with all specified parameters checked.
Base class for all quantized types known to this dialect.
Type getExpressedType() const
Gets the original expressed type that this quantized type approximates.
static constexpr unsigned MaxStorageBits
The maximum number of bits supported for storage types.
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
static Type castToStorageType(Type quantizedType)
Casts from a type based on a QuantizedType to a corresponding type based on the storageType (returns ...
Type castExpressedToStorageType(Type candidateType)
Casts from a type based on the expressedType to the equivalent type based on storageType by way of th...
static Type castToExpressedType(Type quantizedType)
Casts from a type based on QuantizedType to a corresponding type based on the expressedType (returns ...
bool isSigned() const
Whether the storage type should be interpreted as a signed quantity (true) or an unsigned value (fals...
static QuantizedType getQuantizedElementType(Type primitiveOrContainerType)
Returns the element type as a QuantizedType or nullptr if it is not a quantized type.
unsigned getFlags() const
Gets the flags associated with this type.
int64_t getStorageTypeMax() const
The maximum value that storageType can take.
static int64_t getDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Gets the maximum possible stored by a storageType.
unsigned getStorageTypeIntegralWidth() const
Gets the integral bit width that the underlying storage type can exactly represent.
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Type castFromStorageType(Type candidateType)
Casts from a type based on the storageType to a corresponding type based on this type (returns nullpt...
int64_t getStorageTypeMin() const
The minimum value that storageType can take.
static int64_t getDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Gets the minimum possible stored by a storageType.
Type getStorageType() const
Gets the underlying type used for to store values.
Type castFromExpressedType(Type candidateType)
Casts from a type based on the expressedType to a corresponding type based on this type (returns null...
bool isCompatibleExpressedType(Type candidateExpressedType)
Returns whether the candidateExpressedType is a match for this QuantizedType.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
This class represents an efficient way to signal success or failure.