[Mlir-commits] [mlir] [MLIR][Vector] Add unrolling pattern for vector StepOp (PR #157752)

Erick Ochoa Lopez llvmlistbot at llvm.org
Tue Sep 16 09:19:41 PDT 2025


================
@@ -3018,6 +3018,7 @@ def Vector_ScanOp :
 
 def Vector_StepOp : Vector_Op<"step", [
     Pure,
+    DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
----------------
amd-eochoalo wrote:

The interface contains a default implementation 

```tblgen
def VectorUnrollOpInterface : OpInterface<"VectorUnrollOpInterface"> {
  let description = [{
    Encodes properties of an operation on vectors that can be unrolled.
  }];
  let cppNamespace = "::mlir";

  let methods = [
    InterfaceMethod<
      /*desc=*/[{
        Return the shape ratio of unrolling to the target vector shape
        `targetShape`. Return `std::nullopt` if the op cannot be unrolled to the
        target vector shape.
      }],
      /*retTy=*/"::std::optional<::llvm::SmallVector<int64_t, 4>>",
      /*methodName=*/"getShapeForUnroll",
      /*args=*/(ins),
      /*methodBody=*/"",
      /*defaultImplementation=*/[{
        assert($_op->getNumResults() == 1);
        auto vt =
            ::llvm::dyn_cast<::mlir::VectorType>($_op.getResult().getType());
        if (!vt)
          return ::std::nullopt;
        ::llvm::SmallVector<int64_t, 4> res(
            vt.getShape().begin(), vt.getShape().end());
        return res;
      }]
    >,
  ];
}
```

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


More information about the Mlir-commits mailing list