[Mlir-commits] [mlir] [mlir][spirv] Add support for RelaxedPrecision in function arguments (PR #138685)
Igor Wodiany
llvmlistbot at llvm.org
Tue May 6 06:13:59 PDT 2025
https://github.com/IgWod-IMG created https://github.com/llvm/llvm-project/pull/138685
With the current implementation only one attribute is attached to the argument and the deserializer fails if more decorations are specified, however I believe that the spec does not prohibit having both `Aliased`/`Restrict` and `RelaxedPrecision`. I am not sure how to attach multiple attributes to a single argument with the current code and at the same time I do not have a use case for it, so I think the patch in the current state is a good starting point and can be extended in the future.
>From c9091989f285b5c862d0c25330c83b641cfdd9a4 Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Thu, 1 May 2025 11:44:18 +0100
Subject: [PATCH] [mlir][spirv] Add support for RelaxedPrecision in function
arguments
---
.../lib/Target/SPIRV/Deserialization/Deserializer.cpp | 11 +++++++++++
mlir/test/Target/SPIRV/decorations.mlir | 8 ++++++++
2 files changed, 19 insertions(+)
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 1e867dde51001..9b015448a6ac2 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -448,6 +448,17 @@ LogicalResult spirv::Deserializer::setFunctionArgAttrs(
foundDecorationAttr = spirv::DecorationAttr::get(context, decoration);
break;
}
+
+ if (decAttr.getName() == getSymbolDecoration(stringifyDecoration(
+ spirv::Decoration::RelaxedPrecision))) {
+ if (foundDecorationAttr)
+ return emitError(unknownLoc, "already found a decoration for function "
+ "argument with result <id> ")
+ << argID;
+
+ foundDecorationAttr = spirv::DecorationAttr::get(
+ context, spirv::Decoration::RelaxedPrecision);
+ }
}
if (!foundDecorationAttr)
diff --git a/mlir/test/Target/SPIRV/decorations.mlir b/mlir/test/Target/SPIRV/decorations.mlir
index d66ac74dc4ef9..fac47f7bd1086 100644
--- a/mlir/test/Target/SPIRV/decorations.mlir
+++ b/mlir/test/Target/SPIRV/decorations.mlir
@@ -151,3 +151,11 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [CacheControlsINTEL], [SP
spirv.Return
}
}
+
+// -----
+
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
+ spirv.func @relaxed_precision_arg(%arg0: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) -> () "None" attributes {relaxed_precision} {
+ spirv.Return
+ }
+}
More information about the Mlir-commits
mailing list