https://github.com/jpienaar updated https://github.com/llvm/llvm-project/pull/79514
>From 06386cb0d21bb8e210e5ee3eef26df39680fc1d1 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar <jpien...@google.com> Date: Sat, 21 Oct 2023 17:06:33 -0700 Subject: [PATCH] [mlir][tosa] Add dialect version. This adds a singular number for the bytecode version. Considered adding spec related version, but decided that against that as 1) I think one may want to capture the minimum spec to execute separately (and it may be function of the ops in the module); 2) Its unrelated to reading the bytecode or upgrade/downgrade. So linking these together felt like linking error domains. --- mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h | 7 +++++++ mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 22 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h index a9bc3351f4cff..062fb28f5ebe3 100644 --- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h +++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h @@ -34,6 +34,13 @@ class PatternRewriter; namespace tosa { +struct TosaDialectVersion : public mlir::DialectVersion { + TosaDialectVersion() = default; + TosaDialectVersion(uint32_t dialectVersion) + : dialectVersion(dialectVersion){}; + uint32_t dialectVersion = 0; +}; + ParseResult parseTypeOrAttr(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &attr); void printTypeOrAttr(OpAsmPrinter &p, Operation *op, TypeAttr type, diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index 729116da45e47..b4035cadce331 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -97,18 +97,30 @@ struct TosaDialectBytecodeInterface : public BytecodeDialectInterface { } void writeVersion(DialectBytecodeWriter &writer) const final { - // TODO: Populate. + // This is currently not being written currently to allow readers to update + // first. +#if 0 + // TODO: This could be refined to not just pick current version. + auto version = TosaDialectVersion(); + writer.writeVarInt(version.dialectVersion); +#endif } std::unique_ptr<DialectVersion> readVersion(DialectBytecodeReader &reader) const final { - // TODO: Populate - reader.emitError("Dialect does not support versioning"); - return nullptr; + uint64_t dialectVersion; + if (failed(reader.readVarInt(dialectVersion))) + return nullptr; + auto version = std::make_unique<TosaDialectVersion>(); + version->dialectVersion = dialectVersion; + return version; } LogicalResult upgradeFromVersion(Operation *topLevelOp, - const DialectVersion &version_) const final { + const DialectVersion &version) const final { + const auto &tosaVersion = static_cast<const TosaDialectVersion &>(version); + // No upgrades currently defined. + (void)tosaVersion; return success(); } }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits