[Mlir-commits] [mlir] [mlir][dataflow] Add arguemnt print for test-liveness-analysis (PR #169625)

lonely eagle llvmlistbot at llvm.org
Wed Nov 26 04:03:13 PST 2025


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

>From 27ccbea9e9cd443b82c718f0978acd53a17b264c Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Wed, 26 Nov 2025 10:00:44 +0000
Subject: [PATCH 1/3] add arguemnt print for test-liveness-analysis.

---
 .../Analysis/DataFlow/test-liveness-analysis.mlir   | 13 ++++++++++++-
 .../lib/Analysis/DataFlow/TestLivenessAnalysis.cpp  |  9 +++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir b/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
index 3748be74eb0f3..74a1abfcedb8f 100644
--- a/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
+++ b/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
@@ -184,6 +184,17 @@ func.func private @private0(%0 : i32) -> i32 {
 // CHECK-NEXT:  result #0: live
 // CHECK-LABEL: test_tag: y:
 // CHECK-NEXT:  result #0: not live
+// CHECK-LABEL: test_tag: for:
+// CHECK-NEXT:  operand #0: live
+// CHECK-NEXT:  operand #1: live
+// CHECK-NEXT:  operand #2: live
+// CHECK-NEXT:  operand #3: live
+// CHECK-NEXT:  operand #4: not live
+// CHECK-NEXT:  result #0: live
+// CHECK-NEXT:  result #1: not live
+// CHECK-NEXT:  argument: #0: live
+// CHECK-NEXT:  argument: #1: not live
+// CHECK-NEXT:  argument: #2: not live
 func.func @test_7_type_3(%arg0: memref<i32>) {
   %c0 = arith.constant {tag = "zero"} 0 : index
   %c10 = arith.constant {tag = "ten"} 10 : index
@@ -194,7 +205,7 @@ func.func @test_7_type_3(%arg0: memref<i32>) {
     %1 = arith.addi %x, %x : i32
     %2 = func.call @private0(%1) : (i32) -> i32
     scf.yield %2, %arg3 : i32, i32
-  }
+  } {tag = "for"}
   memref.store %0#0, %arg0[] : memref<i32>
   return
 }
diff --git a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
index 8e2f03b644e49..04026008899af 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
@@ -56,6 +56,15 @@ struct TestLivenessAnalysisPass
         liveness->print(os);
         os << "\n";
       }
+      for (mlir::Region &region : op->getRegions()) {
+        for (auto [index, argument] : llvm::enumerate(region.getArguments())) {
+          const Liveness *liveness = livenessAnalysis.getLiveness(argument);
+          assert(liveness && "expected a sparse lattice");
+          os << " argument: #" << index << ": ";
+          liveness->print(os);
+          os << "\n";
+        }
+      }
     });
   }
 };

>From dab38a4afa05de8eb7d37206aedaa1e6aacf6050 Mon Sep 17 00:00:00 2001
From: lonely eagle <2020382038 at qq.com>
Date: Wed, 26 Nov 2025 19:52:56 +0800
Subject: [PATCH 2/3] Update
 mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp

Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
 mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
index 04026008899af..db5e07e135f11 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
@@ -60,7 +60,7 @@ struct TestLivenessAnalysisPass
         for (auto [index, argument] : llvm::enumerate(region.getArguments())) {
           const Liveness *liveness = livenessAnalysis.getLiveness(argument);
           assert(liveness && "expected a sparse lattice");
-          os << " argument: #" << index << ": ";
+          os << "   argument: #" << index << ": ";
           liveness->print(os);
           os << "\n";
         }

>From 8ee443c76dff71813d32f9312cf1c0c2adc6fe1a Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Wed, 26 Nov 2025 12:02:57 +0000
Subject: [PATCH 3/3] add print region index.

---
 mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir  | 1 +
 mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir b/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
index 74a1abfcedb8f..768f1cfcb3d02 100644
--- a/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
+++ b/mlir/test/Analysis/DataFlow/test-liveness-analysis.mlir
@@ -192,6 +192,7 @@ func.func private @private0(%0 : i32) -> i32 {
 // CHECK-NEXT:  operand #4: not live
 // CHECK-NEXT:  result #0: live
 // CHECK-NEXT:  result #1: not live
+// CHECK-NEXT:  region: #0:
 // CHECK-NEXT:  argument: #0: live
 // CHECK-NEXT:  argument: #1: not live
 // CHECK-NEXT:  argument: #2: not live
diff --git a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
index db5e07e135f11..99f72c6c86f20 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp
@@ -56,11 +56,13 @@ struct TestLivenessAnalysisPass
         liveness->print(os);
         os << "\n";
       }
-      for (mlir::Region &region : op->getRegions()) {
-        for (auto [index, argument] : llvm::enumerate(region.getArguments())) {
+      for (auto [regionIndex, region] : llvm::enumerate(op->getRegions())) {
+        os << " region: #" << regionIndex << ":\n";
+        for (auto [argumntIndex, argument] :
+             llvm::enumerate(region.getArguments())) {
           const Liveness *liveness = livenessAnalysis.getLiveness(argument);
           assert(liveness && "expected a sparse lattice");
-          os << "   argument: #" << index << ": ";
+          os << "   argument: #" << argumntIndex << ": ";
           liveness->print(os);
           os << "\n";
         }



More information about the Mlir-commits mailing list