Skip to content

Commit

Permalink
Optimize greedy rewrite passes (#298)
Browse files Browse the repository at this point in the history
Optimize a number of greedy rewrite passes. 
- QUIRAngleConversionPass: Goes from about ~7.5s for 100x100 to 0.9s on
my machine
  • Loading branch information
taalexander authored Mar 15, 2024
1 parent eb2052e commit 239ea89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Dialect/QUIR/IR/QUIRInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ std::set<uint32_t>
interfaces_impl::getQubitsBetweenOperations(mlir::Operation *first,
mlir::Operation *second) {
std::set<uint32_t> operatedQubits;
if (!first->isBeforeInBlock(second))
// Don't use isBeforeInBlock if the op order is invalid as
// this is O(n) in the worst case.
if (first->getBlock()->isOpOrderValid() && !first->isBeforeInBlock(second))
return operatedQubits;

Operation *curOp = first->getNextNode();
Expand Down
3 changes: 3 additions & 0 deletions lib/Dialect/QUIR/Transforms/AngleConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void QUIRAngleConversionPass::runOnOperation() {
mlir::GreedyRewriteConfig config;
// Disable to improve performance
config.enableRegionSimplification = false;
config.strictMode = mlir::GreedyRewriteStrictness::ExistingOps;
// Each operation can only be modified once so limit
config.maxIterations = 1;

if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),
config))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
The performance of the QUIRAngleConversionPass has been improved by a factor of
~8-10x by optimizing the greedy rewrite behaviour.
- |
Parallelize control flow improves by ~8-10x due to a quadratic scaling factor
that was uncovered.

0 comments on commit 239ea89

Please sign in to comment.