9 #ifndef MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
10 #define MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
18 #include "llvm/Support/MathExtras.h"
33 namespace QuantizationFlags {
59 Type storageType,
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);
200 detail::AnyQuantizedTypeStorage> {
203 using Base::getChecked;
205 static constexpr StringLiteral
name =
"quant.any";
210 Type expressedType, int64_t storageTypeMin,
211 int64_t storageTypeMax);
217 Type storageType,
Type expressedType, int64_t storageTypeMin,
218 int64_t storageTypeMax);
223 Type storageType,
Type expressedType, int64_t storageTypeMin,
224 int64_t storageTypeMax);
261 detail::UniformQuantizedTypeStorage> {
264 using Base::getChecked;
266 static constexpr StringLiteral
name =
"quant.uniform";
271 Type expressedType,
double scale,
272 int64_t zeroPoint, int64_t storageTypeMin,
273 int64_t storageTypeMax);
279 Type storageType,
Type expressedType,
double scale,
280 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
285 Type storageType,
Type expressedType,
double scale,
286 int64_t zeroPoint, int64_t storageTypeMin,
287 int64_t storageTypeMax);
320 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
321 detail::UniformQuantizedPerAxisTypeStorage> {
324 using Base::getChecked;
326 static constexpr StringLiteral
name =
"quant.uniform_per_axis";
331 get(
unsigned flags,
Type storageType,
Type expressedType,
333 int32_t quantizedDimension, int64_t storageTypeMin,
334 int64_t storageTypeMax);
342 int64_t storageTypeMin, int64_t storageTypeMax);
347 Type storageType,
Type expressedType,
349 int32_t quantizedDimension, int64_t storageTypeMin,
350 int64_t storageTypeMax);
391 detail::CalibratedQuantizedTypeStorage> {
394 using Base::getChecked;
396 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 constexpr StringLiteral name
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Verifies construction invariants and issues errors/warnings.
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 constexpr StringLiteral name
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type expressedType, double min, double max)
Verifies construction invariants and issues errors/warnings.
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.
bool hasStorageTypeBounds() const
Return whether the storage type has explicit min or max boundaries different from the minimum and max...
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.
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.