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
10#include "QuantDialectBytecode.h"
11#include "mlir/Bytecode/BytecodeImplementation.h"
12#include "mlir/Dialect/Quant/IR/Quant.h"
13#include "mlir/Dialect/Quant/IR/QuantTypes.h"
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(semantics: llvm::APFloat::IEEEdouble());
27 if (failed(Result: 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(context: getContext(), reader);
45 }
46
47 LogicalResult writeAttribute(Attribute attr,
48 DialectBytecodeWriter &writer) const override {
49 return ::writeAttribute(attribute: attr, writer);
50 }
51
52 //===--------------------------------------------------------------------===//
53 // Types
54
55 Type readType(DialectBytecodeReader &reader) const override {
56 return ::readType(context: 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}
69

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