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