MLIR  16.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 "TypeDetail.h"
11 
13 #include "mlir/IR/BuiltinTypes.h"
14 #include "mlir/IR/MLIRContext.h"
15 #include "mlir/IR/Matchers.h"
16 #include "mlir/IR/PatternMatch.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/Support/MathExtras.h"
20 #include <numeric>
21 
22 using namespace mlir;
23 using namespace mlir::quant;
24 using namespace mlir::quant::detail;
25 
26 #include "mlir/Dialect/Quant/QuantOpsDialect.cpp.inc"
27 
28 void QuantizationDialect::initialize() {
31  addOperations<
32 #define GET_OP_LIST
33 #include "mlir/Dialect/Quant/QuantOps.cpp.inc"
34  >();
35 }
36 
37 OpFoldResult StorageCastOp::fold(ArrayRef<Attribute> operands) {
38  // Matches x -> [scast -> scast] -> y, replacing the second scast with the
39  // value of x if the casts invert each other.
40  auto srcScastOp = getArg().getDefiningOp<StorageCastOp>();
41  if (!srcScastOp || srcScastOp.getArg().getType() != getType())
42  return OpFoldResult();
43  return srcScastOp.getArg();
44 }
45 
46 #define GET_OP_CLASSES
47 #include "mlir/Dialect/Quant/QuantOps.cpp.inc"
Include the generated interface declarations.
This class represents a single result from folding an operation.
Definition: OpDefinition.h:239
Represents a family of uniform, quantized types.
Definition: QuantTypes.h:256
A quantized type that infers its range from given min/max values.
Definition: QuantTypes.h:383
A quantized type that maps storage to/from expressed types in an unspecified way. ...
Definition: QuantTypes.h:197
Represents per-axis (also known as per-channel quantization).
Definition: QuantTypes.h:314