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
9#include "mlir/Dialect/Quant/QuantOps.h"
10#include "QuantDialectBytecode.h"
11#include "TypeDetail.h"
12
13#include "mlir/Dialect/Quant/QuantTypes.h"
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
23using namespace mlir;
24using namespace mlir::quant;
25using namespace mlir::quant::detail;
26
27#include "mlir/Dialect/Quant/QuantOpsDialect.cpp.inc"
28
29void QuantizationDialect::initialize() {
30 addTypes<AnyQuantizedType, CalibratedQuantizedType, UniformQuantizedType,
31 UniformQuantizedPerAxisType>();
32 addOperations<
33#define GET_OP_LIST
34#include "mlir/Dialect/Quant/QuantOps.cpp.inc"
35 >();
36 addBytecodeInterface(this);
37}
38
39OpFoldResult 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"
50

source code of mlir/lib/Dialect/Quant/IR/QuantOps.cpp