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 
10 #include "QuantDialectBytecode.h"
14 #include "mlir/IR/Diagnostics.h"
15 #include "llvm/ADT/APFloat.h"
16 #include "llvm/ADT/TypeSwitch.h"
17 
18 using namespace mlir;
19 using namespace mlir::quant;
20 
21 namespace {
22 
23 static 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.
36 struct 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 
66 void quant::detail::addBytecodeInterface(QuantDialect *dialect) {
67  dialect->addInterfaces<QuantDialectBytecodeInterface>();
68 }
static MLIRContext * getContext(OpFoldResult val)
Attributes are known-constant values of operations.
Definition: Attributes.h:25
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.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:38
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
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:491
Include the generated interface declarations.