[Mlir-commits] [mlir] [MLIR][Affine] Check dependences during MDG init (PR #156422)

Arnab Dutta llvmlistbot at llvm.org
Wed Sep 3 20:50:57 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())
----------------
arnab-polymage wrote:

Likewise.

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


More information about the Mlir-commits mailing list