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

lonely eagle llvmlistbot at llvm.org
Tue Jan 20 03:52:05 PST 2026


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

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

---
 .../mlir/Analysis/DataFlow/SparseAnalysis.h   |  4 +---
 .../include/mlir/Analysis/DataFlowFramework.h |  8 +++----
 mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 19 +++++++++++++++--
 mlir/lib/Analysis/DataFlowFramework.cpp       | 21 +++++++++++++++++--
 4 files changed, 41 insertions(+), 11 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 87ec01a918d90..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:
@@ -707,6 +705,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/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index 6515e42bb2081..d47413943b707 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -36,9 +36,24 @@ 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() << debugName << " of " << anchor << "\n"
+             << "Value: " << *this << "\nenqueuing 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 c848a98576845..ddaa07bd1f682 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -37,15 +37,30 @@ AnalysisState::~AnalysisState() = default;
 void AnalysisState::addDependency(ProgramPoint *dependent,
                                   DataFlowAnalysis *analysis) {
   auto inserted = dependents.insert({dependent, analysis});
-  (void)inserted;
   if (inserted) {
     LDBG() << "Creating dependency between " << debugName << " of " << anchor
-           << "\nand " << debugName << " on " << *dependent;
+           << "\nand " << debugName << " on " << *dependent << "\nwith "
+           << analysis->debugName;
   }
 }
 
 void AnalysisState::dump() const { print(llvm::errs()); }
 
+void AnalysisState::onUpdate(DataFlowSolver *solver) const {
+  for (const DataFlowSolver::WorkItem &item : dependents) {
+    LDBG() << debugName << " of " << anchor << "\n"
+           << "Value: " << *this
+           << "\nenqueueing dependent work item: " << *item.first << "\nwith "
+           << item.second->debugName;
+    solver->enqueue(item);
+  }
+}
+
+StringRef
+AnalysisState::getAnalysisDebugName(DataFlowAnalysis *analysis) const {
+  return analysis->debugName;
+}
+
 //===----------------------------------------------------------------------===//
 // ProgramPoint
 //===----------------------------------------------------------------------===//
@@ -128,6 +143,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.
+  LDBG() << "Initialize child analyses successfully, start run "
+            "the analysis until fixpoint";
   while (!worklist.empty()) {
     auto [point, analysis] = worklist.front();
     worklist.pop();



More information about the Mlir-commits mailing list