14 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHERS_SLICEMATCHERS_H
15 #define MLIR_TOOLS_MLIRQUERY_MATCHERS_SLICEMATCHERS_H
42 template <
typename Matcher>
46 bool omitBlockArguments,
bool omitUsesFromAbove)
47 : innerMatcher(std::move(innerMatcher)), maxDepth(maxDepth),
48 inclusive(inclusive), omitBlockArguments(omitBlockArguments),
49 omitUsesFromAbove(omitUsesFromAbove) {}
54 options.omitUsesFromAbove = omitUsesFromAbove;
55 options.omitBlockArguments = omitBlockArguments;
56 return (innerMatcher.match(rootOp) &&
57 matches(rootOp, backwardSlice,
options, maxDepth));
75 bool omitBlockArguments;
76 bool omitUsesFromAbove;
79 template <
typename Matcher>
80 bool BackwardSliceMatcher<Matcher>::matches(
83 backwardSlice.clear();
90 if (!opDepths.contains(subOp))
93 for (
auto operand : subOp->getOperands()) {
94 int64_t newDepth = opDepths[subOp] + 1;
97 if (newDepth > maxDepth)
100 if (
auto definingOp = operand.getDefiningOp()) {
102 if (!opDepths.contains(definingOp) || newDepth < opDepths[definingOp])
103 opDepths[definingOp] = newDepth;
105 auto blockArgument = cast<BlockArgument>(operand);
110 if (!opDepths.contains(parentOp) || newDepth < opDepths[parentOp])
111 opDepths[parentOp] = newDepth;
117 assert(result.succeeded() &&
"expected backward slice to succeed");
119 return options.inclusive ? backwardSlice.size() > 1
120 : backwardSlice.size() >= 1;
125 template <
typename BaseMatcher,
typename Filter>
129 bool inclusive,
bool omitBlockArguments,
130 bool omitUsesFromAbove)
131 : innerMatcher(std::move(innerMatcher)),
132 filterMatcher(std::move(filterMatcher)), inclusive(inclusive),
133 omitBlockArguments(omitBlockArguments),
134 omitUsesFromAbove(omitUsesFromAbove) {}
137 backwardSlice.clear();
140 options.omitUsesFromAbove = omitUsesFromAbove;
141 options.omitBlockArguments = omitBlockArguments;
142 if (innerMatcher.match(rootOp)) {
144 return !filterMatcher.match(subOp);
147 assert(result.succeeded() &&
"expected backward slice to succeed");
149 return options.inclusive ? backwardSlice.size() > 1
150 : backwardSlice.size() >= 1;
156 BaseMatcher innerMatcher;
157 Filter filterMatcher;
159 bool omitBlockArguments;
160 bool omitUsesFromAbove;
165 template <
typename BaseMatcher,
typename Filter>
170 : innerMatcher(std::move(innerMatcher)),
171 filterMatcher(std::move(filterMatcher)), inclusive(inclusive) {}
174 forwardSlice.clear();
177 if (innerMatcher.match(rootOp)) {
179 return !filterMatcher.match(subOp);
182 return options.inclusive ? forwardSlice.size() > 1
183 : forwardSlice.size() >= 1;
189 BaseMatcher innerMatcher;
190 Filter filterMatcher;
195 template <
typename Matcher>
196 inline BackwardSliceMatcher<Matcher>
198 bool omitBlockArguments,
bool omitUsesFromAbove) {
199 assert(maxDepth >= 0 &&
"maxDepth must be non-negative");
201 inclusive, omitBlockArguments,
206 template <
typename Matcher>
209 assert(maxDepth >= 0 &&
"maxDepth must be non-negative");
216 template <
typename BaseMatcher,
typename Filter>
217 inline PredicateBackwardSliceMatcher<BaseMatcher, Filter>
219 bool inclusive,
bool omitBlockArguments,
220 bool omitUsesFromAbove) {
222 std::move(innerMatcher), std::move(filterMatcher), inclusive,
223 omitBlockArguments, omitUsesFromAbove);
228 template <
typename BaseMatcher,
typename Filter>
229 inline PredicateForwardSliceMatcher<BaseMatcher, Filter>
233 std::move(innerMatcher), std::move(filterMatcher), inclusive);
static llvm::ManagedStatic< PassManagerOptions > options
Operation is the basic unit of execution within MLIR.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
BackwardSliceMatcher(Matcher innerMatcher, int64_t maxDepth, bool inclusive, bool omitBlockArguments, bool omitUsesFromAbove)
bool match(Operation *rootOp, SetVector< Operation * > &backwardSlice)
Computes the backward-slice of all transitive defs reachable from rootOp, if innerMatcher matches.
PredicateBackwardSliceMatcher(BaseMatcher innerMatcher, Filter filterMatcher, bool inclusive, bool omitBlockArguments, bool omitUsesFromAbove)
bool match(Operation *rootOp, SetVector< Operation * > &backwardSlice)
Computes the forward-slice of all users reachable from rootOp, if innerMatcher matches.
PredicateForwardSliceMatcher(BaseMatcher innerMatcher, Filter filterMatcher, bool inclusive)
bool match(Operation *rootOp, SetVector< Operation * > &forwardSlice)
Computes the backward-slice of all transitive defs reachable from rootOp, if innerMatcher matches.
PredicateForwardSliceMatcher< BaseMatcher, Filter > m_GetUsersByPredicate(BaseMatcher innerMatcher, Filter filterMatcher, bool inclusive)
Matches all users of a top-level operation and stops where filterMatcher rejects.
PredicateBackwardSliceMatcher< BaseMatcher, Filter > m_GetDefinitionsByPredicate(BaseMatcher innerMatcher, Filter filterMatcher, bool inclusive, bool omitBlockArguments, bool omitUsesFromAbove)
Matches all transitive defs of a top-level operation and stops where filterMatcher rejects.
BackwardSliceMatcher< Matcher > m_GetAllDefinitions(Matcher innerMatcher, int64_t maxDepth)
Matches all transitive defs of a top-level operation up to N levels.
BackwardSliceMatcher< Matcher > m_GetDefinitions(Matcher innerMatcher, int64_t maxDepth, bool inclusive, bool omitBlockArguments, bool omitUsesFromAbove)
Matches transitive defs of a top-level operation up to N levels.
LogicalResult getBackwardSlice(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options={})
Fills backwardSlice with the computed backward slice (i.e.
void getForwardSlice(Operation *op, SetVector< Operation * > *forwardSlice, const ForwardSliceOptions &options={})
Fills forwardSlice with the computed forward slice (i.e.