[Mlir-commits] [mlir] [mlir][vector] Update syntax and representation of insert/extract_strided_slice (PR #101850)

Han-Chung Wang llvmlistbot at llvm.org
Tue Aug 6 10:29:18 PDT 2024


================
@@ -82,4 +87,63 @@ def Vector_PrintPunctuation : EnumAttr<Vector_Dialect, PrintPunctuation, "punctu
   let assemblyFormat = "`<` $value `>`";
 }
 
+def Vector_StridedSliceAttr : Vector_Attr<"StridedSlice", "strided_slice">
+{
+  let summary = "strided vector slice";
+
+  let description = [{
+    An attribute that represents a strided slice of a vector.
+
+    *Syntax:*
+
+    ```
+    offset = integer-literal
+    stride = integer-literal
+    size = integer-literal
+    offset-list = offset (`,` offset)*
+
+    // Without sizes (used for insert_strided_slice)
+    strided-slice-without-sizes = offset-list? (`[` offset `:` stride `]`)+
+
+    // With sizes (used for extract_strided_slice)
+    strided-slice-with-sizes = (`[` offset `:` size `:` stride `]`)+
+    ```
+
+    *Examples:*
+
+    Without sizes:
+
+    `[0:1][4:2]`
+
+    - The first dimension starts at offset 0 and is strided by 1
+    - The second dimension starts at offset 4 and is strided by 2
+
+    `[0, 1, 2][3:1][4:8]`
----------------
hanhanW wrote:

I think the existing syntax is clearer too. My first thought about `[1:2:1]` is something like 
"iterate on `range(1, 2)` with `strides=1`", though it does not make sense to insert/extract_strided_slice ops. Spelling out `offsets`, `sizes`, and `strides` looks clearer to me.

On the other hand, the existing style looks more consistent with the tensor version. E.g., `tensor.insert_slice %11 into %arg4[%8, 0] [1, 2] [1, 1]`

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


More information about the Mlir-commits mailing list