16 #include "mlir/Transforms/Passes.h"
17 #include "llvm/Support/Debug.h"
19 #define DEBUG_TYPE "circt-reduce"
21 using namespace circt;
34 bool canIncreaseSize,
bool oneShot)
35 : context(context), canIncreaseSize(canIncreaseSize), oneShot(oneShot) {
40 pm = std::make_unique<mlir::PassManager>(
41 context,
"builtin.module", mlir::OpPassManager::Nesting::Explicit);
42 auto opName = pass->getOpName();
43 if (opName && *opName ==
"firrtl.circuit")
44 pm->nest<firrtl::CircuitOp>().addPass(std::move(pass));
45 else if (opName && *opName ==
"firrtl.module")
46 pm->nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
48 else if (opName && *opName ==
"hw.module")
51 pm->addPass(std::move(pass));
55 return op->getName() ==
pm->getOpName(*
context);
67 const std::function<
bool(
const Reduction &)> &pred) {
70 if (!pred(*iter->first))
77 [](
const auto &pairA,
const auto &pairB) {
78 return pairA.second > pairB.second;
SmallVector< std::pair< std::unique_ptr< Reduction >, unsigned > > reducePatternsWithBenefit
void filter(const std::function< bool(const Reduction &)> &pred)
Reduction & operator[](size_t idx) const
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
LogicalResult rewrite(Operation *op) override
Apply the reduction to a specific operation.
uint64_t match(Operation *op) override
Check if the reduction can apply to a specific operation.
MLIRContext *const context
std::string getName() const override
Return a human-readable name for this reduction pattern.
std::unique_ptr< mlir::PassManager > pm
PassReduction(MLIRContext *context, std::unique_ptr< Pass > pass, bool canIncreaseSize=false, bool oneShot=false)
A dialect interface to provide reduction patterns to a reducer tool.
virtual void populateReducePatterns(ReducePatternSet &patterns) const =0
void populateReducePatterns(ReducePatternSet &patterns) const
An abstract reduction pattern.