1 //===- TopologicalSort.cpp - Topological sort pass ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PassDetail.h"
10 #include "mlir/IR/RegionKindInterface.h"
11 #include "mlir/Transforms/TopologicalSortUtils.h"
12 
13 using namespace mlir;
14 
15 namespace {
16 struct TopologicalSortPass : public TopologicalSortBase<TopologicalSortPass> {
runOnOperation__anonb4aac55c0111::TopologicalSortPass17   void runOnOperation() override {
18     // Topologically sort the regions of the operation without SSA dominance.
19     getOperation()->walk([](RegionKindInterface op) {
20       for (auto &it : llvm::enumerate(op->getRegions())) {
21         if (op.hasSSADominance(it.index()))
22           continue;
23         for (Block &block : it.value())
24           sortTopologically(&block);
25       }
26     });
27   }
28 };
29 } // end anonymous namespace
30 
createTopologicalSortPass()31 std::unique_ptr<Pass> mlir::createTopologicalSortPass() {
32   return std::make_unique<TopologicalSortPass>();
33 }
34