21#include "mlir/IR/Builders.h"
22#include "mlir/Pass/Pass.h"
23#include "llvm/Support/Debug.h"
25#define DEBUG_TYPE "synth-generic-lut-mapper"
32#define GEN_PASS_DEF_GENERICLUTMAPPER
33#include "circt/Dialect/Synth/Transforms/SynthPasses.h.inc"
54 llvm::FailureOr<Operation *>
rewrite(mlir::OpBuilder &rewriter,
55 Cut &cut)
const override {
59 llvm::dbgs() <<
"Rewriting cut with " << cut.
getInputSize()
61 <<
" operations to a generic LUT with " <<
k <<
" inputs.\n";
62 cut.
dump(llvm::dbgs());
63 llvm::dbgs() <<
"Truth table details:\n";
64 truthTable.dump(llvm::dbgs());
67 SmallVector<bool> lutTable;
69 for (uint32_t i = 0; i < truthTable.table.getBitWidth(); ++i)
70 lutTable.push_back(truthTable.table[i]);
72 auto arrayAttr = rewriter.getBoolArrayAttr(
76 SmallVector<Value> lutInputs(cut.
inputs.rbegin(), cut.
inputs.rend());
79 auto truthTableOp = rewriter.create<comb::TruthTableOp>(
80 cut.
getRoot()->getLoc(), lutInputs, arrayAttr);
83 return truthTableOp.getOperation();
108 :
public impl::GenericLutMapperBase<GenericLUTMapperPass> {
112 auto module = getOperation();
122 SmallVector<std::unique_ptr<CutRewritePattern>, 4>
patterns;
124 std::make_unique<GenericLUT>(module->getContext(), maxLutSize));
133 if (failed(rewriter.
run(module)))
134 return signalPassFailure();
Manages a collection of rewriting patterns for combinational logic optimization.
Main cut-based rewriting algorithm for combinational logic optimization.
LogicalResult run(Operation *topOp)
Execute the complete cut-based rewriting algorithm.
Represents a cut in the combinational logic network.
unsigned getOutputSize() const
Get the number of outputs from root operation.
mlir::Operation * getRoot() const
Get the root operation of this cut.
llvm::SmallSetVector< mlir::Value, 4 > inputs
External inputs to this cut (cut boundary).
void dump(llvm::raw_ostream &os) const
const BinaryTruthTable & getTruthTable() const
Get the truth table for this cut.
unsigned getInputSize() const
Get the number of inputs to this cut.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void runOnOperation() override
A generic K-input LUT pattern that can implement any boolean function with up to K inputs using a loo...
unsigned getNumInputs() const override
Get the number of inputs this pattern expects.
bool match(const Cut &cut) const override
Check if a cut matches this pattern.
DelayType getDelay(unsigned inputIndex, unsigned outputIndex) const override
Get the delay between specific input and output.
unsigned getNumOutputs() const override
Get the number of outputs this pattern produces.
llvm::FailureOr< Operation * > rewrite(mlir::OpBuilder &rewriter, Cut &cut) const override
Return a new operation that replaces the matched cut.
double getArea(const Cut &cut) const override
Get the area cost of this pattern.
StringRef getPatternName() const override
Get the name of this pattern. Used for debugging.
GenericLUT(mlir::MLIRContext *context, unsigned k)
Base class for cut rewriting patterns used in combinational logic optimization.
mlir::MLIRContext * context
Configuration options for the cut-based rewriting algorithm.
unsigned maxCutInputSize
Maximum number of inputs allowed for any cut.
unsigned maxCutSizePerRoot
Maximum number of cuts to maintain per logic node.
bool allowNoMatch
Fail if there is a root operation that has no matching pattern.
bool attachDebugTiming
Put arrival times to rewritten operations.
OptimizationStrategy strategy
Optimization strategy (area vs. timing).