@@ -49,33 +49,55 @@ class GreedyRewriteConfig {
49
49
// / larger patterns when given an ambiguous pattern set.
50
50
// /
51
51
// / 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
+ }
53
57
54
58
// / Perform control flow optimizations to the region tree after applying all
55
59
// / patterns.
56
60
// /
57
61
// / 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
+ }
60
70
61
71
// / This specifies the maximum number of times the rewriter will iterate
62
72
// / between applying patterns and simplifying regions. Use `kNoLimit` to
63
73
// / disable this iteration limit.
64
74
// /
65
75
// / 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
+ }
67
81
68
82
// / This specifies the maximum number of rewrites within an iteration. Use
69
83
// / `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
+ }
71
89
72
90
static constexpr int64_t kNoLimit = -1 ;
73
91
74
92
// / Only ops within the scope are added to the worklist. If no scope is
75
93
// / specified, the closest enclosing region around the initial list of ops
76
94
// / (or the specified region, depending on which greedy rewrite entry point
77
95
// / 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
+ }
79
101
80
102
// / Strict mode can restrict the ops that are added to the worklist during
81
103
// / the rewrite.
@@ -87,16 +109,44 @@ class GreedyRewriteConfig {
87
109
// / * GreedyRewriteStrictness::ExistingOps: Only pre-existing ops (that were
88
110
// / were on the worklist at the very beginning) enqueued. All other ops are
89
111
// / excluded.
90
- GreedyRewriteStrictness strictMode = GreedyRewriteStrictness::AnyOp;
112
+ GreedyRewriteStrictness getStrictness () const { return strictness; }
113
+ GreedyRewriteConfig &setStrictness (GreedyRewriteStrictness mode) {
114
+ strictness = mode;
115
+ return *this ;
116
+ }
91
117
92
118
// / 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
+ }
94
124
95
125
// / 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
+ }
97
131
98
132
// / If set to "true", constants are CSE'd (even across multiple regions that
99
133
// / 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 ;
100
150
bool cseConstants = true ;
101
151
};
102
152
@@ -128,14 +178,14 @@ applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns,
128
178
GreedyRewriteConfig config = GreedyRewriteConfig(),
129
179
bool *changed = nullptr );
130
180
// / 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 .
132
182
LLVM_DEPRECATED (" Use applyPatternsGreedily() instead" , " applyPatternsGreedily" )
133
183
inline LogicalResult
134
184
applyPatternsAndFoldGreedily (Region ®ion,
135
185
const FrozenRewritePatternSet &patterns,
136
186
GreedyRewriteConfig config = GreedyRewriteConfig(),
137
187
bool *changed = nullptr ) {
138
- config.fold = true ;
188
+ config.enableFolding () ;
139
189
return applyPatternsGreedily (region, patterns, config, changed);
140
190
}
141
191
@@ -187,7 +237,7 @@ applyPatternsAndFoldGreedily(Operation *op,
187
237
const FrozenRewritePatternSet &patterns,
188
238
GreedyRewriteConfig config = GreedyRewriteConfig(),
189
239
bool *changed = nullptr ) {
190
- config.fold = true ;
240
+ config.enableFolding () ;
191
241
return applyPatternsGreedily (op, patterns, config, changed);
192
242
}
193
243
@@ -233,7 +283,7 @@ applyOpPatternsAndFold(ArrayRef<Operation *> ops,
233
283
const FrozenRewritePatternSet &patterns,
234
284
GreedyRewriteConfig config = GreedyRewriteConfig(),
235
285
bool *changed = nullptr , bool *allErased = nullptr ) {
236
- config.fold = true ;
286
+ config.enableFolding () ;
237
287
return applyOpPatternsGreedily (ops, patterns, config, changed, allErased);
238
288
}
239
289
0 commit comments