[Mlir-commits] [mlir] [mlir][linalg] Hoist transfer pairs through disjoint subview slices (PR #220244)
Hugo Pompougnac
llvmlistbot at llvm.org
Fri Sep 4 02:53:53 PDT 2026
================
@@ -351,5 +352,120 @@ bool hasNegativeStaticStride(MemRefType memRefTy) {
});
}
+namespace {
+/// Static footprint of a memref value resolved through a chain of
+/// rank-preserving, unit-stride `memref.subview` ops: the underlying root
+/// memref and, per root dimension, the `[offset, offset + size)` interval it
+/// covers.
+struct SubviewFootprint {
+ Value root;
+ SmallVector<int64_t> offsets;
+ SmallVector<int64_t> sizes;
+};
+} // namespace
+
+/// Resolve `base` through a `memref.subview` chain to its static footprint, or
+/// `std::nullopt` if it cannot be modelled statically.
+static std::optional<SubviewFootprint> resolveSubviewFootprint(Value base) {
+ SmallVector<SubViewOp> chain;
+ Value source = base;
+ while (auto sv = source.getDefiningOp<SubViewOp>()) {
+ chain.push_back(sv);
+ source = sv.getSource();
+ }
+ // The resolved root must be a genuine buffer, not another kind of view.
+ if (isa_and_nonnull<ViewLikeOpInterface>(source.getDefiningOp()))
+ return std::nullopt;
+
+ auto rootTy = dyn_cast<MemRefType>(source.getType());
+ if (!rootTy || !rootTy.hasStaticShape())
+ return std::nullopt;
+ SubviewFootprint footprint;
+ footprint.root = source;
+ // Seed with the whole-root footprint (offset 0, full extent per dimension).
+ // Each subview in the chain narrows it below.
+ footprint.offsets.assign(rootTy.getRank(), 0);
+ footprint.sizes.assign(rootTy.getShape().begin(), rootTy.getShape().end());
+ // Compose from the outermost subview (closest to the root) inward.
+ for (SubViewOp sv : llvm::reverse(chain)) {
+ // Rank-reducing subviews would misalign the per-dimension bookkeeping.
+ if (sv.getSourceType().getRank() != sv.getType().getRank())
+ return std::nullopt;
+ ArrayRef<int64_t> staticOffsets = sv.getStaticOffsets();
+ ArrayRef<int64_t> staticSizes = sv.getStaticSizes();
+ ArrayRef<int64_t> staticStrides = sv.getStaticStrides();
+ if (llvm::any_of(staticOffsets, ShapedType::isDynamic) ||
+ llvm::any_of(staticSizes, ShapedType::isDynamic) ||
+ llvm::any_of(staticStrides, [](int64_t s) { return s != 1; }))
+ return std::nullopt;
+ for (unsigned d = 0, e = staticOffsets.size(); d < e; ++d) {
+ footprint.offsets[d] += staticOffsets[d];
+ footprint.sizes[d] = staticSizes[d];
+ }
+ }
+ return footprint;
+}
+
+/// True if two footprints provably cover disjoint memory: they must share the
+/// same root and be separated along at least one dimension.
+static bool footprintsDisjoint(const SubviewFootprint &a,
----------------
qaco wrote:
Ok
https://github.com/llvm/llvm-project/pull/220244
More information about the Mlir-commits
mailing list