[Mlir-commits] [mlir] [MLIR][Affine] Check dependences during MDG init (PR #156422)
Uday Bondhugula
llvmlistbot at llvm.org
Wed Sep 3 23:23:53 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 :
----------------
bondhugula wrote:
Each of the lists src/dest stores/loads is expected to contain 1-2 load/stores initially and then typically a handful of them during/post fusion. Efficiency benefits from creating separate lists here (after filtering on `memref`) will be negligible and may even be slower for the common case! So kept it simple.
https://github.com/llvm/llvm-project/pull/156422
More information about the Mlir-commits
mailing list