Merge pull request #6124 from YosysHQ/nella/scl-cache-arg

scl_cache: add pass to control merged SCL caching for ABC [sc-771]
This commit is contained in:
nella 2026-08-17 12:18:18 +00:00 committed by GitHub
commit 8c5789903a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 61 additions and 5 deletions

View File

@ -49,6 +49,7 @@ yosys_pass(abc
LIBRARIES
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
libcache
read_blif
ENABLE_IF
YOSYS_ENABLE_ABC
@ -59,6 +60,8 @@ yosys_pass(abc9_exe
${abc_definitions}
LIBRARIES
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
libcache
ENABLE_IF
YOSYS_ENABLE_ABC
)

View File

@ -1033,6 +1033,8 @@ void AbcModuleState::prepare_module(RTLIL::Design *design, RTLIL::Module *module
} else if(!config.liberty_files.empty()) {
if (!config.abc_liberty_args.empty()) {
log("ABC: abc_liberty_args provided, using liberty format\n");
} else if (!scl_cache_enabled) {
log("ABC: SCL cache disabled, using liberty format\n");
} else {
log_warning("ABC: Merged scl conversion failed, using liberty format\n");
}

View File

@ -190,7 +190,10 @@ void abc9_module(RTLIL::Design *design, std::string script_file, std::string exe
if (!merged_scl.empty()) {
abc9_script += stringf("read_scl \"%s\" ; ", merged_scl.c_str());
} else if(!liberty_files.empty()) {
log_warning("ABC: Merged scl conversion failed, using liberty format\n");
if (!scl_cache_enabled)
log("ABC: SCL cache disabled, using liberty format\n");
else
log_warning("ABC: Merged scl conversion failed, using liberty format\n");
bool first_lib = true;
for (std::string liberty_file : liberty_files) {
abc9_script += stringf("read_lib %s %s -w \"%s\" ; ", dont_use_args, first_lib ? "" : "-m", liberty_file);

View File

@ -20,6 +20,11 @@
#include "kernel/yosys.h"
#include "passes/techmap/libparse.h"
YOSYS_NAMESPACE_BEGIN
// Read by convert_liberty_files_to_merged_scl() in liberty_cache.h
bool scl_cache_enabled = true;
YOSYS_NAMESPACE_END
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
@ -43,6 +48,11 @@
log("\n");
log("By default caching is disabled.\n");
log("\n");
log(" libcache -scl {-enable|-disable}\n");
log("\n");
log("Controls the on-disk cache of merged SCL files that the abc and abc9 passes\n");
log("generate from liberty files. By default this caching is enabled.\n");
log("\n");
log(" libcache -list\n");
log("\n");
log("Displays the current cache settings and cached paths.\n");
@ -61,6 +71,7 @@
bool disable = false;
bool purge = false;
bool all = false;
bool scl = false;
bool list = false;
bool verbose = false;
bool quiet = false;
@ -73,7 +84,11 @@
continue;
}
if (args[argidx] == "-disable") {
enable = true;
disable = true;
continue;
}
if (args[argidx] == "-scl") {
scl = true;
continue;
}
if (args[argidx] == "-purge") {
@ -109,17 +124,24 @@
log_cmd_error("The -all option cannot be combined with a list of paths.\n");
if (list && (all || !paths.empty()))
log_cmd_error("The -list mode takes no further options.\n");
if (!list && !all && paths.empty())
if (scl && !(enable || disable))
log_cmd_error("The -scl option can only be combined with -enable or -disable.\n");
if (scl && (all || !paths.empty()))
log_cmd_error("The -scl option cannot be combined with -all or a list of paths.\n");
if (!list && !all && !scl && paths.empty())
log("No paths specified, use -all to %s\n", purge ? "purge all paths" : "change the default setting");
if (list) {
log("Caching is %s by default.\n", LibertyAstCache::instance.cache_by_default ? "enabled" : "disabled");
log("SCL caching is %s.\n", scl_cache_enabled ? "enabled" : "disabled");
for (auto const &entry : LibertyAstCache::instance.cache_path)
log("Caching is %s for `%s'.\n", entry.second ? "enabled" : "disabled", entry.first);
for (auto const &entry : LibertyAstCache::instance.cached)
log("Data for `%s' is currently cached.\n", entry.first);
} else if (enable || disable) {
if (all) {
if (scl) {
scl_cache_enabled = enable;
} else if (all) {
LibertyAstCache::instance.cache_by_default = enable;
} else {
for (auto const &path : paths) {

View File

@ -11,6 +11,9 @@ namespace abc {
YOSYS_NAMESPACE_BEGIN
// Controlled by the libcache pass (-scl option), enabled by default
extern bool scl_cache_enabled;
/*
* convert_liberty_files_to_merged_scl() - Convert multiple Liberty files to a single merged SCL cache file.
* @liberty_files: Vector of liberty file paths to merge
@ -18,10 +21,11 @@ YOSYS_NAMESPACE_BEGIN
* @abc_exe: Path to ABC executable for conversion
*
* Return: Path to merged SCL cache file, or empty string if conversion fails
* or caching is disabled via libcache -scl -disable
*/
inline std::string convert_liberty_files_to_merged_scl(const std::vector<std::string> &liberty_files, const std::string &dont_use_args, const std::string &abc_exe)
{
if (liberty_files.empty())
if (liberty_files.empty() || !scl_cache_enabled)
return "";
std::string cache_dir = get_base_tmpdir() + "/yosys-liberty-scl-cache";

View File

@ -64,3 +64,9 @@ logger -check-expected
logger -expect log "Using cached data" 1
dfflibmap -liberty normal.lib
logger -check-expected
libcache -disable -all
logger -expect log "Caching is disabled by default." 1
libcache -list
logger -check-expected

View File

@ -5,3 +5,19 @@ abc -liberty normal.lib
logger -expect log "using cached merged SCL" 1
abc -liberty normal.lib
logger -check-expected
libcache -scl -disable
logger -expect log "SCL caching is disabled." 1
libcache -list
logger -check-expected
logger -expect log "SCL cache disabled, using liberty format" 1
abc -liberty normal.lib
logger -check-expected
libcache -scl -enable
logger -expect log "using cached merged SCL" 1
abc -liberty normal.lib
logger -check-expected