10#include <mlir/Bytecode/BytecodeImplementation.h>
12#include <llvm/ADT/APInt.h>
20static constexpr auto kV1ConstParamsAttr =
"llzk.v1_const_params";
25 static mlir::FailureOr<LLZKDialectVersion>
read(mlir::DialectBytecodeReader &reader);
31 void write(mlir::DialectBytecodeWriter &writer)
const;
33 std::string
str()
const;
44inline void writeAPInt(mlir::DialectBytecodeWriter &writer,
const llvm::APInt &value) {
45 writer.writeVarInt(value.getBitWidth());
46 writer.writeAPIntWithKnownWidth(value);
50inline mlir::FailureOr<llvm::APInt>
readAPInt(mlir::DialectBytecodeReader &reader) {
52 if (mlir::failed(reader.readVarInt(bitWidth))) {
53 return mlir::failure();
55 if (bitWidth > std::numeric_limits<unsigned>::max()) {
56 return reader.emitError(
"APInt bit width too large");
58 return reader.readAPIntWithKnownWidth(
static_cast<unsigned>(bitWidth));
62template <
typename DialectTy>
68 void writeVersion(mlir::DialectBytecodeWriter &writer)
const override {
69 auto versionOr = writer.getDialectVersion<DialectTy>();
71 if (mlir::succeeded(versionOr)) {
81 std::unique_ptr<mlir::DialectVersion>
82 readVersion(mlir::DialectBytecodeReader &reader)
const override {
84 if (mlir::failed(versionOr)) {
87 return std::make_unique<LLZKDialectVersion>(std::move(*versionOr));
98 if (requested == current) {
99 return mlir::success();
101 if (requested > current) {
102 return rootOp->emitError().append(
103 "Cannot upgrade from current version ", current.str(),
" to future version ",
114 assert(requested < current &&
"pre-condition of upgradeFromVersion not met");
117 return mlir::success();
void writeAPInt(mlir::DialectBytecodeWriter &writer, const llvm::APInt &value)
Write an APInt with its bit width, so the bytecode reader can use MLIR's native APInt payload encodin...
mlir::FailureOr< llvm::APInt > readAPInt(mlir::DialectBytecodeReader &reader)
Read an APInt written by writeAPInt.
mlir::LogicalResult upgradeFromVersion(mlir::Operation *rootOp, const mlir::DialectVersion &version) const final
Hook invoked for each custom dialect after parsing is completed if a version directive was present an...
std::unique_ptr< mlir::DialectVersion > readVersion(mlir::DialectBytecodeReader &reader) const override
Read the version of this dialect from the provided reader and return it as a unique_ptr to a dialect ...
virtual mlir::LogicalResult upgradeFromVersion(mlir::Operation *, const LLZKDialectVersion ¤t, const LLZKDialectVersion &requested) const
void writeVersion(mlir::DialectBytecodeWriter &writer) const override
Writes the current version of the LLZK-lib to the given writer.
LLZKDialectBytecodeInterface(mlir::Dialect *dia)
static const LLZKDialectVersion & CurrentVersion()
LLZKDialectVersion(uint64_t majorV, uint64_t minorV, uint64_t patchV)
bool operator==(const LLZKDialectVersion &other) const
std::strong_ordering operator<=>(const LLZKDialectVersion &other) const
static mlir::FailureOr< LLZKDialectVersion > read(mlir::DialectBytecodeReader &reader)
void write(mlir::DialectBytecodeWriter &writer) const