Add control over scl cache.

This commit is contained in:
nella 2026-08-17 10:49:45 +02:00
parent dbe5b7c03f
commit 5efa8187ad
6 changed files with 115 additions and 2 deletions

View File

@ -37,6 +37,9 @@ yosys_pass(libcache
REQUIRES
libparse
)
yosys_pass(scl_cache
scl_cache.cc
)
set(abc_definitions
"$<$<BOOL:${YOSYS_ABC_EXECUTABLE}>:ABCEXTERNAL=\"${YOSYS_ABC_EXECUTABLE}\">"
@ -50,6 +53,7 @@ yosys_pass(abc
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
read_blif
scl_cache
ENABLE_IF
YOSYS_ENABLE_ABC
)
@ -59,6 +63,8 @@ yosys_pass(abc9_exe
${abc_definitions}
LIBRARIES
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
scl_cache
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

@ -11,6 +11,9 @@ namespace abc {
YOSYS_NAMESPACE_BEGIN
// Controlled by the scl_cache pass, 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 the scl_cache pass
*/
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

@ -0,0 +1,82 @@
/*
* yosys -- Yosys Open SYnthesis Suite
*
* Copyright (C) 2026 Simon Tupy <simontupy64@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#include "kernel/yosys.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
struct SclCachePass : public Pass {
SclCachePass() : Pass("scl_cache", "control caching of merged SCL files generated for ABC") { }
void help() override
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n");
log(" scl_cache {-enable|-disable|-list}\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.\n");
log("\n");
log(" -enable Enable caching (default).\n");
log(" -disable Disable caching, ABC reads the liberty files directly.\n");
log(" -list Display the current cache setting.\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *) override
{
bool enable = false;
bool disable = false;
bool list = false;
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++) {
if (args[argidx] == "-enable") {
enable = true;
continue;
}
if (args[argidx] == "-disable") {
disable = true;
continue;
}
if (args[argidx] == "-list") {
list = true;
continue;
}
break;
}
if (argidx != args.size())
log_cmd_error("Unexpected argument `%s'.\n", args[argidx].c_str());
int modes = enable + disable + list;
if (modes != 1)
log_cmd_error("Exactly one of -enable, -disable, or -list is required.\n");
if (list)
log("SCL caching is %s.\n", scl_cache_enabled ? "enabled" : "disabled");
else
scl_cache_enabled = enable;
}
} SclCachePass;
PRIVATE_NAMESPACE_END

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
scl_cache -disable
logger -expect log "SCL caching is disabled." 1
scl_cache -list
logger -check-expected
logger -expect log "SCL cache disabled, using liberty format" 1
abc -liberty normal.lib
logger -check-expected
scl_cache -enable
logger -expect log "using cached merged SCL" 1
abc -liberty normal.lib
logger -check-expected