13 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHERS_SLICEMATCHERS_H
14 #define MLIR_TOOLS_MLIRQUERY_MATCHERS_SLICEMATCHERS_H
41 template <
typename Matcher>
45 bool omitBlockArguments,
bool omitUsesFromAbove)
46 : innerMatcher(std::move(innerMatcher)), maxDepth(maxDepth),
47 inclusive(inclusive), omitBlockArguments(omitBlockArguments),
48 omitUsesFromAbove(omitUsesFromAbove) {}
53 options.omitUsesFromAbove = omitUsesFromAbove;
54 options.omitBlockArguments = omitBlockArguments;
55 return (innerMatcher.match(rootOp) &&
56 matches(rootOp, backwardSlice,
options, maxDepth));
74 bool omitBlockArguments;
75 bool omitUsesFromAbove;
78 template <
typename Matcher>
79 bool BackwardSliceMatcher<Matcher>::matches(
82 backwardSlice.clear();
89 if (!opDepths.contains(subOp))
92 for (
auto operand : subOp->getOperands()) {
93 int64_t newDepth = opDepths[subOp] + 1;
96 if (newDepth > maxDepth)
99 if (
auto definingOp = operand.getDefiningOp()) {
101 if (!opDepths.contains(definingOp) || newDepth < opDepths[definingOp])
102 opDepths[definingOp] = newDepth;
104 auto blockArgument = cast<BlockArgument>(operand);
109 if (!opDepths.contains(parentOp) || newDepth < opDepths[parentOp])
110 opDepths[parentOp] = newDepth;
116 return options.inclusive ? backwardSlice.size() > 1
117 : backwardSlice.size() >= 1;
121 template <
typename Matcher>
122 inline BackwardSliceMatcher<Matcher>
124 bool omitBlockArguments,
bool omitUsesFromAbove) {
125 assert(maxDepth >= 0 &&
"maxDepth must be non-negative");
127 inclusive, omitBlockArguments,
132 template <
typename Matcher>
135 assert(maxDepth >= 0 &&
"maxDepth must be non-negative");
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)
A matcher encapsulating getBackwardSlice method from SliceAnalysis.h.
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.
void getBackwardSlice(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options={})
Fills backwardSlice with the computed backward slice (i.e.