[Mlir-commits] [mlir] [MLIR][SliceAnalysis] Add comment and restore failure condition (PR #142223)

William Moses llvmlistbot at llvm.org
Thu Oct 16 17:20:33 PDT 2025


https://github.com/wsmoses updated https://github.com/llvm/llvm-project/pull/142223

>From 90167b53edc46a32fbd3cb7dd9bf79617ffd2026 Mon Sep 17 00:00:00 2001
From: "William S. Moses" <gh at wsmoses.com>
Date: Fri, 30 May 2025 18:24:19 -0400
Subject: [PATCH 1/4] [MLIR][SliceAnalysis] Add comment and restore failure
 condition

---
 mlir/include/mlir/Analysis/SliceAnalysis.h | 2 ++
 mlir/lib/Analysis/SliceAnalysis.cpp        | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/mlir/include/mlir/Analysis/SliceAnalysis.h b/mlir/include/mlir/Analysis/SliceAnalysis.h
index d082d2d9f758b..dc0d56d6b753d 100644
--- a/mlir/include/mlir/Analysis/SliceAnalysis.h
+++ b/mlir/include/mlir/Analysis/SliceAnalysis.h
@@ -140,6 +140,8 @@ void getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
 ///
 /// This function returns whether the backwards slice was able to be
 /// successfully computed, and failure if it was unable to determine the slice.
+/// This function will presently return failure if a value to process is a blockargument
+/// whose parent op has more than region or more than one block.
 LogicalResult getBackwardSlice(Operation *op,
                                SetVector<Operation *> *backwardSlice,
                                const BackwardSliceOptions &options = {});
diff --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp
index 4cdf47a405c01..20ba558507f4e 100644
--- a/mlir/lib/Analysis/SliceAnalysis.cpp
+++ b/mlir/lib/Analysis/SliceAnalysis.cpp
@@ -109,6 +109,8 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
         if (parentOp->getNumRegions() == 1 &&
             llvm::hasSingleElement(parentOp->getRegion(0).getBlocks())) {
           return getBackwardSliceImpl(parentOp, backwardSlice, options);
+        } else {
+          return failure();
         }
       }
     } else {

>From 1a578c9bfeb4c295c9f690ecdecc2bd04819251c Mon Sep 17 00:00:00 2001
From: William Moses <gh at wsmoses.com>
Date: Sat, 31 May 2025 12:17:50 -0400
Subject: [PATCH 2/4] Update mlir/include/mlir/Analysis/SliceAnalysis.h

Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
 mlir/include/mlir/Analysis/SliceAnalysis.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Analysis/SliceAnalysis.h b/mlir/include/mlir/Analysis/SliceAnalysis.h
index dc0d56d6b753d..b6efdcee30683 100644
--- a/mlir/include/mlir/Analysis/SliceAnalysis.h
+++ b/mlir/include/mlir/Analysis/SliceAnalysis.h
@@ -141,7 +141,7 @@ void getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
 /// This function returns whether the backwards slice was able to be
 /// successfully computed, and failure if it was unable to determine the slice.
 /// This function will presently return failure if a value to process is a blockargument
-/// whose parent op has more than region or more than one block.
+/// whose parent op has more than one region, or a region with more than one block.
 LogicalResult getBackwardSlice(Operation *op,
                                SetVector<Operation *> *backwardSlice,
                                const BackwardSliceOptions &options = {});

>From d81f2df72f11cd4434fb5de8e5603535892179c2 Mon Sep 17 00:00:00 2001
From: William Moses <gh at wsmoses.com>
Date: Fri, 17 Oct 2025 08:11:21 +0800
Subject: [PATCH 3/4] Update SliceAnalysis.h

---
 mlir/include/mlir/Analysis/SliceAnalysis.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Analysis/SliceAnalysis.h b/mlir/include/mlir/Analysis/SliceAnalysis.h
index 96a128184e21d..61ee9ffbd25ff 100644
--- a/mlir/include/mlir/Analysis/SliceAnalysis.h
+++ b/mlir/include/mlir/Analysis/SliceAnalysis.h
@@ -142,8 +142,9 @@ void getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
 ///
 /// This function returns whether the backwards slice was able to be
 /// successfully computed, and failure if it was unable to determine the slice.
-/// This function will presently return failure if a value to process is a blockargument
-/// whose parent op has more than one region, or a region with more than one block.
+/// This function will presently return failure if a value to process is a
+/// blockargument whose parent op has more than one region, or a region with
+/// more than one block.
 LogicalResult getBackwardSlice(Operation *op,
                                SetVector<Operation *> *backwardSlice,
                                const BackwardSliceOptions &options = {});

>From 0c088277a07f581a9f9099434d839973ac0861a2 Mon Sep 17 00:00:00 2001
From: William Moses <gh at wsmoses.com>
Date: Fri, 17 Oct 2025 08:15:02 +0800
Subject: [PATCH 4/4] Update SliceAnalysis.cpp

---
 mlir/lib/Analysis/SliceAnalysis.cpp | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp
index ef7a5fac3024a..5f11286dd6a25 100644
--- a/mlir/lib/Analysis/SliceAnalysis.cpp
+++ b/mlir/lib/Analysis/SliceAnalysis.cpp
@@ -161,18 +161,25 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
       SmallPtrSet<Region *, 4> descendents;
       region.walk(
           [&](Region *childRegion) { descendents.insert(childRegion); });
-      region.walk([&](Operation *op) {
-        for (OpOperand &operand : op->getOpOperands()) {
-          if (!descendents.contains(operand.get().getParentRegion()))
-            if (!processValue(operand.get()).succeeded()) {
-              return WalkResult::interrupt();
-            }
-        }
-        return WalkResult::advance();
-      });
+      if (region
+              .walk([&](Operation *op) {
+                for (OpOperand &operand : op->getOpOperands()) {
+                  if (!descendents.contains(operand.get().getParentRegion()))
+                    if (!processValue(operand.get()).succeeded()) {
+                      return WalkResult::interrupt();
+                    }
+                }
+                return WalkResult::advance();
+              })
+              .wasInterrupted())
+        succeeded = false;
     });
   }
-  llvm::for_each(op->getOperands(), processValue);
+  llvm::for_each(op->getOperands(), [&](Value value) {
+    if (!processValue(value).succeeded()) {
+      succeeded = false;
+    }
+  });
 
   backwardSlice->insert(op);
   return success(succeeded);



More information about the Mlir-commits mailing list