[Mlir-commits] [mlir] [mlir][spirv] Update assembly format for Image operand types (PR #130758)

Igor Wodiany llvmlistbot at llvm.org
Fri Mar 14 03:55:02 PDT 2025


https://github.com/IgWod-IMG updated https://github.com/llvm/llvm-project/pull/130758

>From 939a9b665630bc1e41a9786b03337aa75d4d6c8c Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Tue, 11 Mar 2025 11:42:27 +0000
Subject: [PATCH] [mlir][spirv] Update assembly format for Image operand types

In the example below it is not clear that `(f32)` relates to
`%arg2` and not to `vector<2xf32>`:

```mlir
%0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Lod"](%arg2) :
  !spirv.sampled_image<...>, vector<2xf32>(f32) -> vector<4xf32>
```

This change applies new format to image operations and image
operands that does not use parenthesis and is less ambiguous:

```mlir
%0 = spirv.ImageSampleImplicitLod %arg0, %arg1 ["Lod"] %arg2 :
  !spirv.sampled_image<...>, vector<2xf32>, f32 -> vector<4xf32>
```
---
 mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td | 8 ++++----
 mlir/test/Dialect/SPIRV/IR/image-ops.mlir           | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
index a4fe29536e60a..5129a50667ca1 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
@@ -114,8 +114,8 @@ def SPIRV_ImageDrefGatherOp : SPIRV_Op<"ImageDrefGather",
 
 
   let assemblyFormat = [{
-    $sampled_image `,` $coordinate `,` $dref custom<ImageOperands>($image_operands) ( `(` $operand_arguments^ `)` )? attr-dict 
-    `:` type($sampled_image) `,` type($coordinate) `,` type($dref) ( `(` type($operand_arguments)^ `)` )?
+    $sampled_image `,` $coordinate `,` $dref custom<ImageOperands>($image_operands) ( $operand_arguments^ )? attr-dict
+    `:` type($sampled_image) `,` type($coordinate) `,` type($dref) ( `,` type($operand_arguments)^ )?
     `->` type($result) 
   }];
 
@@ -226,8 +226,8 @@ def SPIRV_ImageWriteOp : SPIRV_Op<"ImageWrite",
   let results = (outs);
 
   let assemblyFormat = [{
-    $image `,` $coordinate `,` $texel custom<ImageOperands>($image_operands) ( `(` $operand_arguments^ `)`)? attr-dict
-    `:` type($image) `,` type($coordinate) `,` type($texel) ( `(` type($operand_arguments)^ `)`)?
+    $image `,` $coordinate `,` $texel custom<ImageOperands>($image_operands) ( $operand_arguments^ )? attr-dict
+    `:` type($image) `,` type($coordinate) `,` type($texel) ( `,` type($operand_arguments)^ )?
   }];
 }
 
diff --git a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
index 266b69fd117d8..eff7470516bb1 100644
--- a/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/image-ops.mlir
@@ -22,7 +22,7 @@ func.func @image_dref_gather_with_single_imageoperands(%arg0 : !spirv.sampled_im
 
 func.func @image_dref_gather_with_mismatch_imageoperands(%arg0 : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, %arg1 : vector<4xf32>, %arg2 : f32) -> () {
   // expected-error @+1 {{the Image Operands should encode what operands follow, as per Image Operands}}
-  %0 = spirv.ImageDrefGather %arg0, %arg1, %arg2 (%arg2, %arg2) : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, vector<4xf32>, f32 (f32, f32) -> vector<4xi32>
+  %0 = spirv.ImageDrefGather %arg0, %arg1, %arg2 %arg2, %arg2 : !spirv.sampled_image<!spirv.image<i32, Dim2D, NoDepth, NonArrayed, SingleSampled, NoSampler, Unknown>>, vector<4xf32>, f32, f32, f32 -> vector<4xi32>
   spirv.Return
 }
 



More information about the Mlir-commits mailing list