Replace references to enumerate results with either result_pairs (reference wrapper type) or structured bindings. I did not use structured bindings everywhere as it wasn't clear to me it would improve readability. This is in preparation to the switch to zip semantics which won't support non-const lvalue reference to elements: https://reviews.llvm.org/D144503. I chose to use values instead of const lvalue-refs because MLIR is biased towards avoiding `const` local variables. This won't degrade performance because currently `result_pair` is cheap to copy (size_t + iterator), and in the future, the enumerator iterator dereference will return temporaries anyway. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D146006
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
//===- 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 "mlir/Transforms/Passes.h"
|
|
|
|
#include "mlir/IR/RegionKindInterface.h"
|
|
#include "mlir/Transforms/TopologicalSortUtils.h"
|
|
|
|
namespace mlir {
|
|
#define GEN_PASS_DEF_TOPOLOGICALSORT
|
|
#include "mlir/Transforms/Passes.h.inc"
|
|
} // namespace mlir
|
|
|
|
using namespace mlir;
|
|
|
|
namespace {
|
|
struct TopologicalSortPass
|
|
: public impl::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>();
|
|
}
|