#include "mlir/Transforms/Passes.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/IR/RegionKindInterface.h"
namespace mlir {
#define GEN_PASS_DEF_TOPOLOGICALSORT
#include "mlir/Transforms/Passes.h.inc"
}
using namespace mlir;
namespace {
struct TopologicalSortPass
: public impl::TopologicalSortBase<TopologicalSortPass> {
void runOnOperation() override {
getOperation()->walk([](RegionKindInterface op) {
for (auto it : llvm::enumerate(op->getRegions())) {
if (op.hasSSADominance(it.index()))
continue;
for (Block &block : it.value())
sortTopologically(&block);
}
});
}
};
}
std::unique_ptr<Pass> mlir::createTopologicalSortPass() {
return std::make_unique<TopologicalSortPass>();
}