From 5efa8187adf6aee0d0c20e21069777b49ed9f529 Mon Sep 17 00:00:00 2001 From: nella Date: Mon, 17 Aug 2026 10:49:45 +0200 Subject: [PATCH] Add control over scl cache. --- passes/techmap/CMakeLists.txt | 6 +++ passes/techmap/abc.cc | 2 + passes/techmap/abc9_exe.cc | 5 ++- passes/techmap/liberty_cache.h | 6 ++- passes/techmap/scl_cache.cc | 82 ++++++++++++++++++++++++++++++++++ tests/liberty/scl_cache.ys | 16 +++++++ 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 passes/techmap/scl_cache.cc diff --git a/passes/techmap/CMakeLists.txt b/passes/techmap/CMakeLists.txt index bb5896325..a7f03af30 100644 --- a/passes/techmap/CMakeLists.txt +++ b/passes/techmap/CMakeLists.txt @@ -37,6 +37,9 @@ yosys_pass(libcache REQUIRES libparse ) +yosys_pass(scl_cache + scl_cache.cc +) set(abc_definitions "$<$: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 ) diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index 3c4341808..81d841c50 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -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"); } diff --git a/passes/techmap/abc9_exe.cc b/passes/techmap/abc9_exe.cc index a32816612..3fd549e7a 100644 --- a/passes/techmap/abc9_exe.cc +++ b/passes/techmap/abc9_exe.cc @@ -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); diff --git a/passes/techmap/liberty_cache.h b/passes/techmap/liberty_cache.h index 9cb8752f1..97753cc64 100644 --- a/passes/techmap/liberty_cache.h +++ b/passes/techmap/liberty_cache.h @@ -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 &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"; diff --git a/passes/techmap/scl_cache.cc b/passes/techmap/scl_cache.cc new file mode 100644 index 000000000..c9642749f --- /dev/null +++ b/passes/techmap/scl_cache.cc @@ -0,0 +1,82 @@ +/* + * 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/scl_cache.ys b/tests/liberty/scl_cache.ys index 85fbae839..e4cfe8032 100644 --- a/tests/liberty/scl_cache.ys +++ b/tests/liberty/scl_cache.ys @@ -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