[Mlir-commits] [mlir] [mlir][tosa] Add specification versioning to target environment (PR #156425)

Luke Hutton llvmlistbot at llvm.org
Wed Oct 8 03:54:26 PDT 2025


================
@@ -50,28 +50,63 @@ TargetEnvAttr getDefaultTargetEnv(MLIRContext *context);
 /// returned by getDefaultTargetEnv() if not provided.
 TargetEnvAttr lookupTargetEnvOrDefault(Operation *op);
 
+/// A thin wrapper around the SpecificationVersion enum to represent
+/// and provide utilities around the TOSA specification version.
+class TosaSpecificationVersion {
+public:
+  TosaSpecificationVersion(uint32_t major, uint32_t minor)
+      : majorVersion(major), minorVersion(minor) {}
+  TosaSpecificationVersion(SpecificationVersion version)
+      : TosaSpecificationVersion(fromVersionEnum(version)) {}
+
+  bool isBackwardsCompatibleWith(TosaSpecificationVersion baseVersion) const {
+    return this->majorVersion == baseVersion.majorVersion &&
+           this->minorVersion >= baseVersion.minorVersion;
+  }
+
+  uint32_t getMajor() const { return majorVersion; }
+  uint32_t getMinor() const { return minorVersion; }
+
+private:
+  uint32_t majorVersion = 0;
+  uint32_t minorVersion = 0;
----------------
lhutton1 wrote:

Yep, I feel patch versions of the spec likely won't be useful due to the nature of the changes, since they cannot add functionality, only make clarifications. It should be relatively easy to extend in the future if there's a case however.

Similarly for `draft`, though I'd be more hesitant to add since any feature checks for `draft` will need to become the non-draft version at some point anyway (that is, we should not be holding onto `draft` versions). Note that this patch does use `1.1.draft` for the user-facing API, at least until 1.1 is released.

https://github.com/llvm/llvm-project/pull/156425


More information about the Mlir-commits mailing list