[Mlir-commits] [mlir] [mlir][vector] Add memref reshapes to transfer flow opt (PR #110521)

Han-Chung Wang llvmlistbot at llvm.org
Mon Sep 30 15:18:32 PDT 2024


================
@@ -193,12 +193,16 @@ MemrefValue skipFullyAliasingOperations(MemrefValue source) {
   return source;
 }
 
-MemrefValue skipSubViewsAndCasts(MemrefValue source) {
+MemrefValue skipViewLikeOps(MemrefValue source) {
   while (auto op = source.getDefiningOp()) {
     if (auto subView = dyn_cast<memref::SubViewOp>(op)) {
       source = cast<MemrefValue>(subView.getSource());
-    } else if (auto cast = dyn_cast<memref::CastOp>(op)) {
-      source = cast.getSource();
+    } else if (auto castOp = dyn_cast<memref::CastOp>(op)) {
+      source = castOp.getSource();
+    } else if (auto collapse = dyn_cast<memref::CollapseShapeOp>(op)) {
+      source = cast<MemrefValue>(collapse.getSrc());
+    } else if (auto expand = dyn_cast<memref::ExpandShapeOp>(op)) {
+      source = cast<MemrefValue>(expand.getSrc());
----------------
hanhanW wrote:

All of these operations implement `ViewLikeOpInterface`, can we just cast them to `ViewLikeOpInterface` and use the `getViewSource()` method?

https://github.com/llvm/llvm-project/blob/78ccffc05336201c90e2c0bb2ae929ea3a6eec2b/mlir/include/mlir/Interfaces/ViewLikeInterface.td#L18-L31

If there are other ViewLikeOpInterface ops broken, we can scope it to these few operations. E.g.,

```cpp
if (auto viewLikeOp = dyn_cast<ViewLikeOpInterface>(op)) {
  // If other ops become an issue, we can do
  // if (!isa<allow_list>(op)) break;
  source = viewLikeOp.getViewSource();
}
```

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


More information about the Mlir-commits mailing list