Skip to content

Commit

Permalink
[xls][mlir] Sort spawns regions topologically after OptimizeSpawns fi…
Browse files Browse the repository at this point in the history
…nishes

We apply patterns that modify two regions, the next and spawns regions. The edits
to the next region always obey dominance rules, but the changes to the spawns regions
are not guaranteed to (we don't have a perfect place to insert our new spawn instruction).

Rather than trying to guarantee it which may be hard, simply sort the spawns regions after
the optimization runs.

PiperOrigin-RevId: 701078946
  • Loading branch information
James Molloy authored and copybara-github committed Nov 28, 2024
1 parent a18db61 commit 90d1a07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions xls/contrib/mlir/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ cc_library(
deps = [
":mlir_xls",
":xls_transforms_passes_inc_gen",
"@llvm-project//mlir:Analysis",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
Expand Down
5 changes: 5 additions & 0 deletions xls/contrib/mlir/transforms/optimize_spawns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdint>
#include <utility>

#include "mlir/include/mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/include/mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/include/mlir/IR/PatternMatch.h"
#include "mlir/include/mlir/IR/Value.h"
Expand Down Expand Up @@ -115,6 +116,10 @@ class OptimizeSpawnsPass
std::move(patterns)))) {
signalPassFailure();
}

// Ensure that all spawns regions are topologically sorted; given the order
// in which the pattern is applied, this is not currently guaranteed.
sortTopologically(&getOperation().getSpawns().front());
}
};

Expand Down

0 comments on commit 90d1a07

Please sign in to comment.