[Mlir-commits] [mlir] [mlir][dataflow] Improve DataFlowFramework debug output (PR #176632)

lonely eagle llvmlistbot at llvm.org
Mon Jan 19 02:45:09 PST 2026


https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/176632

>From 140d3a29464a55ba205c3ad3fe77689b501b6f15 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Sun, 18 Jan 2026 07:44:29 +0000
Subject: [PATCH 1/3] improve DataFlowFramework debug output.

---
 mlir/include/mlir/Analysis/DataFlowFramework.h | 2 ++
 mlir/lib/Analysis/DataFlowFramework.cpp        | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Analysis/DataFlowFramework.h b/mlir/include/mlir/Analysis/DataFlowFramework.h
index 87ec01a918d90..99801c67280dc 100644
--- a/mlir/include/mlir/Analysis/DataFlowFramework.h
+++ b/mlir/include/mlir/Analysis/DataFlowFramework.h
@@ -707,6 +707,8 @@ class DataFlowAnalysis {
 
   /// Allow the data-flow solver to access the internals of this class.
   friend class DataFlowSolver;
+  // Allow the AnalysisState to access the internals of this class.
+  friend class AnalysisState;
 };
 
 template <typename AnalysisT, typename... Args>
diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp
index 56780e8b7b127..2d4ef9f659d5a 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -46,7 +46,8 @@ void AnalysisState::addDependency(ProgramPoint *dependent,
   DATAFLOW_DEBUG({
     if (inserted) {
       LDBG() << "Creating dependency between " << debugName << " of " << anchor
-             << "\nand " << debugName << " on " << *dependent;
+             << "\nand " << debugName << " on " << *dependent << "\nwith "
+             << analysis->debugName;
     }
   });
 }
@@ -135,6 +136,8 @@ LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {
   // Run the analysis until fixpoint.
   // Iterate until all states are in some initialized state and the worklist
   // is exhausted.
+  DATAFLOW_DEBUG(LDBG() << "Initialize child analyses successfully, start run "
+                           "the analysis until fixpoint");
   while (!worklist.empty()) {
     auto [point, analysis] = worklist.front();
     worklist.pop();

>From 46498a940841f56681350ace99680452db8a6e09 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 19 Jan 2026 06:35:13 +0000
Subject: [PATCH 2/3] improve Subscribe log and update log.

---
 .../mlir/Analysis/DataFlow/SparseAnalysis.h    |  4 +---
 mlir/include/mlir/Analysis/DataFlowFramework.h |  6 ++----
 mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp  | 18 ++++++++++++++++--
 mlir/lib/Analysis/DataFlowFramework.cpp        | 13 +++++++++++++
 4 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
index 02f699de06f99..8f6fb85ddfec8 100644
--- a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
@@ -58,9 +58,7 @@ class AbstractSparseLattice : public AnalysisState {
   /// Subscribe an analysis to updates of the lattice. When the lattice changes,
   /// subscribed analyses are re-invoked on all users of the value. This is
   /// more efficient than relying on the dependency map.
-  void useDefSubscribe(DataFlowAnalysis *analysis) {
-    useDefSubscribers.insert(analysis);
-  }
+  void useDefSubscribe(DataFlowAnalysis *analysis);
 
 private:
   /// A set of analyses that should be updated when this lattice changes.
diff --git a/mlir/include/mlir/Analysis/DataFlowFramework.h b/mlir/include/mlir/Analysis/DataFlowFramework.h
index 99801c67280dc..c10d1da82e315 100644
--- a/mlir/include/mlir/Analysis/DataFlowFramework.h
+++ b/mlir/include/mlir/Analysis/DataFlowFramework.h
@@ -507,10 +507,7 @@ class AnalysisState {
   /// to enqueue more work items. For example, if a state tracks dependents
   /// through the IR (e.g. use-def chains), this function can be implemented to
   /// push those dependents on the worklist.
-  virtual void onUpdate(DataFlowSolver *solver) const {
-    for (const DataFlowSolver::WorkItem &item : dependents)
-      solver->enqueue(item);
-  }
+  virtual void onUpdate(DataFlowSolver *solver) const;
 
   /// The lattice anchor to which the state belongs.
   LatticeAnchor anchor;
@@ -518,6 +515,7 @@ class AnalysisState {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
   /// When compiling with debugging, keep a name for the analysis state.
   StringRef debugName;
+  StringRef getAnalysisDebugName(DataFlowAnalysis *analysis) const;
 #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
 
 private:
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index f86bb55df3ac5..aae588c501f85 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -36,9 +36,23 @@ void AbstractSparseLattice::onUpdate(DataFlowSolver *solver) const {
   AnalysisState::onUpdate(solver);
 
   // Push all users of the value to the queue.
-  for (Operation *user : cast<Value>(anchor).getUsers())
-    for (DataFlowAnalysis *analysis : useDefSubscribers)
+  for (Operation *user : cast<Value>(anchor).getUsers()) {
+    for (DataFlowAnalysis *analysis : useDefSubscribers) {
+      LDBG() << "Enqueuing user dependent work item: "
+             << *solver->getProgramPointAfter(user) << "\nwith "
+             << AnalysisState::getAnalysisDebugName(analysis);
       solver->enqueue({solver->getProgramPointAfter(user), analysis});
+    }
+  }
+}
+
+void AbstractSparseLattice::useDefSubscribe(DataFlowAnalysis *analysis) {
+  bool inserted = useDefSubscribers.insert(analysis);
+  if (inserted) {
+    LDBG() << debugName << " of " << anchor << "\n"
+           << "Value: " << *this << "\nsubscribing analysis: "
+           << AnalysisState::getAnalysisDebugName(analysis);
+  }
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp
index 2d4ef9f659d5a..53705a272f4a5 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -54,6 +54,19 @@ void AnalysisState::addDependency(ProgramPoint *dependent,
 
 void AnalysisState::dump() const { print(llvm::errs()); }
 
+void AnalysisState::onUpdate(DataFlowSolver *solver) const {
+  for (const DataFlowSolver::WorkItem &item : dependents) {
+    DATAFLOW_DEBUG(LDBG() << "Enqueueing dependent work item: " << *item.first
+                          << "\nwith " << item.second->debugName);
+    solver->enqueue(item);
+  }
+}
+
+StringRef
+AnalysisState::getAnalysisDebugName(DataFlowAnalysis *analysis) const {
+  return analysis->debugName;
+}
+
 //===----------------------------------------------------------------------===//
 // ProgramPoint
 //===----------------------------------------------------------------------===//

>From 8857701961c698966e187071feece6252e83a738 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 19 Jan 2026 10:44:52 +0000
Subject: [PATCH 3/3] take advice.

---
 mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 3 ++-
 mlir/lib/Analysis/DataFlowFramework.cpp       | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index aae588c501f85..8bb6f6eb7eff1 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -38,7 +38,8 @@ void AbstractSparseLattice::onUpdate(DataFlowSolver *solver) const {
   // Push all users of the value to the queue.
   for (Operation *user : cast<Value>(anchor).getUsers()) {
     for (DataFlowAnalysis *analysis : useDefSubscribers) {
-      LDBG() << "Enqueuing user dependent work item: "
+      LDBG() << debugName << " of " << anchor << "\n"
+             << "Value: " << *this << "\nenqueuing user dependent work item: "
              << *solver->getProgramPointAfter(user) << "\nwith "
              << AnalysisState::getAnalysisDebugName(analysis);
       solver->enqueue({solver->getProgramPointAfter(user), analysis});
diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp
index 53705a272f4a5..e573876f19ef3 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -56,7 +56,9 @@ void AnalysisState::dump() const { print(llvm::errs()); }
 
 void AnalysisState::onUpdate(DataFlowSolver *solver) const {
   for (const DataFlowSolver::WorkItem &item : dependents) {
-    DATAFLOW_DEBUG(LDBG() << "Enqueueing dependent work item: " << *item.first
+    DATAFLOW_DEBUG(LDBG() << debugName << " of " << anchor << "\n"
+                          << "Value: " << *this
+                          << "\nenqueueing dependent work item: " << *item.first
                           << "\nwith " << item.second->debugName);
     solver->enqueue(item);
   }



More information about the Mlir-commits mailing list