[Mlir-commits] [mlir] [mlir] MLIR-QUERY slice-matchers implementation (PR #115670)
Jacques Pienaar
llvmlistbot at llvm.org
Mon Apr 21 08:28:05 PDT 2025
================
@@ -363,8 +364,72 @@ struct RecursivePatternMatcher {
std::tuple<OperandMatchers...> operandMatchers;
};
+/// A matcher encapsulating the initial `getBackwardSlice` method from
+/// SliceAnalysis.h
+/// Additionally, it limits the slice computation to a certain depth level using
+/// a custom filter
+///
+/// Example starting from node 9, assuming the matcher
+/// computes the slice for the first two depth levels
+/// ============================
+/// 1 2 3 4
+/// |_______| |______|
+/// | | |
+/// | 5 6
+/// |___|_____________|
+/// | |
+/// 7 8
+/// |_______________|
+/// |
+/// 9
+///
+/// Assuming all local orders match the numbering order:
+/// {5, 7, 6, 8, 9}
+class BackwardSliceMatcher {
+public:
+ BackwardSliceMatcher(query::matcher::DynMatcher &&innerMatcher,
+ int64_t maxDepth)
+ : innerMatcher(std::move(innerMatcher)), maxDepth(maxDepth) {}
+ bool match(Operation *op, SetVector<Operation *> &backwardSlice,
+ query::QueryOptions &options) {
+
+ if (innerMatcher.match(op) &&
----------------
jpienaar wrote:
Just do
return innerMatcher.match(op) && matches(op, backwardSlice, options, maxDepth);
https://github.com/llvm/llvm-project/pull/115670
More information about the Mlir-commits
mailing list