Skip to content

Commit 6e4b4e8

Browse files
committed
Renamed to QuantStorageTypeInterface and removed redundant dyn_cast checks
1 parent 407fae4 commit 6e4b4e8

File tree

9 files changed

+50
-59
lines changed

9 files changed

+50
-59
lines changed

mlir/include/mlir/IR/BuiltinTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class BaseMemRefType : public Type,
167167
// Tablegen Type Declarations
168168
//===----------------------------------------------------------------------===//
169169

170-
#include "mlir/IR/QuantizationInterface.h"
170+
#include "mlir/IR/QuantStorageTypeInterface.h"
171171

172172
#define GET_TYPEDEF_CLASSES
173173
#include "mlir/IR/BuiltinTypes.h.inc"

mlir/include/mlir/IR/BuiltinTypes.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
include "mlir/IR/AttrTypeBase.td"
1818
include "mlir/IR/BuiltinDialect.td"
1919
include "mlir/IR/BuiltinTypeInterfaces.td"
20-
include "mlir/IR/QuantizationInterface.td"
20+
include "mlir/IR/QuantStorageTypeInterface.td"
2121
include "mlir/IR/CommonTypeConstraints.td"
2222

2323
// TODO: Currently the types defined in this file are prefixed with `Builtin_`.
@@ -102,7 +102,7 @@ class Builtin_CachedFloatType<string name, string mnemonic,
102102
//===----------------------------------------------------------------------===//
103103

104104
def Builtin_Float8E5M2 : Builtin_FloatType<"Float8E5M2", "f8E5M2",
105-
["QuantizationInterface"]> {
105+
["QuantStorageTypeInterface"]> {
106106
let summary = "8-bit floating point with 2 bit mantissa";
107107
let description = [{
108108
An 8-bit floating point type with 1 sign bit, 5 bits exponent and 2 bits
@@ -120,7 +120,7 @@ def Builtin_Float8E5M2 : Builtin_FloatType<"Float8E5M2", "f8E5M2",
120120
}];
121121

122122
let extraClassDeclaration = [{
123-
/// QuantizationInterface method implementations
123+
/// QuantStorageTypeInterface method implementations
124124
bool isStorageSigned() const { return true; }
125125
/// Get the bit width of this 8-bit floating point type.
126126
unsigned getStorageWidth() const { return 8; }
@@ -160,7 +160,7 @@ def Builtin_Float8E4M3 : Builtin_FloatType<"Float8E4M3", "f8E4M3"> {
160160
//===----------------------------------------------------------------------===//
161161

162162
def Builtin_Float8E4M3FN : Builtin_FloatType<"Float8E4M3FN", "f8E4M3FN",
163-
["QuantizationInterface"]> {
163+
["QuantStorageTypeInterface"]> {
164164
let summary = "8-bit floating point with 3 bit mantissa";
165165
let description = [{
166166
An 8-bit floating point type with 1 sign bit, 4 bits exponent and 3 bits
@@ -179,7 +179,7 @@ def Builtin_Float8E4M3FN : Builtin_FloatType<"Float8E4M3FN", "f8E4M3FN",
179179
}];
180180

181181
let extraClassDeclaration = [{
182-
/// QuantizationInterface method implementations
182+
/// QuantStorageTypeInterface method implementations
183183
bool isStorageSigned() const { return true; }
184184
/// Get the bit width of this 8-bit floating point type.
185185
unsigned getStorageWidth() const { return 8; }
@@ -530,7 +530,7 @@ def Builtin_Index : Builtin_Type<"Index", "index",
530530
//===----------------------------------------------------------------------===//
531531

532532
def Builtin_Integer : Builtin_Type<"Integer", "integer",
533-
[VectorElementTypeInterface, QuantizationInterface]> {
533+
[VectorElementTypeInterface, QuantStorageTypeInterface]> {
534534
let summary = "Integer type with arbitrary precision up to a fixed limit";
535535
let description = [{
536536
Syntax:
@@ -588,7 +588,7 @@ def Builtin_Integer : Builtin_Type<"Integer", "integer",
588588
/// Note: This is aligned with the maximum width of llvm::IntegerType.
589589
static constexpr unsigned kMaxWidth = (1 << 24) - 1;
590590

591-
/// QuantizationInterface method implementations
591+
/// QuantStorageTypeInterface method implementations
592592
/// Return true if this is a signed or signless integer type.
593593
bool isStorageSigned() const { return !isUnsigned(); }
594594
/// Get the bit width of this integer type.

mlir/include/mlir/IR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_mlir_interface(SymbolInterfaces)
22
add_mlir_interface(RegionKindInterface)
33

4-
add_mlir_type_interface(QuantizationInterface)
4+
add_mlir_type_interface(QuantStorageTypeInterface)
55

66
set(LLVM_TARGET_DEFINITIONS OpAsmInterface.td)
77
mlir_tablegen(OpAsmAttrInterface.h.inc -gen-attr-interface-decls)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- QuantizationInterface.h - Quantzation Interfaces --------*- C++
1+
//===- QuantStorageTypeInterface.h - Quantzation Interfaces --------*- C++
22
//-*-===//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef MLIR_IR_QuantizationInterface_H
11-
#define MLIR_IR_QuantizationInterface_H
10+
#ifndef MLIR_IR_QuantStorageTypeInterface_H
11+
#define MLIR_IR_QuantStorageTypeInterface_H
1212

1313
#include "mlir/IR/Types.h"
1414

@@ -17,6 +17,6 @@ namespace mlir {
1717
class IntegerType;
1818
} // namespace mlir
1919

20-
#include "mlir/IR/QuantizationInterface.h.inc"
20+
#include "mlir/IR/QuantStorageTypeInterface.h.inc"
2121

22-
#endif // MLIR_IR_QuantizationInterface_H
22+
#endif // MLIR_IR_QuantStorageTypeInterface_H

mlir/include/mlir/IR/QuantizationInterface.td renamed to mlir/include/mlir/IR/QuantStorageTypeInterface.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef MLIR_IR_QUANTIZATIONINTERFACE
2-
#define MLIR_IR_QUANTIZATIONINTERFACE
1+
#ifndef MLIR_IR_QuantStorageTypeInterface
2+
#define MLIR_IR_QuantStorageTypeInterface
33

44
include "mlir/IR/OpBase.td"
55

6-
def QuantizationInterface : TypeInterface<"QuantizationInterface"> {
6+
def QuantStorageTypeInterface : TypeInterface<"QuantStorageTypeInterface"> {
77
let description = [{
88
Interface for types that can be used as storage types in Quant dialect.
99
This interface provides methods to determine storage characteristics for quantization purposes.
@@ -41,4 +41,4 @@ def QuantizationInterface : TypeInterface<"QuantizationInterface"> {
4141

4242
}
4343

44-
#endif // MLIR_IR_QUANTIZATIONINTERFACE
44+
#endif // MLIR_IR_QuantStorageTypeInterface

mlir/lib/Dialect/Quant/IR/QuantTypes.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "mlir/Dialect/Quant/IR/QuantTypes.h"
1010
#include "TypeDetail.h"
1111
#include "mlir/Dialect/Quant/IR/Quant.h"
12-
#include "mlir/IR/QuantizationInterface.h"
12+
#include "mlir/IR/QuantStorageTypeInterface.h"
1313

1414
#include "mlir/IR/BuiltinTypes.h"
1515
#include "mlir/IR/MLIRContext.h"
@@ -47,23 +47,16 @@ QuantizedType::verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
4747
unsigned flags, Type storageType,
4848
Type expressedType, int64_t storageTypeMin,
4949
int64_t storageTypeMax) {
50-
// Verify that the storage type is integral.
51-
// This restriction may be lifted at some point in favor of using bf16
52-
// or f16 as exact representations on hardware where that is advantageous.
53-
auto intStorageType = llvm::dyn_cast<IntegerType>(storageType);
54-
if (!intStorageType)
55-
return emitError() << "storage type must be integral";
56-
57-
if (auto quantizationInterface =
58-
llvm::dyn_cast<QuantizationInterface>(storageType)) {
59-
unsigned integralWidth = quantizationInterface.getStorageWidth();
50+
if (auto quantStorageTypeInterface =
51+
llvm::dyn_cast<QuantStorageTypeInterface>(storageType)) {
52+
unsigned integralWidth = quantStorageTypeInterface.getStorageWidth();
6053

6154
// Verify storage width.
6255
if (integralWidth == 0 || integralWidth > MaxStorageBits)
6356
return emitError() << "illegal storage type size: " << integralWidth;
6457

65-
int64_t defaultMin = quantizationInterface.getDefaultMinimum();
66-
int64_t defaultMax = quantizationInterface.getDefaultMaximum();
58+
int64_t defaultMin = quantStorageTypeInterface.getDefaultMinimum();
59+
int64_t defaultMax = quantStorageTypeInterface.getDefaultMaximum();
6760

6861
if (storageTypeMax - storageTypeMin <= 0 || storageTypeMin < defaultMin ||
6962
storageTypeMax > defaultMax) {
@@ -74,7 +67,7 @@ QuantizedType::verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
7467
return success();
7568
}
7669

77-
return emitError() << "storage type must implement QuantizationInterface";
70+
return emitError() << "storage type must implement QuantStorageTypeInterface";
7871
}
7972

8073
Type QuantizedType::getStorageType() const {
@@ -91,21 +84,21 @@ int64_t QuantizedType::getStorageTypeMax() const {
9184

9285
bool QuantizedType::hasStorageTypeBounds() const {
9386
Type storageType = static_cast<ImplType *>(impl)->storageType;
94-
auto quantizationInterface =
95-
llvm::dyn_cast<QuantizationInterface>(storageType);
87+
auto quantStorageTypeInterface =
88+
llvm::dyn_cast<QuantStorageTypeInterface>(storageType);
9689

97-
int64_t defaultMin = quantizationInterface.getDefaultMinimum();
98-
int64_t defaultMax = quantizationInterface.getDefaultMaximum();
90+
int64_t defaultMin = quantStorageTypeInterface.getDefaultMinimum();
91+
int64_t defaultMax = quantStorageTypeInterface.getDefaultMaximum();
9992

10093
return defaultMin != getStorageTypeMin() || defaultMax != getStorageTypeMax();
10194
}
10295

10396
unsigned QuantizedType::getStorageTypeIntegralWidth() const {
10497
Type storageType = static_cast<ImplType *>(impl)->storageType;
105-
auto quantizationInterface =
106-
llvm::dyn_cast<QuantizationInterface>(storageType);
98+
auto quantStorageTypeInterface =
99+
llvm::dyn_cast<QuantStorageTypeInterface>(storageType);
107100

108-
return quantizationInterface.getStorageWidth();
101+
return quantStorageTypeInterface.getStorageWidth();
109102
}
110103

111104
Type QuantizedType::getExpressedType() const {

mlir/lib/Dialect/Quant/IR/TypeParser.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "mlir/Dialect/Quant/IR/QuantTypes.h"
1111
#include "mlir/IR/BuiltinTypes.h"
1212
#include "mlir/IR/DialectImplementation.h"
13-
#include "mlir/IR/QuantizationInterface.h"
13+
#include "mlir/IR/QuantStorageTypeInterface.h"
1414
#include "mlir/IR/Types.h"
1515
#include "llvm/ADT/APFloat.h"
1616

@@ -29,10 +29,10 @@ static Type parseStorageType(DialectAsmParser &parser, bool &isSigned) {
2929
if (!succeeded(*result))
3030
return nullptr;
3131

32-
if (auto quantizationInterface =
33-
llvm::dyn_cast<QuantizationInterface>(type)) {
34-
isSigned = quantizationInterface.isStorageSigned();
35-
storageTypeWidth = quantizationInterface.getStorageWidth();
32+
if (auto quantStorageTypeInterface =
33+
llvm::dyn_cast<QuantStorageTypeInterface>(type)) {
34+
isSigned = quantStorageTypeInterface.isStorageSigned();
35+
storageTypeWidth = quantStorageTypeInterface.getStorageWidth();
3636
} else {
3737
parser.emitError(typeLoc, "illegal quantized storage type alias");
3838
return nullptr;
@@ -67,12 +67,11 @@ static Type parseStorageType(DialectAsmParser &parser, bool &isSigned) {
6767
static ParseResult parseStorageRange(DialectAsmParser &parser, Type storageType,
6868
int64_t &storageTypeMin,
6969
int64_t &storageTypeMax) {
70-
int64_t defaultMin, defaultMax;
71-
if (auto quantizationInterface =
72-
llvm::dyn_cast<QuantizationInterface>(storageType)) {
73-
defaultMin = quantizationInterface.getDefaultMinimum();
74-
defaultMax = quantizationInterface.getDefaultMaximum();
75-
}
70+
auto quantStorageTypeInterface =
71+
llvm::dyn_cast<QuantStorageTypeInterface>(storageType);
72+
73+
int64_t defaultMin = quantStorageTypeInterface.getDefaultMinimum();
74+
int64_t defaultMax = quantStorageTypeInterface.getDefaultMaximum();
7675

7776
if (failed(parser.parseOptionalLess())) {
7877
storageTypeMin = defaultMin;
@@ -495,10 +494,10 @@ Type QuantDialect::parseType(DialectAsmParser &parser) const {
495494

496495
static void printStorageType(QuantizedType type, DialectAsmPrinter &out) {
497496
// storage type
498-
if (auto quantizationInterface =
499-
llvm::dyn_cast<QuantizationInterface>(type.getStorageType())) {
500-
out << quantizationInterface.getStorageType();
501-
}
497+
auto quantStorageTypeInterface =
498+
llvm::dyn_cast<QuantStorageTypeInterface>(type.getStorageType());
499+
500+
out << quantStorageTypeInterface.getStorageType();
502501

503502
// storageTypeMin and storageTypeMax if not default.
504503
if (type.hasStorageTypeBounds()) {

mlir/lib/IR/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_mlir_library(MLIRIR
3131
OperationSupport.cpp
3232
PatternLoggingListener.cpp
3333
PatternMatch.cpp
34-
QuantizationInterface.cpp
34+
QuantStorageTypeInterface.cpp
3535
Region.cpp
3636
RegionKindInterface.cpp
3737
SymbolTable.cpp
@@ -63,7 +63,7 @@ add_mlir_library(MLIRIR
6363
MLIRCastInterfacesIncGen
6464
MLIRDataLayoutInterfacesIncGen
6565
MLIROpAsmInterfaceIncGen
66-
MLIRQuantizationInterfaceIncGen
66+
MLIRQuantStorageTypeInterfaceIncGen
6767
MLIRRegionKindInterfaceIncGen
6868
MLIRSideEffectInterfacesIncGen
6969
MLIRSymbolInterfacesIncGen
@@ -72,4 +72,3 @@ add_mlir_library(MLIRIR
7272
LINK_LIBS PUBLIC
7373
MLIRSupport
7474
)
75-

mlir/lib/IR/QuantizationInterface.cpp renamed to mlir/lib/IR/QuantStorageTypeInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- QuantizationInterface.cpp
1+
//===- QuantStorageTypeInterface.cpp
22
//------------------------------------------===//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -20,4 +20,4 @@ using namespace mlir::detail;
2020
/// Tablegen Interface Definitions
2121
//===----------------------------------------------------------------------===//
2222

23-
#include "mlir/IR/QuantizationInterface.cpp.inc"
23+
#include "mlir/IR/QuantStorageTypeInterface.cpp.inc"

0 commit comments

Comments
 (0)