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"
33 class OptReductionPass :
public impl::OptReductionPassBase<OptReductionPass> {
38 void runOnOperation()
override;
44 void OptReductionPass::runOnOperation() {
45 LLVM_DEBUG(llvm::dbgs() <<
"\nOptimization Reduction pass: ");
47 Tester test(testerName, testerArgs);
49 ModuleOp module = this->getOperation();
50 ModuleOp moduleVariant = module.clone();
54 module.emitError() <<
"\nfailed to parse pass pipeline";
55 return signalPassFailure();
58 std::pair<Tester::Interestingness, int> original = test.isInteresting(module);
60 module.emitError() <<
"\nthe original input is not interested";
61 return signalPassFailure();
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";
72 return signalPassFailure();
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");
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.
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.