CIRCT 22.0.0git
|
An abstract reduction pattern. More...
#include <Reduction.h>
Public Member Functions | |
virtual | ~Reduction () |
virtual void | beforeReduction (mlir::ModuleOp) |
Called before the reduction is applied to a new subset of operations. | |
virtual void | afterReduction (mlir::ModuleOp) |
Called after the reduction has been applied to a subset of operations. | |
virtual uint64_t | match (Operation *op) |
Check if the reduction can apply to a specific operation. | |
virtual void | matches (Operation *op, llvm::function_ref< void(uint64_t, uint64_t)> addMatch) |
Collect all ways how this reduction can apply to a specific operation. | |
virtual LogicalResult | rewrite (Operation *op) |
Apply the reduction to a specific operation. | |
virtual LogicalResult | rewriteMatches (Operation *op, ArrayRef< uint64_t > matches) |
Apply a set of matches of this reduction to a specific operation. | |
virtual std::string | getName () const =0 |
Return a human-readable name for this reduction pattern. | |
virtual bool | acceptSizeIncrease () const |
Return true if the tool should accept the transformation this reduction performs on the module even if the overall size of the output increases. | |
virtual bool | isOneShot () const |
Return true if the tool should not try to reapply this reduction after it has been successful. | |
void | notifyOpErased (Operation *op) |
Public Attributes | |
std::function< void(Operation *)> | notifyOpErasedCallback = nullptr |
An optional callback for reductions to communicate removal of operations. | |
An abstract reduction pattern.
Definition at line 24 of file Reduction.h.
|
virtualdefault |
|
inlinevirtual |
Return true if the tool should accept the transformation this reduction performs on the module even if the overall size of the output increases.
This can be handy for patterns that reduce the complexity of the IR at the cost of some verbosity.
Reimplemented in circt::PassReduction, InstanceStubber, MemoryStubber, ConnectInvalidator, ExtmoduleInstanceRemover, EagerInliner, ModuleInternalNameSanitizer, ModuleNameSanitizer, ModuleExternalizer, HWConstantifier, ModuleInputPruner, and ModuleOutputPruner.
Definition at line 79 of file Reduction.h.
|
inlinevirtual |
Called after the reduction has been applied to a subset of operations.
Reductions may use this callback to perform post-processing of the reductions before the resulting module is tried for interestingness.
Reimplemented in FIRRTLModuleExternalizer, InstanceStubber, MemoryStubber, AnnotationRemover, ExtmoduleInstanceRemover, ConnectForwarder, DetachSubaccesses, and EagerInliner.
Definition at line 35 of file Reduction.h.
|
inlinevirtual |
Called before the reduction is applied to a new subset of operations.
Reductions may use this callback to collect information such as symbol tables about the module upfront.
Reimplemented in FIRRTLModuleExternalizer, InstanceStubber, MemoryStubber, AnnotationRemover, ExtmoduleInstanceRemover, ConnectForwarder, DetachSubaccesses, EagerInliner, ModuleNameSanitizer, ModuleExternalizer, ModuleInputPruner, and ModuleOutputPruner.
Definition at line 30 of file Reduction.h.
|
pure virtual |
Return a human-readable name for this reduction pattern.
Implemented in circt::PassReduction, StateElimination, FIRRTLModuleExternalizer, InstanceStubber, MemoryStubber, FIRRTLOperandForwarder< OpNum >, FIRRTLConstantifier, ConnectInvalidator, AnnotationRemover, RootPortPruner, ExtmoduleInstanceRemover, ConnectForwarder, ConnectSourceOperandForwarder< OpNum >, DetachSubaccesses, NodeSymbolRemover, EagerInliner, ModuleInternalNameSanitizer, ModuleNameSanitizer, ModuleExternalizer, HWOperandForwarder< OpNum >, HWConstantifier, ModuleInputPruner, and ModuleOutputPruner.
|
inlinevirtual |
Return true if the tool should not try to reapply this reduction after it has been successful.
This is useful for reductions whose match()
function keeps returning true even after the reduction has reached a fixed-point and no longer performs any change. An example of this are reductions that apply a lowering pass which always applies but may leave the input unmodified.
This is mainly useful in conjunction with returning true from acceptSizeIncrease()
. For reductions that don't accept an increase, the module size has to decrease for them to be considered useful, which prevents the tool from getting stuck at a local point where the reduction applies but produces no change in the input. However, reductions that do accept a size increase can get stuck in this local fixed-point as they keep applying to the same operations and the tool keeps accepting the unmodified input as an improvement.
Reimplemented in circt::PassReduction, ModuleInternalNameSanitizer, and ModuleNameSanitizer.
Definition at line 96 of file Reduction.h.
|
inlinevirtual |
Check if the reduction can apply to a specific operation.
Returns a benefit measure where a higher number means that applying the pattern leads to a bigger reduction and zero means that the patten does not match and thus cannot be applied at all.
Reimplemented in circt::OpReduction< OpTy >, circt::OpReduction< firrtl::CircuitOp >, circt::OpReduction< firrtl::FModuleOp >, circt::OpReduction< firrtl::InstanceOp >, circt::OpReduction< firrtl::MemOp >, circt::OpReduction< firrtl::NodeOp >, circt::OpReduction< HWModuleOp >, circt::OpReduction< StateOp >, circt::PassReduction, FIRRTLOperandForwarder< OpNum >, FIRRTLConstantifier, ConnectInvalidator, AnnotationRemover, ConnectForwarder, ConnectSourceOperandForwarder< OpNum >, DetachSubaccesses, ModuleInternalNameSanitizer, and HWOperandForwarder< OpNum >.
Definition at line 41 of file Reduction.h.
Referenced by matches().
|
inlinevirtual |
Collect all ways how this reduction can apply to a specific operation.
If a reduction can apply to an operation in different ways, for example deleting different operands, it should call addMatch
multiple times with the expected benefit of the match, as well as an integer identifying one of the different ways it can match.
Calls match(op)
by default.
Reimplemented in HWConstantifier, ModuleInputPruner, and ModuleOutputPruner.
Definition at line 50 of file Reduction.h.
References match().
Referenced by rewriteMatches().
|
inline |
Definition at line 101 of file Reduction.h.
References notifyOpErasedCallback.
Referenced by circt::reduce::pruneUnusedOps().
|
inlinevirtual |
Apply the reduction to a specific operation.
If the returned result indicates that the application failed, the resulting module is treated the same as if the tester marked it as uninteresting.
Reimplemented in circt::OpReduction< OpTy >, circt::OpReduction< firrtl::CircuitOp >, circt::OpReduction< firrtl::FModuleOp >, circt::OpReduction< firrtl::InstanceOp >, circt::OpReduction< firrtl::MemOp >, circt::OpReduction< firrtl::NodeOp >, circt::OpReduction< HWModuleOp >, circt::OpReduction< StateOp >, circt::PassReduction, FIRRTLOperandForwarder< OpNum >, FIRRTLConstantifier, ConnectInvalidator, AnnotationRemover, ConnectForwarder, ConnectSourceOperandForwarder< OpNum >, DetachSubaccesses, ModuleInternalNameSanitizer, and HWOperandForwarder< OpNum >.
Definition at line 58 of file Reduction.h.
Referenced by rewriteMatches().
|
inlinevirtual |
Apply a set of matches of this reduction to a specific operation.
If the reduction registered multiple matches for an operation, a subset of the integer identifiers of those matches will be passed to this function again. If the returned result indicates that the application failed, the resulting module is treated the same as if the tester marked it as uninteresting.
Reimplemented in HWConstantifier, ModuleInputPruner, and ModuleOutputPruner.
Definition at line 66 of file Reduction.h.
std::function<void(Operation *)> circt::Reduction::notifyOpErasedCallback = nullptr |
An optional callback for reductions to communicate removal of operations.
Definition at line 99 of file Reduction.h.
Referenced by notifyOpErased().