Skip to content

Commit d2744aa

Browse files
authored
Disable region simplification (#197)
Region simplification is used in many places where it will not yield a tangible improvement in the IR and comes with a performance cost.
1 parent 2762408 commit d2744aa

11 files changed

+60
-13
lines changed

lib/Dialect/Pulse/Transforms/MergeDelays.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ void MergeDelayPass::runOnOperation() {
9999
RewritePatternSet patterns(&getContext());
100100
patterns.add<DelayAndDelayPattern>(&getContext());
101101

102-
if (failed(applyPatternsAndFoldGreedily(operation, std::move(patterns))))
102+
mlir::GreedyRewriteConfig config;
103+
// Disable to improve performance
104+
config.enableRegionSimplification = false;
105+
106+
if (failed(
107+
applyPatternsAndFoldGreedily(operation, std::move(patterns), config)))
103108
signalPassFailure();
104109

105110
} // runOnOperation

lib/Dialect/Pulse/Transforms/RemoveUnusedArguments.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ void RemoveUnusedArgumentsPass::runOnOperation() {
109109

110110
patterns.add<RemoveUnusedArgumentsPattern>(&getContext());
111111

112-
if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns))))
112+
mlir::GreedyRewriteConfig config;
113+
// Disable to improve performance
114+
config.enableRegionSimplification = false;
115+
116+
if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),
117+
config)))
113118
signalPassFailure();
114119
}
115120

lib/Dialect/QUIR/Transforms/AngleConversion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ void QUIRAngleConversionPass::runOnOperation() {
8484
RewritePatternSet patterns(&getContext());
8585
patterns.add<AngleConversion>(&getContext(), functionOps);
8686

87-
if (failed(
88-
applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) {
87+
mlir::GreedyRewriteConfig config;
88+
// Disable to improve performance
89+
config.enableRegionSimplification = false;
90+
91+
if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),
92+
config))) {
8993
; // TODO why would this call to applyPatternsAndFoldGreedily fail?
9094
// signalPassFailure();
9195
}

lib/Dialect/QUIR/Transforms/BreakReset.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void BreakResetPass::runOnOperation() {
115115
// use cheaper top-down traversal (in this case, bottom-up would not behave
116116
// any differently)
117117
config.useTopDownTraversal = true;
118+
// Disable to improve performance
119+
config.enableRegionSimplification = false;
118120

119121
patterns.add<BreakResetsPattern>(&getContext(), numIterations, delayCycles);
120122

lib/Dialect/QUIR/Transforms/MergeCircuits.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,12 @@ void MergeCircuitsPass::runOnOperation() {
394394
patterns.add<BarrierAndCircuitPattern>(&getContext());
395395
patterns.add<CircuitAndBarrierPattern>(&getContext());
396396

397-
if (failed(
398-
applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns))))
397+
mlir::GreedyRewriteConfig config;
398+
// Disable to improve performance
399+
config.enableRegionSimplification = false;
400+
401+
if (failed(applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns),
402+
config)))
399403
signalPassFailure();
400404
} // runOnOperation
401405

lib/Dialect/QUIR/Transforms/MergeMeasures.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ void MergeMeasuresLexographicalPass::runOnOperation() {
109109
RewritePatternSet patterns(&getContext());
110110
patterns.add<MeasureAndMeasureLexographicalPattern>(&getContext());
111111

112-
if (failed(
113-
applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns))))
112+
mlir::GreedyRewriteConfig config;
113+
// Disable to improve performance
114+
config.enableRegionSimplification = false;
115+
116+
if (failed(applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns),
117+
config)))
114118
signalPassFailure();
115119
} // runOnOperation
116120

@@ -175,8 +179,12 @@ void MergeMeasuresTopologicalPass::runOnOperation() {
175179
RewritePatternSet patterns(&getContext());
176180
patterns.add<MeasureAndMeasureTopologicalPattern>(&getContext());
177181

178-
if (failed(
179-
applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns))))
182+
mlir::GreedyRewriteConfig config;
183+
// Disable to improve performance
184+
config.enableRegionSimplification = false;
185+
186+
if (failed(applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns),
187+
config)))
180188
signalPassFailure();
181189
} // runOnOperation
182190

lib/Dialect/QUIR/Transforms/MergeParallelResets.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void MergeResetsLexicographicPass::runOnOperation() {
9595
// use cheaper top-down traversal (in this case, bottom-up would not behave
9696
// any differently)
9797
config.useTopDownTraversal = true;
98+
// Disable to improve performance
99+
config.enableRegionSimplification = false;
98100

99101
patterns.add<MergeResetsLexicographicPattern>(&getContext());
100102

@@ -203,6 +205,8 @@ void MergeResetsTopologicalPass::runOnOperation() {
203205
// use cheaper top-down traversal (in this case, bottom-up would not behave
204206
// any differently)
205207
config.useTopDownTraversal = true;
208+
// Disable to improve performance
209+
config.enableRegionSimplification = false;
206210

207211
patterns.add<MergeResetsTopologicalPattern>(&getContext());
208212

lib/Dialect/QUIR/Transforms/ReorderCircuits.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ void ReorderCircuitsPass::runOnOperation() {
8989
// only run this pass on call_circuits within the main body of the program
9090
// there may be call_circuits within circuits that have not been properly
9191
// labeled with their qubit arguments
92+
mlir::GreedyRewriteConfig config;
93+
// Disable to improve performance
94+
config.enableRegionSimplification = false;
9295

93-
if (failed(applyPatternsAndFoldGreedily(mainFunc, std::move(patterns))))
96+
if (failed(
97+
applyPatternsAndFoldGreedily(mainFunc, std::move(patterns), config)))
9498
signalPassFailure();
9599
} // runOnOperation
96100

lib/Dialect/QUIR/Transforms/ReorderMeasurements.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ void ReorderMeasurementsPass::runOnOperation() {
213213
RewritePatternSet patterns(&getContext());
214214
patterns.add<ReorderMeasureAndNonMeasurePat>(&getContext());
215215

216-
if (failed(
217-
applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns))))
216+
mlir::GreedyRewriteConfig config;
217+
// Disable to improve performance
218+
config.enableRegionSimplification = false;
219+
220+
if (failed(applyPatternsAndFoldGreedily(moduleOperation, std::move(patterns),
221+
config)))
218222
signalPassFailure();
219223
} // runOnOperation
220224

lib/Dialect/QUIR/Transforms/UnusedVariable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ void UnusedVariablePass::runOnOperation() {
8181
// use cheaper top-down traversal (in this case, bottom-up would not behave
8282
// any differently)
8383
config.useTopDownTraversal = true;
84+
// Disable to improve performance
85+
config.enableRegionSimplification = false;
86+
8487
patterns.add<UnusedVariablePat>(&getContext(), symbolUsers);
8588

8689
if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),

0 commit comments

Comments
 (0)