MLIR  19.0.0git
QuantOps.cpp
Go to the documentation of this file.
1 //===- QuantOps.cpp - Quantization Type and Ops Implementation --*- C++ -*-===//
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 
10 #include "QuantDialectBytecode.h"
11 #include "TypeDetail.h"
12 
14 #include "mlir/IR/BuiltinTypes.h"
15 #include "mlir/IR/MLIRContext.h"
16 #include "mlir/IR/Matchers.h"
17 #include "mlir/IR/PatternMatch.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Support/MathExtras.h"
21 #include <numeric>
22 
23 using namespace mlir;
24 using namespace mlir::quant;
25 using namespace mlir::quant::detail;
26 
27 #include "mlir/Dialect/Quant/QuantOpsDialect.cpp.inc"
28 
29 void QuantizationDialect::initialize() {
32  addOperations<
33 #define GET_OP_LIST
34 #include "mlir/Dialect/Quant/QuantOps.cpp.inc"
35  >();
37 }
38 
39 OpFoldResult StorageCastOp::fold(FoldAdaptor adaptor) {
40  // Matches x -> [scast -> scast] -> y, replacing the second scast with the
41  // value of x if the casts invert each other.
42  auto srcScastOp = getArg().getDefiningOp<StorageCastOp>();
43  if (!srcScastOp || srcScastOp.getArg().getType() != getType())
44  return OpFoldResult();
45  return srcScastOp.getArg();
46 }
47 
48 #define GET_OP_CLASSES
49 #include "mlir/Dialect/Quant/QuantOps.cpp.inc"
This class represents a single result from folding an operation.
Definition: OpDefinition.h:268
A quantized type that maps storage to/from expressed types in an unspecified way.
Definition: QuantTypes.h:196
A quantized type that infers its range from given min/max values.
Definition: QuantTypes.h:387
Represents per-axis (also known as per-channel quantization).
Definition: QuantTypes.h:317
Represents a family of uniform, quantized types.
Definition: QuantTypes.h:257
void addBytecodeInterface(QuantizationDialect *dialect)
Add the interfaces necessary for encoding the quantization dialect components in bytecode.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition: Utils.cpp:305