[Mlir-commits] [mlir] Extend `getBackwardSlice` to track values captured from above (PR #113478)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 23 10:47:06 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Ian Wood (IanWood1)
<details>
<summary>Changes</summary>
This change modifies `getBackwardSlice` to track values captures by the regions of each operation that it traverses. Ignoring values captured from a parent region may lead to an incomplete program slice. However, there seems to be logic that depends on not traversing captured values, so this change preserves the default behavior by hiding this logic behind the `omitUsesFromAbove` flag.
I'm looking for feedback on how to add this functionality (which I think should be default) without breaking users of `getBackwardSlice`
---
Full diff: https://github.com/llvm/llvm-project/pull/113478.diff
2 Files Affected:
- (modified) mlir/include/mlir/Analysis/SliceAnalysis.h (+5)
- (modified) mlir/lib/Analysis/SliceAnalysis.cpp (+14)
``````````diff
diff --git a/mlir/include/mlir/Analysis/SliceAnalysis.h b/mlir/include/mlir/Analysis/SliceAnalysis.h
index 99279fdfe427c8..a4f5d937cd51da 100644
--- a/mlir/include/mlir/Analysis/SliceAnalysis.h
+++ b/mlir/include/mlir/Analysis/SliceAnalysis.h
@@ -47,6 +47,11 @@ struct BackwardSliceOptions : public SliceOptions {
/// backward slice computation traverses block arguments and asserts that the
/// parent op has a single region with a single block.
bool omitBlockArguments = false;
+
+ /// When omitUsesFromAbove is true, the backward slice computation omits
+ /// traversing values that are captured from above.
+ /// TODO: this should default to `false` after users have been updated.
+ bool omitUsesFromAbove = true;
};
using ForwardSliceOptions = SliceOptions;
diff --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp
index 2b1cf411ceeeeb..d07ae7b3ffa2c7 100644
--- a/mlir/lib/Analysis/SliceAnalysis.cpp
+++ b/mlir/lib/Analysis/SliceAnalysis.cpp
@@ -16,6 +16,7 @@
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Support/LLVM.h"
+#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -115,6 +116,19 @@ static void getBackwardSliceImpl(Operation *op,
}
}
+ // Visit values that are defined above.
+ if (!options.omitUsesFromAbove) {
+ visitUsedValuesDefinedAbove(op->getRegions(), [&](OpOperand *operand) {
+ if (Operation *definingOp = operand->get().getDefiningOp()) {
+ getBackwardSliceImpl(definingOp, backwardSlice, options);
+ return;
+ }
+ Operation *bbAargOwner =
+ cast<BlockArgument>(operand->get()).getOwner()->getParentOp();
+ getBackwardSliceImpl(bbAargOwner, backwardSlice, options);
+ });
+ }
+
backwardSlice->insert(op);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/113478
More information about the Mlir-commits
mailing list