Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@uenoku
Copy link
Member

@uenoku uenoku commented Aug 4, 2025

This is the first commit introducing a cut-based rewriting framework for combinational logic optimization. Cut-based rewriting is a fundamental technique in logic synthesis which are used for not only technology mapping/LUT mappping but also logic optimization by identifying and replacing subgraphs (cuts) in combinational circuits with functionally equivalent but more optimal implementations (ABC's rewrite and lazy man's synthesis etc, mockturtle's cut rewriting )

This initial implementation focuses specifically on priority cuts enumeration as the foundation for future cut-based optimization passes. The framework includes a Cut data structure for representing logical cuts with truth tables, a CutEnumerator implementing the priority cuts algorithm with configurable limits, cut enumeration with size constraints and deduplication, truth table computation and NPN canonical form matching, support for AIG operations.

The implementation is based on ABC's priority cuts paper https://people.eecs.berkeley.edu/~alanmi/publications/2007/iccad07_map.pdf

The priority cuts algorithm maintains a bounded set of promising cuts per node to avoid exponential explosion while preserving optimization quality. This foundation enables future development of technology mapping, LUT mapping, and other cut-based combinational optimization passes.

CutRewriter.h and CutRewriter.cpp are actual implementations of cut enumeration.

@uenoku uenoku force-pushed the dev/hidetou/upstream-priority-cuts branch 4 times, most recently from e044ee4 to a3c70ab Compare August 4, 2025 06:27
@uenoku uenoku changed the title [Synth] Add cut rewrite framework (priority cuts enumeration) [Synth] Add Priority Cuts Enumerator Aug 4, 2025
Base automatically changed from dev/hidetou/synth-dialect to main August 4, 2025 20:09
This is the first commit introducing a cut-based rewriting framework for
combinational logic optimization. Cut-based rewriting is a fundamental
technique in  logic synthesis which are used for not only technology
mapping/LUT mappping but also logic optimization by identifying and replacing
subgraphs (cuts) in combinational circuits with functionally equivalent
but more optimal implementations.

This initial implementation focuses specifically on priority cuts enumeration
as the foundation for future cut-based optimization passes. The framework
includes a Cut data structure for representing logical cuts with truth tables,
a CutEnumerator implementing the priority cuts algorithm with configurable
limits, cut enumeration with size constraints and deduplication, truth table
computation and NPN canonical form matching, support for AIG operations with
comprehensive error handling, and test infrastructure for priority cuts
validation.

The priority cuts algorithm maintains a bounded set of promising cuts per
node to avoid exponential explosion while preserving optimization quality.
This foundation enables future development of technology mapping, LUT mapping,
and other cut-based combinational optimization passes.
@uenoku uenoku force-pushed the dev/hidetou/upstream-priority-cuts branch from a3c70ab to 2b80560 Compare August 4, 2025 20:41
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very very cool! Only a few nits here and there. The test pass is a great idea. Makes this whole thing a lot more hackable and interactive.

// CHECK-LABEL: Enumerating cuts for module: trivial
hw.module @trivial(in %a : i1, out result : i1) {
// CHECK: a 1 cuts: {a}@t2d0
// CHECK-NEXT: out0 2 cuts: {out0}@t2d0 {a}@t2d1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool that this already gives you the minimal truth table 😍

Comment on lines +229 to +231
// Simulate the operations in the cut
for (auto *op : operations)
simulateLogicOp(op, eval);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool idea to generate these input truth table vectors and then flow them through the ops, essentially vectorizing the circuit evaluation using bitwise logic ops. 🥳

Comment on lines +484 to +488
// Schedule cut set finalization when exiting this scope
auto prune = llvm::make_scope_exit([&]() {
// Finalize cut set: remove duplicates, limit size, and match patterns
resultCutSet->finalize(options);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

@uenoku uenoku force-pushed the dev/hidetou/upstream-priority-cuts branch 2 times, most recently from db359c6 to a4adb18 Compare August 5, 2025 05:24
@uenoku uenoku force-pushed the dev/hidetou/upstream-priority-cuts branch from a4adb18 to 9241902 Compare August 5, 2025 05:33
@uenoku uenoku merged commit 43cdcc5 into main Aug 5, 2025
7 checks passed
@uenoku uenoku deleted the dev/hidetou/upstream-priority-cuts branch August 5, 2025 06:16
@cowardsa
Copy link
Contributor

cowardsa commented Aug 5, 2025

Sorry I couldn't get to this quickly enough - but looks really interesting - did have two questions though:

  1. The ABC paper largely talks about FPGA mapping where the target is K-LUTs - do you know how effective the technique is for standard cell libraries?
  2. Do you have a benchmark suite (potentially internal) to evaluate "progress" on in terms of runtime vs logic depth vs number of cells as would be helpful to understand where gains are coming from?

@uenoku
Copy link
Member Author

uenoku commented Aug 5, 2025

Thank you for taking a look! Sorry I was a bit rush to merge :)

  1. https://dl.acm.org/doi/10.1145/2593069.2593158 has comparison for MIG/AIG-based mapping with commercial tools for standard cell mapping. MIG has better results in the paper but AIG(ABC) is on par with commercial tool. ABC uses priority-cut + NPN + supergate based mapping. Though for MIG experiments setup has short description ("traditional optimization mapping") and implementation is not disclosed as far as I see but I believe they are doing the same (considered that mockturtle's mapper works in the same way https://mockturtle.readthedocs.io/en/latest/algorithms/mapper.html).
  2. No at this moment but I'm planning to add https://github.com/lsils/benchmarks to https://github.com/circt/circt-tests test-suites and track (combinatorial) mapping results with open source PDK. Also for e2e testing I'm hoping we can use large chisel open source projects as benchmark (rocket, boom, XiangShan, t1 etc). I eventually want to track results on internal designs but it's difficult to disclose the design so first I'd like to focus on setting up benchmark on open source projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants