11 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
12 #include "mlir/Transforms/Passes.h"
15 using namespace circt;
25 userMap = std::make_unique<SymbolUserMap>(table, module);
27 uint64_t
match(Operation *op)
override {
28 if (op->hasTrait<OpTrait::IsTerminator>())
31 return !isa<ModuleOp>(op) &&
32 (op->getNumResults() == 0 || op->use_empty()) &&
33 userMap->useEmpty(op);
35 LogicalResult
rewrite(Operation *op)
override {
39 std::string
getName()
const override {
return "operation-pruner"; }
50 GreedyRewriteConfig config;
51 config.useTopDownTraversal =
true;
52 config.enableRegionSimplification =
false;
53 return createCanonicalizerPass(config);
static std::unique_ptr< Pass > createSimpleCanonicalizerPass()
void pruneUnusedOps(Operation *initialOp, Reduction &reduction)
Starting at the given op, traverse through it and its operands and erase operations that have no more...
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
void populateGenericReducePatterns(MLIRContext *context, ReducePatternSet &patterns)
Populate reduction patterns that are not specific to certain operations or dialects.
A sample reduction pattern that removes operations which either produce no results or their results h...
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.
std::unique_ptr< SymbolUserMap > userMap
void beforeReduction(mlir::ModuleOp module) override
Called before the reduction is applied to a new subset of operations.
std::string getName() const override
Return a human-readable name for this reduction pattern.
SymbolTableCollection table
A reduction pattern that applies an mlir::Pass.
An abstract reduction pattern.