[Mlir-commits] [mlir] [MLIR][Affine] Fix fusion in the presence of cyclic deps in source nests (PR #128397)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Feb 24 00:49:47 PST 2025
================
@@ -28,10 +28,138 @@
#include <optional>
#include <type_traits>
+#define DEBUG_TYPE "affine-loop-analysis"
+
using namespace mlir;
using namespace mlir::affine;
-#define DEBUG_TYPE "affine-loop-analysis"
+namespace {
+
+/// A directed graph to model relationships between MLIR Operations.
+class DirectedOpGraph {
+public:
+ /// Add a node to
+ void addNode(Operation *op) {
+ assert(!hasNode(op) && "node already added");
+ nodes.emplace_back(op);
+ edges[op] = {};
+ }
+
+ /// Add an edge between `src` and `dest`.
+ void addEdge(Operation *src, Operation *dest) {
+ // This is a multi-graph.
+ assert(hasNode(src) && "src node does not exist in graph");
+ assert(hasNode(dest) && "dest node does not exist in graph");
+ edges[src].push_back(getNode(dest));
+ }
+
+ /// Returns true if there is a (directed) cycle in the graph.
+ bool hasCycle() { return dfsImpl(/*cycleCheck=*/true); }
+
+ void printEdges() {
+ for (auto &en : edges) {
+ llvm::dbgs() << *en.first << " (" << en.first << ")"
+ << " has " << en.second.size() << " edges:\n";
+ for (auto *node : en.second) {
+ llvm::dbgs() << '\t' << *node->op << '\n';
+ }
+ }
+ }
+
+private:
+ /// A node of a directed graph between MLIR Operations to model various
+ /// relationships. This is meant to be used internally.
+ struct DGNode {
+ DGNode(Operation *op) : op(op) {};
+ Operation *op;
+
+ // Start and finish visit numbers are standard in DFS to implement things
+ // strongly connected components. These numbers are modified during analyses
----------------
patel-vimal wrote:
typo in this phrase -> `implement things strongly connected components`.
https://github.com/llvm/llvm-project/pull/128397
More information about the Mlir-commits
mailing list