@@ -62,7 +62,8 @@ class GreedyRewriteConfig {
6262
6363 // / Only ops within the scope are added to the worklist. If no scope is
6464 // / specified, the closest enclosing region around the initial list of ops
65- // / is used as a scope.
65+ // / (or the specified region, depending on which greedy rewrite entry point
66+ // / is used) is used as a scope.
6667 Region *scope = nullptr ;
6768
6869 // / Strict mode can restrict the ops that are added to the worklist during
@@ -86,30 +87,54 @@ class GreedyRewriteConfig {
8687// ===----------------------------------------------------------------------===//
8788
8889// / Rewrite ops in the given region, which must be isolated from above, by
89- // / repeatedly applying the highest benefit patterns in a greedy work-list
90- // / driven manner.
90+ // / repeatedly applying the highest benefit patterns in a greedy worklist
91+ // / driven manner until a fixpoint is reached .
9192// /
92- // / This variant may stop after a predefined number of iterations, see the
93- // / alternative below to provide a specific number of iterations before stopping
94- // / in absence of convergence.
93+ // / The greedy rewrite may prematurely stop after a maximum number of
94+ // / iterations, which can be configured in the configuration parameter.
9595// /
96- // / Return success if the iterative process converged and no more patterns can
97- // / be matched in the result operation regions. `changed` is set to true if the
98- // / IR was modified at all.
96+ // / Also performs folding and simple dead-code elimination before attempting to
97+ // / match any of the provided patterns.
9998// /
100- // / Note: This does not apply patterns to the top-level operation itself.
101- // / These methods also perform folding and simple dead-code elimination
102- // / before attempting to match any of the provided patterns.
99+ // / A region scope can be set in the configuration parameter. By default, the
100+ // / scope is set to the specified region. Only in-scope ops are added to the
101+ // / worklist and only in-scope ops are allowed to be modified by the patterns.
103102// /
104- // / You may configure several aspects of this with GreedyRewriteConfig.
103+ // / Returns "success" if the iterative process converged (i.e., fixpoint was
104+ // / reached) and no more patterns can be matched within the region. `changed`
105+ // / is set to "true" if the IR was modified at all.
106+ // /
107+ // / Note: This method does not apply patterns to the region's parent operation.
105108LogicalResult
106109applyPatternsAndFoldGreedily (Region ®ion,
107110 const FrozenRewritePatternSet &patterns,
108111 GreedyRewriteConfig config = GreedyRewriteConfig(),
109112 bool *changed = nullptr );
110113
111- // / Rewrite ops in all regions of the given op, which must be isolated from
112- // / above.
114+ // / Rewrite ops nested under the given operation, which must be isolated from
115+ // / above, by repeatedly applying the highest benefit patterns in a greedy
116+ // / worklist driven manner until a fixpoint is reached.
117+ // /
118+ // / The greedy rewrite may prematurely stop after a maximum number of
119+ // / iterations, which can be configured in the configuration parameter.
120+ // /
121+ // / Also performs folding and simple dead-code elimination before attempting to
122+ // / match any of the provided patterns.
123+ // /
124+ // / This overload runs a separate greedy rewrite for each region of the
125+ // / specified op. A region scope can be set in the configuration parameter. By
126+ // / default, the scope is set to the region of the current greedy rewrite. Only
127+ // / in-scope ops are added to the worklist and only in-scope ops and the
128+ // / specified op itself are allowed to be modified by the patterns.
129+ // /
130+ // / Note: The specified op may be modified, but it may not be removed by the
131+ // / patterns.
132+ // /
133+ // / Returns "success" if the iterative process converged (i.e., fixpoint was
134+ // / reached) and no more patterns can be matched within the region. `changed`
135+ // / is set to "true" if the IR was modified at all.
136+ // /
137+ // / Note: This method does not apply patterns to the given operation itself.
113138inline LogicalResult
114139applyPatternsAndFoldGreedily (Operation *op,
115140 const FrozenRewritePatternSet &patterns,
@@ -129,27 +154,34 @@ applyPatternsAndFoldGreedily(Operation *op,
129154 return failure (failed);
130155}
131156
132- // / Applies the specified rewrite patterns on `ops` while also trying to fold
133- // / these ops.
157+ // / Rewrite the specified ops by repeatedly applying the highest benefit
158+ // / patterns in a greedy worklist driven manner until a fixpoint is reached.
159+ // /
160+ // / The greedy rewrite may prematurely stop after a maximum number of
161+ // / iterations, which can be configured in the configuration parameter.
162+ // /
163+ // / Also performs folding and simple dead-code elimination before attempting to
164+ // / match any of the provided patterns.
134165// /
135166// / Newly created ops and other pre-existing ops that use results of rewritten
136- // / ops or supply operands to such ops are simplified , unless such ops are
167+ // / ops or supply operands to such ops are also processed , unless such ops are
137168// / excluded via `config.strictMode`. Any other ops remain unmodified (i.e.,
138169// / regardless of `strictMode`).
139170// /
140171// / In addition to strictness, a region scope can be specified. Only ops within
141172// / the scope are simplified. This is similar to `applyPatternsAndFoldGreedily`,
142- // / where only ops within the given regions are simplified. If no scope is
143- // / specified, it is assumed to be the first common enclosing region of the
144- // / given ops.
173+ // / where only ops within the given region/op are simplified by default . If no
174+ // / scope is specified, it is assumed to be the first common enclosing region of
175+ // / the given ops.
145176// /
146177// / Note that ops in `ops` could be erased as result of folding, becoming dead,
147178// / or via pattern rewrites. If more far reaching simplification is desired,
148- // / applyPatternsAndFoldGreedily should be used.
179+ // / ` applyPatternsAndFoldGreedily` should be used.
149180// /
150- // / Returns success if the iterative process converged and no more patterns can
151- // / be matched. `changed` is set to true if the IR was modified at all.
152- // / `allOpsErased` is set to true if all ops in `ops` were erased.
181+ // / Returns "success" if the iterative process converged (i.e., fixpoint was
182+ // / reached) and no more patterns can be matched. `changed` is set to "true" if
183+ // / the IR was modified at all. `allOpsErased` is set to "true" if all ops in
184+ // / `ops` were erased.
153185LogicalResult
154186applyOpPatternsAndFold (ArrayRef<Operation *> ops,
155187 const FrozenRewritePatternSet &patterns,
0 commit comments