brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 1b3cc5a Raw
69 lines · cpp
1//===- QuantDialectBytecode.cpp - Quant Bytecode Implementation2//------------===//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-exception7//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(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  // Attributes42 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  // Types54 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} // namespace65 66void quant::detail::addBytecodeInterface(QuantDialect *dialect) {67  dialect->addInterfaces<QuantDialectBytecodeInterface>();68}69