From 027677d43b1be5a7e1824c12ee131bc6d07d3e22 Mon Sep 17 00:00:00 2001 From: nella Date: Mon, 17 Aug 2026 12:37:49 +0200 Subject: [PATCH] Move scl cache args to libcache, fix -disable. --- passes/techmap/CMakeLists.txt | 7 +-- passes/techmap/libcache.cc | 28 ++++++++++-- passes/techmap/liberty_cache.h | 4 +- passes/techmap/scl_cache.cc | 82 ---------------------------------- tests/liberty/libcache.ys | 6 +++ tests/liberty/scl_cache.ys | 6 +-- 6 files changed, 38 insertions(+), 95 deletions(-) delete mode 100644 passes/techmap/scl_cache.cc diff --git a/passes/techmap/CMakeLists.txt b/passes/techmap/CMakeLists.txt index a7f03af30..f06a36e69 100644 --- a/passes/techmap/CMakeLists.txt +++ b/passes/techmap/CMakeLists.txt @@ -37,9 +37,6 @@ yosys_pass(libcache REQUIRES libparse ) -yosys_pass(scl_cache - scl_cache.cc -) set(abc_definitions "$<$: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 ) diff --git a/passes/techmap/libcache.cc b/passes/techmap/libcache.cc index e4326c49f..c6fa98524 100644 --- a/passes/techmap/libcache.cc +++ b/passes/techmap/libcache.cc @@ -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) { diff --git a/passes/techmap/liberty_cache.h b/passes/techmap/liberty_cache.h index 97753cc64..e2b0900aa 100644 --- a/passes/techmap/liberty_cache.h +++ b/passes/techmap/liberty_cache.h @@ -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 &liberty_files, const std::string &dont_use_args, const std::string &abc_exe) { diff --git a/passes/techmap/scl_cache.cc b/passes/techmap/scl_cache.cc deleted file mode 100644 index c9642749f..000000000 --- a/passes/techmap/scl_cache.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * yosys -- Yosys Open SYnthesis Suite - * - * Copyright (C) 2026 Simon Tupy - * - * 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 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 diff --git a/tests/liberty/libcache.ys b/tests/liberty/libcache.ys index 8132b3f11..5914a50e4 100644 --- a/tests/liberty/libcache.ys +++ b/tests/liberty/libcache.ys @@ -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 diff --git a/tests/liberty/scl_cache.ys b/tests/liberty/scl_cache.ys index e4cfe8032..e7305fe25 100644 --- a/tests/liberty/scl_cache.ys +++ b/tests/liberty/scl_cache.ys @@ -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