Move scl cache args to libcache, fix -disable.

This commit is contained in:
nella 2026-08-17 12:37:49 +02:00
parent 5efa8187ad
commit 027677d43b
6 changed files with 38 additions and 95 deletions

View File

@ -37,9 +37,6 @@ yosys_pass(libcache
REQUIRES
libparse
)
yosys_pass(scl_cache
scl_cache.cc
)
set(abc_definitions
"$<$<BOOL:${YOSYS_ABC_EXECUTABLE}>:ABCEXTERNAL=\"${YOSYS_ABC_EXECUTABLE}\">"
@ -52,8 +49,8 @@ yosys_pass(abc
LIBRARIES
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
libcache
read_blif
scl_cache
ENABLE_IF
YOSYS_ENABLE_ABC
)
@ -64,7 +61,7 @@ yosys_pass(abc9_exe
LIBRARIES
$<${YOSYS_LINK_ABC}:libyosys-abc>
REQUIRES
scl_cache
libcache
ENABLE_IF
YOSYS_ENABLE_ABC
)

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,7 +11,7 @@ namespace abc {
YOSYS_NAMESPACE_BEGIN
// Controlled by the scl_cache pass, enabled by default
// Controlled by the libcache pass (-scl option), enabled by default
extern bool scl_cache_enabled;
/*
@ -21,7 +21,7 @@ extern bool scl_cache_enabled;
* @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
* 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)
{

View File

@ -1,82 +0,0 @@
/*
* 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

@ -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

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