Files
clang-p2996/mlir/test/lib/Analysis/TestSlice.cpp
River Riddle 4157455425 [mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>
The only benefit of FunctionPass is that it filters out function
declarations. This isn't enough to justify carrying it around, as we can
simplify filter out declarations when necessary within the pass. We can
also explore with better scheduling primitives to filter out declarations
at the pipeline level in the future.

The definition of FunctionPass is left intact for now to allow time for downstream
users to migrate.

Differential Revision: https://reviews.llvm.org/D117182
2022-01-18 19:52:44 -08:00

51 lines
1.5 KiB
C++

//===------------- TestSlice.cpp - Test slice related analisis ------------===//
//
// 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/Analysis/SliceAnalysis.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
static const StringLiteral kOrderMarker = "__test_sort_original_idx__";
namespace {
struct TestTopologicalSortPass
: public PassWrapper<TestTopologicalSortPass, OperationPass<FuncOp>> {
StringRef getArgument() const final { return "test-print-topological-sort"; }
StringRef getDescription() const final {
return "Print operations in topological order";
}
void runOnOperation() override {
std::map<int, Operation *> ops;
getOperation().walk([&ops](Operation *op) {
if (auto originalOrderAttr = op->getAttrOfType<IntegerAttr>(kOrderMarker))
ops[originalOrderAttr.getInt()] = op;
});
SetVector<Operation *> sortedOp;
for (auto op : ops)
sortedOp.insert(op.second);
sortedOp = topologicalSort(sortedOp);
llvm::errs() << "Testing : " << getOperation().getName() << "\n";
for (Operation *op : sortedOp) {
op->print(llvm::errs());
llvm::errs() << "\n";
}
}
};
} // namespace
namespace mlir {
namespace test {
void registerTestSliceAnalysisPass() {
PassRegistration<TestTopologicalSortPass>();
}
} // namespace test
} // namespace mlir