20#include "llvm/Support/Debug.h"
23#define GEN_PASS_DEF_OPTREDUCTIONPASS
24#include "mlir/Reducer/Passes.h.inc"
27#define DEBUG_TYPE "mlir-reduce"
44void OptReductionPass::runOnOperation() {
45 LLVM_DEBUG(llvm::dbgs() <<
"\nOptimization Reduction pass: ");
50 ModuleOp moduleVariant =
module.clone();
54 module.emitError() << "\nfailed to parse pass pipeline";
58 std::pair<Tester::Interestingness, int> original = test.isInteresting(module);
60 module.emitError() << "\nthe original input is not interested";
66 module.getBody()->push_back(moduleVariant);
67 LogicalResult pipelineResult =
runPipeline(passManager, moduleVariant);
68 moduleVariant->remove();
70 if (failed(pipelineResult)) {
71 module.emitError() << "\nfailed to run pass pipeline";
75 std::pair<Tester::Interestingness, int> reduced =
76 test.isInteresting(moduleVariant);
79 reduced.second < original.second) {
80 module.getBody()->clear();
81 module.getBody()->getOperations().splice(
82 module.getBody()->begin(), moduleVariant.getBody()->getOperations());
83 LLVM_DEBUG(llvm::dbgs() <<
"\nSuccessful Transformed version\n\n");
85 LLVM_DEBUG(llvm::dbgs() <<
"\nUnsuccessful Transformed version\n\n");
88 moduleVariant->destroy();
90 LLVM_DEBUG(llvm::dbgs() <<
"Pass Complete\n\n");
LogicalResult runPipeline(OpPassManager &pipeline, Operation *op)
Schedule an arbitrary pass pipeline on the provided operation.
virtual void runOnOperation()=0
The polymorphic API that runs the pass over the currently held operation.
friend class OpPassManager
Allow access to 'clone'.
void signalPassFailure()
Signal that some invariant was broken when running.
This class is used to keep track of the testing environment of the tool.
::mlir::Pass::Option< std::string > testerName
::mlir::Pass::Option< std::string > optPass
::mlir::Pass::ListOption< std::string > testerArgs
Include the generated interface declarations.
LogicalResult parsePassPipeline(StringRef pipeline, OpPassManager &pm, raw_ostream &errorStream=llvm::errs())
Parse the textual representation of a pass pipeline, adding the result to 'pm' on success.