19 #include "llvm/Support/Debug.h"
22 #define GEN_PASS_DEF_OPTREDUCTION
23 #include "mlir/Reducer/Passes.h.inc"
26 #define DEBUG_TYPE "mlir-reduce"
32 class OptReductionPass :
public impl::OptReductionBase<OptReductionPass> {
35 void runOnOperation()
override;
41 void OptReductionPass::runOnOperation() {
42 LLVM_DEBUG(llvm::dbgs() <<
"\nOptimization Reduction pass: ");
44 Tester test(testerName, testerArgs);
46 ModuleOp module = this->getOperation();
47 ModuleOp moduleVariant = module.clone();
51 module.emitError() <<
"\nfailed to parse pass pipeline";
52 return signalPassFailure();
55 std::pair<Tester::Interestingness, int> original = test.isInteresting(module);
57 module.emitError() <<
"\nthe original input is not interested";
58 return signalPassFailure();
63 module.getBody()->push_back(moduleVariant);
64 LogicalResult pipelineResult = runPipeline(passManager, moduleVariant);
65 moduleVariant->remove();
67 if (failed(pipelineResult)) {
68 module.emitError() <<
"\nfailed to run pass pipeline";
69 return signalPassFailure();
72 std::pair<Tester::Interestingness, int> reduced =
73 test.isInteresting(moduleVariant);
76 reduced.second < original.second) {
77 module.getBody()->clear();
78 module.getBody()->getOperations().splice(
79 module.getBody()->begin(), moduleVariant.getBody()->getOperations());
80 LLVM_DEBUG(llvm::dbgs() <<
"\nSuccessful Transformed version\n\n");
82 LLVM_DEBUG(llvm::dbgs() <<
"\nUnsuccessful Transformed version\n\n");
85 moduleVariant->destroy();
87 LLVM_DEBUG(llvm::dbgs() <<
"Pass Complete\n\n");
91 return std::make_unique<OptReductionPass>();
This class represents a pass manager that runs passes on either a specific operation type,...
This class is used to keep track of the testing environment of the tool.
Include the generated interface declarations.
std::unique_ptr< Pass > createOptReductionPass()
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.