File tree Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -92,14 +92,13 @@ class GreedyRewriteConfig {
92
92
// / An optional listener that should be notified about IR modifications.
93
93
RewriterBase::Listener *listener = nullptr ;
94
94
95
- // Whether this should fold while greedily rewriting.
96
- //
97
- // Note: greedy here generally refers to two forms, 1) greedily applying
98
- // patterns based purely on benefit and applying without backtracking using
99
- // default cost model, 2) greedily folding where possible while attempting to
100
- // match and rewrite using the provided patterns. With this option set to
101
- // false it only does the former.
95
+ // / Whether this should fold while greedily rewriting. This also disables
96
+ // / CSE'ing constants.
102
97
bool fold = true ;
98
+
99
+ // / If set to "true", constants are CSE'd (even across multiple regions that
100
+ // / are in a parent-ancestor relationship).
101
+ bool cseConstants = true ;
103
102
};
104
103
105
104
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -840,11 +840,6 @@ LogicalResult RegionPatternRewriteDriver::simplify(bool *changed) && {
840
840
// regions to enable more aggressive CSE'ing).
841
841
OperationFolder folder (ctx, this );
842
842
auto insertKnownConstant = [&](Operation *op) {
843
- // This hoisting is to enable more folding, so skip checking if known
844
- // constant, updating dense map etc if not doing folding.
845
- if (!config.fold )
846
- return false ;
847
-
848
843
// Check for existing constants when populating the worklist. This avoids
849
844
// accidentally reversing the constant order during processing.
850
845
Attribute constValue;
@@ -857,13 +852,13 @@ LogicalResult RegionPatternRewriteDriver::simplify(bool *changed) && {
857
852
if (!config.useTopDownTraversal ) {
858
853
// Add operations to the worklist in postorder.
859
854
region.walk ([&](Operation *op) {
860
- if (!insertKnownConstant (op))
855
+ if (!config. cseConstants || ! insertKnownConstant (op))
861
856
addToWorklist (op);
862
857
});
863
858
} else {
864
859
// Add all nested operations to the worklist in preorder.
865
860
region.walk <WalkOrder::PreOrder>([&](Operation *op) {
866
- if (!insertKnownConstant (op)) {
861
+ if (!config. cseConstants || ! insertKnownConstant (op)) {
867
862
addToWorklist (op);
868
863
return WalkResult::advance ();
869
864
}
You can’t perform that action at this time.
0 commit comments