mirror of https://github.com/YosysHQ/yosys.git
abc: centralize gzipped Liberty extraction, use a separate directory, still allow per-module tmp dirs
This commit is contained in:
parent
4d6f16567c
commit
ee0b91417c
|
@ -48,6 +48,7 @@
|
||||||
#include "kernel/ff.h"
|
#include "kernel/ff.h"
|
||||||
#include "kernel/cost.h"
|
#include "kernel/cost.h"
|
||||||
#include "kernel/log.h"
|
#include "kernel/log.h"
|
||||||
|
#include "kernel/gzip.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -71,6 +72,51 @@ namespace abc {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
|
|
||||||
|
std::string tmp_base(bool cleanup)
|
||||||
|
{
|
||||||
|
std::string base;
|
||||||
|
if (cleanup)
|
||||||
|
base = get_base_tmpdir() + "/";
|
||||||
|
else
|
||||||
|
base = "_tmp_";
|
||||||
|
return base + proc_program_prefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts gzipped liberty_files and rewrites their paths
|
||||||
|
* to the new temporary file paths
|
||||||
|
*/
|
||||||
|
void lib_to_tmp(std::string top_tmpdir, std::vector<std::string>& liberty_files)
|
||||||
|
{
|
||||||
|
for (std::string& f : liberty_files) {
|
||||||
|
bool ends_gz = false;
|
||||||
|
auto dot_pos = f.find_last_of(".");
|
||||||
|
if(dot_pos != std::string::npos)
|
||||||
|
ends_gz = f.substr(dot_pos+1) == "gz";
|
||||||
|
log_debug("Does %s end with .gz? %d\n", f.c_str(), ends_gz);
|
||||||
|
if (ends_gz) {
|
||||||
|
auto filename_pos = f.find_last_of("/");
|
||||||
|
if(filename_pos == std::string::npos)
|
||||||
|
filename_pos = f.find_last_of("\\");
|
||||||
|
if(filename_pos == std::string::npos) {
|
||||||
|
filename_pos = 0;
|
||||||
|
} else {
|
||||||
|
filename_pos++;
|
||||||
|
}
|
||||||
|
std::istream* s = uncompressed(f);
|
||||||
|
std::string base = f.substr(filename_pos, dot_pos - filename_pos);
|
||||||
|
log_debug("base %s\n", base.c_str());
|
||||||
|
std::string tmp_f = top_tmpdir + "/" + base + "-XXXXXX";
|
||||||
|
tmp_f = make_temp_file(tmp_f);
|
||||||
|
log_debug("tmp_f %s\n", tmp_f.c_str());
|
||||||
|
std::ofstream out(tmp_f);
|
||||||
|
out << s->rdbuf();
|
||||||
|
f = tmp_f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PRIVATE_NAMESPACE_BEGIN
|
PRIVATE_NAMESPACE_BEGIN
|
||||||
|
|
||||||
enum class gate_type_t {
|
enum class gate_type_t {
|
||||||
|
@ -787,12 +833,7 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin
|
||||||
if (dff_mode && clk_sig.empty())
|
if (dff_mode && clk_sig.empty())
|
||||||
log_cmd_error("Clock domain %s not found.\n", clk_str.c_str());
|
log_cmd_error("Clock domain %s not found.\n", clk_str.c_str());
|
||||||
|
|
||||||
std::string tempdir_name;
|
std::string tempdir_name = tmp_base(cleanup) + "yosys-abc-XXXXXX";
|
||||||
if (cleanup)
|
|
||||||
tempdir_name = get_base_tmpdir() + "/";
|
|
||||||
else
|
|
||||||
tempdir_name = "_tmp_";
|
|
||||||
tempdir_name += proc_program_prefix() + "yosys-abc-XXXXXX";
|
|
||||||
tempdir_name = make_temp_dir(tempdir_name);
|
tempdir_name = make_temp_dir(tempdir_name);
|
||||||
log_header(design, "Extracting gate netlist of module `%s' to `%s/input.blif'..\n",
|
log_header(design, "Extracting gate netlist of module `%s' to `%s/input.blif'..\n",
|
||||||
module->name.c_str(), replace_tempdir(tempdir_name, tempdir_name, show_tempdir).c_str());
|
module->name.c_str(), replace_tempdir(tempdir_name, tempdir_name, show_tempdir).c_str());
|
||||||
|
@ -2041,6 +2082,9 @@ struct AbcPass : public Pass {
|
||||||
enabled_gates.insert("MUX");
|
enabled_gates.insert("MUX");
|
||||||
// enabled_gates.insert("NMUX");
|
// enabled_gates.insert("NMUX");
|
||||||
}
|
}
|
||||||
|
std::string lib_tempdir_name = tmp_base(cleanup) + "yosys-abc-lib-XXXXXX";
|
||||||
|
lib_tempdir_name = make_temp_dir(lib_tempdir_name);
|
||||||
|
lib_to_tmp(lib_tempdir_name, liberty_files);
|
||||||
|
|
||||||
for (auto mod : design->selected_modules())
|
for (auto mod : design->selected_modules())
|
||||||
{
|
{
|
||||||
|
@ -2221,6 +2265,9 @@ struct AbcPass : public Pass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cleanup)
|
||||||
|
remove_directory(lib_tempdir_name);
|
||||||
|
|
||||||
assign_map.clear();
|
assign_map.clear();
|
||||||
signal_list.clear();
|
signal_list.clear();
|
||||||
signal_map.clear();
|
signal_map.clear();
|
||||||
|
|
|
@ -24,6 +24,10 @@
|
||||||
#include "kernel/gzip.h"
|
#include "kernel/gzip.h"
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
|
|
||||||
|
void lib_to_tmp(std::string top_tmpdir, std::vector<std::string>& liberty_files);
|
||||||
|
std::string tmp_base(bool cleanup);
|
||||||
|
|
||||||
PRIVATE_NAMESPACE_BEGIN
|
PRIVATE_NAMESPACE_BEGIN
|
||||||
|
|
||||||
std::vector<Module*> order_modules(Design *design, std::vector<Module *> modules)
|
std::vector<Module*> order_modules(Design *design, std::vector<Module *> modules)
|
||||||
|
@ -82,7 +86,6 @@ struct AbcNewPass : public ScriptPass {
|
||||||
|
|
||||||
bool cleanup;
|
bool cleanup;
|
||||||
std::string abc_exe_options;
|
std::string abc_exe_options;
|
||||||
std::string top_tmpdir;
|
|
||||||
std::vector<std::string> liberty_files;
|
std::vector<std::string> liberty_files;
|
||||||
|
|
||||||
void execute(std::vector<std::string> args, RTLIL::Design *d) override
|
void execute(std::vector<std::string> args, RTLIL::Design *d) override
|
||||||
|
@ -115,13 +118,12 @@ struct AbcNewPass : public ScriptPass {
|
||||||
|
|
||||||
log_header(d, "Executing ABC_NEW pass.\n");
|
log_header(d, "Executing ABC_NEW pass.\n");
|
||||||
log_push();
|
log_push();
|
||||||
top_tmpdir = cleanup ? (get_base_tmpdir() + "/") : "_tmp_";
|
std::string lib_tmpdir = tmp_base(cleanup) + "yosys-abc-lib-XXXXXX";
|
||||||
top_tmpdir += proc_program_prefix() + "yosys-abc-XXXXXX";
|
lib_tmpdir = make_temp_dir(lib_tmpdir);
|
||||||
top_tmpdir = make_temp_dir(top_tmpdir);
|
lib_to_tmp(lib_tmpdir, liberty_files);
|
||||||
lib_to_tmp();
|
|
||||||
run_script(d, run_from, run_to);
|
run_script(d, run_from, run_to);
|
||||||
if (cleanup)
|
if (cleanup)
|
||||||
remove_directory(top_tmpdir);
|
remove_directory(lib_tmpdir);
|
||||||
log_pop();
|
log_pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,12 +159,15 @@ struct AbcNewPass : public ScriptPass {
|
||||||
run("foreach module in selection");
|
run("foreach module in selection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto f : liberty_files)
|
||||||
|
abc_exe_options += stringf(" -liberty %s", f.c_str());
|
||||||
|
|
||||||
for (auto mod : selected_modules) {
|
for (auto mod : selected_modules) {
|
||||||
std::string tmpdir = "<abc-temp-dir>/<mod-dir>";
|
std::string tmpdir = "<abc-temp-dir>/<mod-dir>";
|
||||||
std::string modname = "<module>";
|
std::string modname = "<module>";
|
||||||
std::string exe_options = "[options]";
|
std::string exe_options = "[options]";
|
||||||
if (!help_mode) {
|
if (!help_mode) {
|
||||||
tmpdir = top_tmpdir + "/XXXXXX";
|
tmpdir = tmp_base(cleanup) + "yosys-abc-XXXXXX";
|
||||||
tmpdir = make_temp_dir(tmpdir);
|
tmpdir = make_temp_dir(tmpdir);
|
||||||
modname = mod->name.str();
|
modname = mod->name.str();
|
||||||
exe_options = abc_exe_options;
|
exe_options = abc_exe_options;
|
||||||
|
@ -202,6 +207,11 @@ struct AbcNewPass : public ScriptPass {
|
||||||
run("abc9_ops -prep_box");
|
run("abc9_ops -prep_box");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cleanup)
|
||||||
|
{
|
||||||
|
log("Removing temp directory.\n");
|
||||||
|
remove_directory(tmpdir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!help_mode) {
|
if (!help_mode) {
|
||||||
|
@ -209,44 +219,8 @@ struct AbcNewPass : public ScriptPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanup)
|
|
||||||
{
|
|
||||||
log("Removing temp directory.\n");
|
|
||||||
remove_directory(top_tmpdir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lib_to_tmp()
|
|
||||||
{
|
|
||||||
for (auto f : liberty_files) {
|
|
||||||
bool ends_gz = false;
|
|
||||||
auto dot_pos = f.find_last_of(".");
|
|
||||||
if(dot_pos != std::string::npos)
|
|
||||||
ends_gz = f.substr(dot_pos+1) == "gz";
|
|
||||||
log_debug("Does %s end with .gz? %d\n", f.c_str(), ends_gz);
|
|
||||||
if (ends_gz) {
|
|
||||||
auto filename_pos = f.find_last_of("/");
|
|
||||||
if(filename_pos == std::string::npos)
|
|
||||||
filename_pos = f.find_last_of("\\");
|
|
||||||
if(filename_pos == std::string::npos) {
|
|
||||||
filename_pos = 0;
|
|
||||||
} else {
|
|
||||||
filename_pos++;
|
|
||||||
}
|
|
||||||
std::istream* s = uncompressed(f);
|
|
||||||
std::string base = f.substr(filename_pos, dot_pos - filename_pos);
|
|
||||||
log_debug("base %s\n", base.c_str());
|
|
||||||
std::string tmp_f = top_tmpdir + "/" + base + "-XXXXXX";
|
|
||||||
tmp_f = make_temp_file(tmp_f);
|
|
||||||
log_debug("tmp_f %s\n", tmp_f.c_str());
|
|
||||||
std::ofstream out(tmp_f);
|
|
||||||
out << s->rdbuf();
|
|
||||||
abc_exe_options += stringf(" -liberty %s", tmp_f.c_str());
|
|
||||||
} else {
|
|
||||||
abc_exe_options += stringf(" -liberty %s", f.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} AbcNewPass;
|
} AbcNewPass;
|
||||||
|
|
||||||
PRIVATE_NAMESPACE_END
|
PRIVATE_NAMESPACE_END
|
||||||
|
|
Loading…
Reference in New Issue