CIRCT 22.0.0git
Loading...
Searching...
No Matches
TestPriorityCuts.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements a test for priority cuts implementation.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/ADT/STLExtras.h"
17#include "llvm/Support/Debug.h"
18#include "llvm/Support/raw_ostream.h"
19#include <memory>
20
21namespace circt {
22namespace synth {
23#define GEN_PASS_DEF_TESTPRIORITYCUTS
24#include "circt/Dialect/Synth/Transforms/SynthPasses.h.inc"
25} // namespace synth
26} // namespace circt
27
28using namespace circt;
29using namespace circt::synth;
30
31#define DEBUG_TYPE "synth-test-priority-cuts"
32
33//===----------------------------------------------------------------------===//
34// Test Priority Cuts Pass
35//===----------------------------------------------------------------------===//
36
37namespace {
38
39// Dummy pattern that matches any cut.
40struct DummyPattern : public CutRewritePattern {
41 DummyPattern(mlir::MLIRContext *ctx) : CutRewritePattern(ctx) {}
42 bool match(const Cut &cut) const override { return true; }
43 FailureOr<Operation *> rewrite(mlir::OpBuilder &builder,
44 Cut &cut) const override {
45 return failure();
46 }
47
48 unsigned getNumOutputs() const override { return 1; }
49
50 double getArea() const override { return 1; }
51 DelayType getDelay(unsigned inputIndex, unsigned outputIndex) const override {
52 return 1;
53 }
54};
55
56struct TestPriorityCutsPass
57 : public impl::TestPriorityCutsBase<TestPriorityCutsPass> {
58 using TestPriorityCutsBase<TestPriorityCutsPass>::TestPriorityCutsBase;
59
60 void runOnOperation() override {
61 auto hwModule = getOperation();
62
63 LLVM_DEBUG(llvm::dbgs() << "Running TestPriorityCuts on module: "
64 << hwModule.getName() << "\n");
65
66 // Set up cut rewriter options for testing
67 CutRewriterOptions options;
68 options.maxCutInputSize = maxCutInputSize;
69 options.maxCutSizePerRoot = maxCutsPerRoot;
70 // Currently there is no behavioral difference between timing and area
71 // so just test with timing strategy.
73 options.testPriorityCuts = true;
74 SmallVector<std::unique_ptr<CutRewritePattern>, 4> patterns;
75 patterns.push_back(std::make_unique<DummyPattern>(hwModule->getContext()));
76 CutRewritePatternSet patternSet(std::move(patterns));
77 CutRewriter rewriter(options, patternSet);
78 CutEnumerator enumerator(options);
79 llvm::outs() << "Enumerating cuts for module: " << hwModule.getModuleName()
80 << "\n";
81
82 if (failed(rewriter.run(hwModule))) {
83 signalPassFailure();
84 return;
85 }
86 }
87};
88
89} // namespace
Cut enumeration engine for combinational logic networks.
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.
@ OptimizationStrategyTiming
Optimize for minimal critical path delay.
Definition SynthPasses.h:26
int64_t DelayType
Definition CutRewriter.h:36
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition synth.py:1
Base class for cut rewriting patterns used in combinational logic optimization.
virtual DelayType getDelay(unsigned inputIndex, unsigned outputIndex) const =0
Get the delay between specific input and output.
virtual FailureOr< Operation * > rewrite(mlir::OpBuilder &builder, Cut &cut) const =0
Return a new operation that replaces the matched cut.
virtual double getArea() const =0
Get the area cost of this pattern.
virtual unsigned getNumOutputs() const =0
Get the number of outputs this pattern produces.
virtual bool match(const Cut &cut) const =0
Check if a cut matches this pattern.
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.
OptimizationStrategy strategy
Optimization strategy (area vs. timing).
bool testPriorityCuts
Run priority cuts enumeration and dump the cut sets.