Skip to content

[Synth][CutRewriter] Migrate CutRewriter to use Flat IR#9805

Merged
uenoku merged 1 commit intomainfrom
dev/uenoku/cut-change
Mar 3, 2026
Merged

[Synth][CutRewriter] Migrate CutRewriter to use Flat IR#9805
uenoku merged 1 commit intomainfrom
dev/uenoku/cut-change

Conversation

@uenoku
Copy link
Member

@uenoku uenoku commented Mar 2, 2026

Switch cut enumeration and truth table handling to LogicNetwork indices, update downstream mappers to the new cut API, and refresh Synth tests for the updated ordering and operations. PR staked on #9804.

This is NFCI except for a small bug fix in NPNClass utils; only operand orders are reordered.

The following is a runtime comparison of LUT mapping for hyp test case (0.2M AIG nodes, largest test case of non MtM category) in EPFL Combinational Benchmark Suite. LUT mapping is a good benchmark to check cut enumeration performance since only cut enumeration is generally performed. Note that this is not a perfectly fair comparison to ABC because ABC performs more optimizations like area recovery or applying several strategies for cut selection. When k=6 is generally same, for k > 6 we are missing fast computation for truth table (since we cannot represent in single 64 bit integer) so it's reasonable. At least it got 8~10 times faster from the previous implementation.

before:

max_lut_size(K) max_cuts_per_root(C) ABC ("if -K -C") time (sec) CIRCT GenericLutMapper (sec) LUT depth ABC LUT depth CIRCT
6 8 2.72 16.3945 4194 4195
6 15 5.52 54.3470 4196 4197

after:

max_lut_size(K) max_cuts_per_root(C) ABC ("if -K -C") time (sec) CIRCT GenericLutMapper (sec) LUT depth ABC LUT depth CIRCT
6 8 2.73 2.5538 4194 4195
6 15 5.49 5.3534 4196 4196
6 25 9.70 9.2742 4194 4194
8 8 3.76 6.2786 2818 2818
8 15 8.40 15.4164 2818 2818
8 25 17.00 28.0075 2818 2818
10 8 4.83 10.0969 2119 2120
10 15 12.02 29.8168 2118 2120
10 25 25.59 69.3343 2119 2119

AI-assisted-by: Claude Sonnet 4.6, Opus 4.6

Comment on lines +940 to +941
} else if (numFanins == 2) {
// Two-way merge (common case for AND gates)
Copy link
Member Author

Choose a reason for hiding this comment

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

Profile showed this merge sort is one of the critical path so these parts are manually written instead of relying on STL.

@uenoku uenoku changed the title [Synth] Migrate CutRewriter to use Flat IR [Synth][CutRewriter] Migrate CutRewriter to use Flat IR Mar 2, 2026
@uenoku uenoku marked this pull request as draft March 2, 2026 03:29
@uenoku uenoku force-pushed the dev/uenoku/cut-change branch from 41c4577 to 644a4ec Compare March 2, 2026 05:40
@uenoku uenoku marked this pull request as ready for review March 2, 2026 05:46
@uenoku uenoku force-pushed the dev/uenoku/cut-change branch from 644a4ec to 774d609 Compare March 2, 2026 07:45
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 really really cool! Amazing speedup, and great to see that the cut rewriting is in the same ballpark as ABC! 🥳

uenoku added a commit that referenced this pull request Mar 3, 2026
…work (#9804)

This commit introduces a data structure which reduces CutRewriter run time quite a bit (see benchmark result in #9805). 

It is well known that MLIR is too slow when naively used for specific logic synthesis transformation like Cut rewriting, and previous implementation was impractical when cut input size > 4. For these tasks, a cache-friendly flat IR data structure (like those in ABC or mockturtle) is much more efficient.

This PR changes CutRewriter to first create a read-only, in-memory IR to be used by the CutRewriter. It allows 2-input AND, 3-input Majority, and 2-input XOR to coexist in the same data structure, which lets us represent AIG, MIG, XOR-AND, and XOR-MAJ together. This is slight different from ABC (AIG), Mockurtle's template based implementation (AIG/MIG/XOR-MAJ/XOR-AND).

This PR introduces only data structure, test changes are included in #9805 

AI-assisted-by: Claude Sonnet 4.6, Opus 4.6
Base automatically changed from dev/hidetou/flat-ir to main March 3, 2026 21:10
Switch cut enumeration and truth table handling to LogicNetwork indices, update downstream mappers to consume the new cut API, and refresh Synth tests for the new ordering/operation support without area-recovery changes.
@uenoku uenoku force-pushed the dev/uenoku/cut-change branch from 6be9729 to 4662d46 Compare March 3, 2026 21:47
@uenoku uenoku merged commit 894bd8c into main Mar 3, 2026
7 checks passed
@uenoku uenoku deleted the dev/uenoku/cut-change branch March 3, 2026 22:11
@cowardsa
Copy link
Contributor

cowardsa commented Mar 4, 2026

Amazing stuff @uenoku - sorry I was too slow to review haha - we've been running circt-synth on some really large testcases and my collaborators have complained about speed so hopefully this might offer some nice benefits right away

@uenoku
Copy link
Member Author

uenoku commented Mar 4, 2026

No worry! Thank you for taking a look! Do your collaborators have performance issues around LUT mapping? If so this PR will immediately improve the compilation time. Otherwise I'm happy to investigate regression.

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