1//===- QuantOpsBase.td - Quantization dialect base ---------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Predicates for types in the Quantization dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef DIALECT_QUANT_QUANT_OPS_BASE_
14#define DIALECT_QUANT_QUANT_OPS_BASE_
15
16include "mlir/IR/OpBase.td"
17
18def Quantization_Dialect : Dialect {
19  let name = "quant";
20  let cppNamespace = "::mlir::quant";
21}
22
23//===----------------------------------------------------------------------===//
24// Quantization type definitions
25//===----------------------------------------------------------------------===//
26
27class quant_TypedPrimitiveOrContainer<Type etype> :
28    Type<Or<[etype.predicate,
29                TensorOf<[etype]>.predicate,
30                VectorOf<[etype]>.predicate]>,
31         "primitive/tensor/vector of " # etype.description>;
32
33// An implementation of QuantizedType.
34def quant_QuantizedType :
35    Type<CPred<"$_self.isa<mlir::quant::QuantizedType>()">, "QuantizedType">;
36
37// A primitive type that can represent a real value. This is either a
38// floating point value or a quantized type.
39def quant_RealPrimitiveType :
40    Type<Or<[AnyFloat.predicate, quant_QuantizedType.predicate]>,
41    "real valued primitive (float or quantized type)">;
42
43// A primitive type that can represent a storage value. This is either an
44// integer or quantized type.
45def quant_StoragePrimitiveType :
46    Type<Or<[AnySignlessInteger.predicate, quant_QuantizedType.predicate]>,
47    "quantized storage primitive (integer or quantized type)">;
48
49// A primitive or container of RealPrimitiveType.
50def quant_RealValueType :
51    quant_TypedPrimitiveOrContainer<quant_RealPrimitiveType>;
52
53// A primitive or container of StoragePrimitiveType.
54def quant_StorageValueType :
55    quant_TypedPrimitiveOrContainer<quant_StoragePrimitiveType>;
56
57// Either a real valued or storage primitive or container type.
58def quant_RealOrStorageValueType :
59    Type<Or<[quant_RealValueType.predicate,
60                quant_StorageValueType.predicate]>>;
61
62// An implementation of UniformQuantizedType.
63def quant_UniformQuantizedType :
64    DialectType<Quantization_Dialect,
65                CPred<"$_self.isa<UniformQuantizedType>()">,
66                "UniformQuantizedType">;
67
68// Predicate for detecting a container or primitive of UniformQuantizedType.
69def quant_UniformQuantizedValueType :
70    quant_TypedPrimitiveOrContainer<quant_UniformQuantizedType>;
71
72#endif // DIALECT_QUANT_QUANT_OPS_BASE_
73