MLIR 22.0.0git
QuantDialectBytecode.cpp
Go to the documentation of this file.
1//===- QuantDialectBytecode.cpp - Quant Bytecode Implementation
2//------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
14#include "mlir/IR/Diagnostics.h"
15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/TypeSwitch.h"
17
18using namespace mlir;
19using namespace mlir::quant;
20
21namespace {
22
23static LogicalResult readDoubleAPFloat(DialectBytecodeReader &reader,
24 double &val) {
25 auto valOr =
26 reader.readAPFloatWithKnownSemantics(llvm::APFloat::IEEEdouble());
27 if (failed(valOr))
28 return failure();
29 val = valOr->convertToDouble();
30 return success();
31}
32
33#include "mlir/Dialect/Quant/IR/QuantDialectBytecode.cpp.inc"
34
35/// This class implements the bytecode interface for the Quant dialect.
36struct QuantDialectBytecodeInterface : public BytecodeDialectInterface {
37 QuantDialectBytecodeInterface(Dialect *dialect)
38 : BytecodeDialectInterface(dialect) {}
39
40 //===--------------------------------------------------------------------===//
41 // Attributes
42
43 Attribute readAttribute(DialectBytecodeReader &reader) const override {
44 return ::readAttribute(getContext(), reader);
45 }
46
47 LogicalResult writeAttribute(Attribute attr,
48 DialectBytecodeWriter &writer) const override {
49 return ::writeAttribute(attr, writer);
50 }
51
52 //===--------------------------------------------------------------------===//
53 // Types
54
55 Type readType(DialectBytecodeReader &reader) const override {
56 return ::readType(getContext(), reader);
57 }
58
59 LogicalResult writeType(Type type,
60 DialectBytecodeWriter &writer) const override {
61 return ::writeType(type, writer);
62 }
63};
64} // namespace
65
66void quant::detail::addBytecodeInterface(QuantDialect *dialect) {
67 dialect->addInterfaces<QuantDialectBytecodeInterface>();
68}
return success()
b getContext())
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual FailureOr< APFloat > readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics)=0
Read an APFloat that is known to have been encoded with the given semantics.
void addBytecodeInterface(QuantDialect *dialect)
Add the interfaces necessary for encoding the quantization dialect components in bytecode.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:561
Include the generated interface declarations.