@@ -49,33 +49,55 @@ class GreedyRewriteConfig {
4949 // / larger patterns when given an ambiguous pattern set.
5050 // /
5151 // / Note: Only applicable when simplifying entire regions.
52- bool useTopDownTraversal = false ;
52+ bool getUseTopDownTraversal () const { return useTopDownTraversal; }
53+ GreedyRewriteConfig &setUseTopDownTraversal (bool use = true ) {
54+ useTopDownTraversal = use;
55+ return *this ;
56+ }
5357
5458 // / Perform control flow optimizations to the region tree after applying all
5559 // / patterns.
5660 // /
5761 // / Note: Only applicable when simplifying entire regions.
58- GreedySimplifyRegionLevel enableRegionSimplification =
59- GreedySimplifyRegionLevel::Aggressive;
62+ GreedySimplifyRegionLevel getRegionSimplificationLevel () const {
63+ return regionSimplificationLevel;
64+ }
65+ GreedyRewriteConfig &
66+ setRegionSimplificationLevel (GreedySimplifyRegionLevel level) {
67+ regionSimplificationLevel = level;
68+ return *this ;
69+ }
6070
6171 // / This specifies the maximum number of times the rewriter will iterate
6272 // / between applying patterns and simplifying regions. Use `kNoLimit` to
6373 // / disable this iteration limit.
6474 // /
6575 // / Note: Only applicable when simplifying entire regions.
66- int64_t maxIterations = 10 ;
76+ int64_t getMaxIterations () const { return maxIterations; }
77+ GreedyRewriteConfig &setMaxIterations (int64_t iterations) {
78+ maxIterations = iterations;
79+ return *this ;
80+ }
6781
6882 // / This specifies the maximum number of rewrites within an iteration. Use
6983 // / `kNoLimit` to disable this limit.
70- int64_t maxNumRewrites = kNoLimit ;
84+ int64_t getMaxNumRewrites () const { return maxNumRewrites; }
85+ GreedyRewriteConfig &setMaxNumRewrites (int64_t limit) {
86+ maxNumRewrites = limit;
87+ return *this ;
88+ }
7189
7290 static constexpr int64_t kNoLimit = -1 ;
7391
7492 // / Only ops within the scope are added to the worklist. If no scope is
7593 // / specified, the closest enclosing region around the initial list of ops
7694 // / (or the specified region, depending on which greedy rewrite entry point
7795 // / is used) is used as a scope.
78- Region *scope = nullptr ;
96+ Region *getScope () const { return scope; }
97+ GreedyRewriteConfig &setScope (Region *scope) {
98+ this ->scope = scope;
99+ return *this ;
100+ }
79101
80102 // / Strict mode can restrict the ops that are added to the worklist during
81103 // / the rewrite.
@@ -87,16 +109,44 @@ class GreedyRewriteConfig {
87109 // / * GreedyRewriteStrictness::ExistingOps: Only pre-existing ops (that were
88110 // / were on the worklist at the very beginning) enqueued. All other ops are
89111 // / excluded.
90- GreedyRewriteStrictness strictMode = GreedyRewriteStrictness::AnyOp;
112+ GreedyRewriteStrictness getStrictness () const { return strictness; }
113+ GreedyRewriteConfig &setStrictness (GreedyRewriteStrictness mode) {
114+ strictness = mode;
115+ return *this ;
116+ }
91117
92118 // / An optional listener that should be notified about IR modifications.
93- RewriterBase::Listener *listener = nullptr ;
119+ RewriterBase::Listener *getListener () const { return listener; }
120+ GreedyRewriteConfig &setListener (RewriterBase::Listener *listener) {
121+ this ->listener = listener;
122+ return *this ;
123+ }
94124
95125 // / Whether this should fold while greedily rewriting.
96- bool fold = true ;
126+ bool isFoldingEnabled () const { return fold; }
127+ GreedyRewriteConfig &enableFolding (bool enable = true ) {
128+ fold = enable;
129+ return *this ;
130+ }
97131
98132 // / If set to "true", constants are CSE'd (even across multiple regions that
99133 // / are in a parent-ancestor relationship).
134+ bool isConstantCSEEnabled () const { return cseConstants; }
135+ GreedyRewriteConfig &enableConstantCSE (bool enable = true ) {
136+ cseConstants = enable;
137+ return *this ;
138+ }
139+
140+ private:
141+ Region *scope = nullptr ;
142+ bool useTopDownTraversal = false ;
143+ GreedySimplifyRegionLevel regionSimplificationLevel =
144+ GreedySimplifyRegionLevel::Aggressive;
145+ int64_t maxIterations = 10 ;
146+ int64_t maxNumRewrites = kNoLimit ;
147+ GreedyRewriteStrictness strictness = GreedyRewriteStrictness::AnyOp;
148+ RewriterBase::Listener *listener = nullptr ;
149+ bool fold = true ;
100150 bool cseConstants = true ;
101151};
102152
@@ -128,14 +178,14 @@ applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns,
128178 GreedyRewriteConfig config = GreedyRewriteConfig(),
129179 bool *changed = nullptr );
130180// / Same as `applyPatternsAndGreedily` above with folding.
131- // / FIXME: Remove this once transition to above is complieted .
181+ // / FIXME: Remove this once transition to above is completed .
132182LLVM_DEPRECATED (" Use applyPatternsGreedily() instead" , " applyPatternsGreedily" )
133183inline LogicalResult
134184applyPatternsAndFoldGreedily (Region ®ion,
135185 const FrozenRewritePatternSet &patterns,
136186 GreedyRewriteConfig config = GreedyRewriteConfig(),
137187 bool *changed = nullptr ) {
138- config.fold = true ;
188+ config.enableFolding () ;
139189 return applyPatternsGreedily (region, patterns, config, changed);
140190}
141191
@@ -187,7 +237,7 @@ applyPatternsAndFoldGreedily(Operation *op,
187237 const FrozenRewritePatternSet &patterns,
188238 GreedyRewriteConfig config = GreedyRewriteConfig(),
189239 bool *changed = nullptr ) {
190- config.fold = true ;
240+ config.enableFolding () ;
191241 return applyPatternsGreedily (op, patterns, config, changed);
192242}
193243
@@ -233,7 +283,7 @@ applyOpPatternsAndFold(ArrayRef<Operation *> ops,
233283 const FrozenRewritePatternSet &patterns,
234284 GreedyRewriteConfig config = GreedyRewriteConfig(),
235285 bool *changed = nullptr , bool *allErased = nullptr ) {
236- config.fold = true ;
286+ config.enableFolding () ;
237287 return applyOpPatternsGreedily (ops, patterns, config, changed, allErased);
238288}
239289
0 commit comments