[Mlir-commits] [mlir] [MLIR][Affine] Check dependences during MDG init (PR #156422)
Arnab Dutta
llvmlistbot at llvm.org
Wed Sep 3 21:08:22 PDT 2025
================
@@ -241,7 +241,55 @@ addNodeToMDG(Operation *nodeOp, MemRefDependenceGraph &mdg,
return &node;
}
-bool MemRefDependenceGraph::init() {
+/// Returns true if there may be a dependence on `memref` from srcNode's
+/// memory ops to dstNode's memory ops, while using the affine memory
+/// dependence analysis checks. The method assumes that there is at least one
+/// memory op in srcNode's loads and stores on `memref`, and similarly for
+/// `dstNode`. `srcNode.op` and `destNode.op` are expected to be nested in the
+/// same block and so the dependences are tested at the depth of that block.
+static bool mayDependence(const Node &srcNode, const Node &dstNode,
+ Value memref) {
+ assert(srcNode.op->getBlock() == dstNode.op->getBlock());
+ if (!isa<AffineForOp>(srcNode.op) || !isa<AffineForOp>(dstNode.op))
+ return true;
+
+ // Non-affine stores, can't check. Conservatively, return true.
+ if (!srcNode.memrefStores.empty())
+ return true;
+ if (!dstNode.memrefStores.empty())
+ return true;
+
+ // Non-affine loads with a store in the other.
+ if (!srcNode.memrefLoads.empty() && !dstNode.stores.empty())
+ return true;
+ if (!dstNode.memrefLoads.empty() && !srcNode.stores.empty())
+ return true;
+
+ // Affine load/store pairs. We don't need to check for locally allocated
+ // memrefs since the dependence analysis here is between mem ops from
+ // srcNode's for op to dstNode's for op at the depth at which those
+ // `affine.for` ops are nested, i.e., dependences at depth `d + 1` where
+ // `d` is the number of common surrounding loops.
+ for (auto *srcMemOp :
----------------
arnab-polymage wrote:
This nested logic is inefficient I feel. How about creating two lists `srcMemOps` and `dstMemOps` separately where they contain memory operations only acting on `memref` in the src and dest nest respectively, and then iterate over them in nested manner. In the current implementation you end up itertaing over all the mem ops in src and dest nest in nested fashion.
https://github.com/llvm/llvm-project/pull/156422
More information about the Mlir-commits
mailing list