[Mlir-commits] [mlir] c38910b - [mlir][spirv] Add support for RelaxedPrecision in function arguments (#138685)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu May 8 22:35:44 PDT 2025


Author: Igor Wodiany
Date: 2025-05-08T22:35:41-07:00
New Revision: c38910bbb963c40e99d150ed456acdc10be4cd38

URL: https://github.com/llvm/llvm-project/commit/c38910bbb963c40e99d150ed456acdc10be4cd38
DIFF: https://github.com/llvm/llvm-project/commit/c38910bbb963c40e99d150ed456acdc10be4cd38.diff

LOG: [mlir][spirv] Add support for RelaxedPrecision in function arguments (#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.

Added: 
    

Modified: 
    mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
    mlir/test/Target/SPIRV/decorations.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 1e867dde51001..7afd6e9b25b77 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -448,6 +448,21 @@ LogicalResult spirv::Deserializer::setFunctionArgAttrs(
       foundDecorationAttr = spirv::DecorationAttr::get(context, decoration);
       break;
     }
+
+    if (decAttr.getName() == getSymbolDecoration(stringifyDecoration(
+                                 spirv::Decoration::RelaxedPrecision))) {
+      // TODO: Current implementation supports only one decoration per function
+      // parameter so RelaxedPrecision cannot be applied at the same time as,
+      // for example, Aliased/Restrict/etc. This should be relaxed to allow any
+      // combination of decoration allowed by the spec to be supported.
+      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..ee7ad814ea0cb 100644
--- a/mlir/test/Target/SPIRV/decorations.mlir
+++ b/mlir/test/Target/SPIRV/decorations.mlir
@@ -151,3 +151,12 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [CacheControlsINTEL], [SP
     spirv.Return
   }
 }
+
+// -----
+
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
+  // CHECK: spirv.func @relaxed_precision_arg({{%.*}}: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) "None" attributes {relaxed_precision} {
+  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