MLIR  16.0.0git
TopologicalSort.cpp
Go to the documentation of this file.
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"
12 
13 using namespace mlir;
14 
15 namespace {
16 struct TopologicalSortPass : public TopologicalSortBase<TopologicalSortPass> {
17  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 
31 std::unique_ptr<Pass> mlir::createTopologicalSortPass() {
32  return std::make_unique<TopologicalSortPass>();
33 }
Include the generated interface declarations.
Block represents an ordered list of Operations.
Definition: Block.h:29
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Definition: Matchers.h:233
std::unique_ptr< Pass > createTopologicalSortPass()
Creates a pass that recursively sorts nested regions without SSA dominance topologically such that...
bool sortTopologically(Block *block, iterator_range< Block::iterator > ops, function_ref< bool(Value, Operation *)> isOperandReady=nullptr)
Given a block, sort a range operations in said block in topological order.