Skip to content

abc/abc_new: cache parsed liberty files as .scl to avoid re-parsing across invocations#5813

Merged
Goubermouche merged 6 commits into
mainfrom
nella/fast-liberty-file
Apr 23, 2026
Merged

abc/abc_new: cache parsed liberty files as .scl to avoid re-parsing across invocations#5813
Goubermouche merged 6 commits into
mainfrom
nella/fast-liberty-file

Conversation

@Goubermouche
Copy link
Copy Markdown
Contributor

@Goubermouche Goubermouche commented Apr 17, 2026

When abc is invoked with -liberty, the liberty file paths are embedded into the generated ABC script as read_lib commands. ABC then re-parses every liberty file from scratch on each invocation. In hierarchical flows where abc runs once per module, this means the same liberty files are parsed N times for N modules. For large libraries this can drastically slow down the entire flow.

This PR aims to fix this issue by adding a cache for the liberty files. The cache is implemented as a merged scl file, which is generated on the first abc invocation, subsequent runs use the merged scl. From my research, scl should preserve everything ABC uses for tech mapping, while stripping the majority of the unneeded data, drastically reducing file size, and being much faster to process.

In order to test perf I've ran the following benchmark: abc -liberty invoked on a couple simple modules with a varying amount of liberty files, resulting in a ~6x speedup. Module contents are intentionally trivial because the bottleneck being addressed is parse time, not mapping time. See results below:

image

I've also tested an implementation which modified ABC so that it's capable of merging scl files via read_scl, the idea behind this being that we could cache separate files, not the entire list, which could prove beneficial when a flow invokes abc with different sets of liberty files, but the speedup went down to about ~4x. I believe that these flows are less common, so I chose to go with the above method.

TODO:

  • abc9_exe support
  • check equivalence of formats
  • verify dont_use_cells

@widlarizer
Copy link
Copy Markdown
Collaborator

cc @QuantamHD @mikesinouye

@widlarizer
Copy link
Copy Markdown
Collaborator

I was wondering if SCL could be accepted by Yosys in place of Liberty so that Liberty is parsed only once across both programs, but unfortunately since abc-written SCL skips sequential cells, Yosys couldn't map flip flops with dfflibmap

@mikesinouye
Copy link
Copy Markdown
Contributor

This is excellent! Thank you for working on this feature.

when a flow invokes abc with different sets of liberty files

This is not a current use case of ours so optimizing for it should not be necessary.

@Goubermouche Goubermouche changed the title abc: cache parsed liberty files as .scl to avoid re-parsing across invocations abc/abc_new: cache parsed liberty files as .scl to avoid re-parsing across invocations Apr 22, 2026
@Goubermouche Goubermouche marked this pull request as ready for review April 22, 2026 09:02
@Goubermouche Goubermouche added this pull request to the merge queue Apr 22, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 22, 2026
@Goubermouche Goubermouche enabled auto-merge April 22, 2026 14:31
Comment thread passes/techmap/liberty_cache.h Outdated
* Return: Path to merged SCL cache file, or empty string if conversion fails
*/
#if defined(YOSYS_LINK_ABC)
inline std::string convert_liberty_files_to_merged_scl(const std::vector<std::string> &, const std::string &, const std::string &) { return ""; }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wait, is it impossible to make this function work with YOSYS_LINK_ABC as well? It's a legitimate option on other platforms, too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, my thinking was that this is only related to WASI, where this optimization wouldn't really be needed and this would be a quick fix. Will fix using Abc_RealMain. Thanks for the headsup.

@Goubermouche Goubermouche disabled auto-merge April 22, 2026 14:43
Comment thread passes/techmap/liberty_cache.h Outdated
if (last_slash == std::string::npos) {
first_dir = ".";
} else {
first_dir = liberty_files[0].substr(0, last_slash);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In most of our flows, the liberty file location and the CWD are non-writeable as you're often inside a container, with some other dir for allocated scratch space. Would it be possible to store this file in the same (or similar) abc tmpdir that's created? This could be done in a follow-up change too to land this one.

https://github.com/YosysHQ/yosys/blob/main/kernel/io.cc#L149

@Goubermouche Goubermouche force-pushed the nella/fast-liberty-file branch from 2102412 to d795a4f Compare April 23, 2026 10:43
@Goubermouche Goubermouche enabled auto-merge April 23, 2026 11:12
@Goubermouche Goubermouche added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit 7e7336c Apr 23, 2026
30 checks passed
@Goubermouche Goubermouche deleted the nella/fast-liberty-file branch April 23, 2026 13:12
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.

4 participants