2019-12-28 07:07:46 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
* (C) 2019 Eddie Hung <eddie@fpgeh.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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-02-08 15:23:54 -06:00
|
|
|
// [[CITE]] ABC
|
|
|
|
// Berkeley Logic Synthesis and Verification Group, ABC: A System for Sequential Synthesis and Verification
|
|
|
|
// http://www.eecs.berkeley.edu/~alanmi/abc/
|
|
|
|
|
2019-12-28 07:07:46 -06:00
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/celltypes.h"
|
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
|
2020-01-13 11:22:42 -06:00
|
|
|
// abc9_exe.cc
|
|
|
|
std::string fold_abc9_cmd(std::string str);
|
2019-02-08 15:23:54 -06:00
|
|
|
|
2019-12-28 07:07:46 -06:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct Abc9Pass : public ScriptPass
|
|
|
|
{
|
|
|
|
Abc9Pass() : ScriptPass("abc9", "use ABC9 for technology mapping") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void on_register() override
|
2020-01-09 19:10:54 -06:00
|
|
|
{
|
2020-01-09 19:17:47 -06:00
|
|
|
RTLIL::constpad["abc9.script.default"] = "+&scorr; &sweep; &dc2; &dch -f; &ps; &if {C} {W} {D} {R} -v; &mfs";
|
|
|
|
RTLIL::constpad["abc9.script.default.area"] = "+&scorr; &sweep; &dc2; &dch -f; &ps; &if {C} {W} {D} {R} -a -v; &mfs";
|
2020-01-09 19:49:56 -06:00
|
|
|
RTLIL::constpad["abc9.script.default.fast"] = "+&if {C} {W} {D} {R} -v";
|
2020-01-09 19:10:54 -06:00
|
|
|
// Based on ABC's &flow
|
2020-01-09 19:17:47 -06:00
|
|
|
RTLIL::constpad["abc9.script.flow"] = "+&scorr; &sweep;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
"&dch -C 500;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
/* Round 1 */ \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 1 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
"&st; &dsdb;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 2 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
"&st; &syn2 -m -R 10; &dsdb;" \
|
|
|
|
"&blut -a -K 6;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 3 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
/* Round 2 */ \
|
|
|
|
"&st; &sopb;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 1 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
"&st; &dsdb;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 2 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
"&st; &syn2 -m -R 10; &dsdb;" \
|
|
|
|
"&blut -a -K 6;" \
|
2020-01-09 20:16:58 -06:00
|
|
|
/* Map 3 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
|
|
|
/* Round 3 */ \
|
|
|
|
/* Map 1 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
|
|
|
"&st; &dsdb;" \
|
|
|
|
/* Map 2 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;" \
|
|
|
|
"&st; &syn2 -m -R 10; &dsdb;" \
|
|
|
|
"&blut -a -K 6;" \
|
|
|
|
/* Map 3 */ "&unmap; &if {C} {W} {D} {R} -v; &save; &load; &mfs;";
|
2020-01-09 19:10:54 -06:00
|
|
|
// Based on ABC's &flow2
|
2020-01-09 19:17:47 -06:00
|
|
|
RTLIL::constpad["abc9.script.flow2"] = "+&scorr; &sweep;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
/* Comm1 */ "&synch2 -K 6 -C 500; &if -m {C} {W} {D} {R} -v; &mfs "/*"-W 4 -M 500 -C 7000"*/"; &save;"\
|
|
|
|
/* Comm2 */ "&dch -C 500; &if -m {C} {W} {D} {R} -v; &mfs "/*"-W 4 -M 500 -C 7000"*/"; &save;"\
|
|
|
|
"&load; &st; &sopb -R 10 -C 4; " \
|
|
|
|
/* Comm3 */ "&synch2 -K 6 -C 500; &if -m "/*"-E 5"*/" {C} {W} {D} {R} -v; &mfs "/*"-W 4 -M 500 -C 7000"*/"; &save;"\
|
|
|
|
/* Comm2 */ "&dch -C 500; &if -m {C} {W} {D} {R} -v; &mfs "/*"-W 4 -M 500 -C 7000"*/"; &save; "\
|
|
|
|
"&load";
|
|
|
|
// Based on ABC's &flow3
|
2020-01-09 19:17:47 -06:00
|
|
|
RTLIL::constpad["abc9.script.flow3"] = "+&scorr; &sweep;" \
|
2020-01-09 19:10:54 -06:00
|
|
|
"&if {C} {W} {D}; &save; &st; &syn2; &if {C} {W} {D} {R} -v; &save; &load;"\
|
|
|
|
"&st; &if {C} -g -K 6; &dch -f; &if {C} {W} {D} {R} -v; &save; &load;"\
|
|
|
|
"&st; &if {C} -g -K 6; &synch2; &if {C} {W} {D} {R} -v; &save; &load;"\
|
|
|
|
"&mfs";
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2019-12-28 07:07:46 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" abc9 [options] [selection]\n");
|
|
|
|
log("\n");
|
2020-01-11 10:42:58 -06:00
|
|
|
log("This script pass performs a sequence of commands to facilitate the use of the ABC\n");
|
|
|
|
log("tool [1] for technology mapping of the current design to a target FPGA\n");
|
|
|
|
log("architecture. Only fully-selected modules are supported.\n");
|
2019-12-28 07:07:46 -06:00
|
|
|
log("\n");
|
2020-01-13 21:22:23 -06:00
|
|
|
log(" -run <from_label>:<to_label>\n");
|
|
|
|
log(" only run the commands between the labels (see below). an empty\n");
|
|
|
|
log(" from label is synonymous to 'begin', and empty to label is\n");
|
|
|
|
log(" synonymous to the end of the command list.\n");
|
|
|
|
log("\n");
|
2019-12-28 07:07:46 -06:00
|
|
|
log(" -exe <command>\n");
|
|
|
|
#ifdef ABCEXTERNAL
|
|
|
|
log(" use the specified command instead of \"" ABCEXTERNAL "\" to execute ABC.\n");
|
|
|
|
#else
|
2020-04-10 03:38:40 -05:00
|
|
|
log(" use the specified command instead of \"<yosys-bindir>/%syosys-abc\" to execute ABC.\n", proc_program_prefix().c_str());
|
2019-12-28 07:07:46 -06:00
|
|
|
#endif
|
|
|
|
log(" This can e.g. be used to call a specific version of ABC or a wrapper.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -script <file>\n");
|
|
|
|
log(" use the specified ABC script file instead of the default script.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" if <file> starts with a plus sign (+), then the rest of the filename\n");
|
|
|
|
log(" string is interpreted as the command string to be passed to ABC. The\n");
|
|
|
|
log(" leading plus sign is removed and all commas (,) in the string are\n");
|
|
|
|
log(" replaced with blanks before the string is passed to ABC.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" if no -script parameter is given, the following scripts are used:\n");
|
2020-01-11 14:11:35 -06:00
|
|
|
log("%s\n", fold_abc9_cmd(RTLIL::constpad.at("abc9.script.default").substr(1,std::string::npos)).c_str());
|
2019-12-28 07:07:46 -06:00
|
|
|
log("\n");
|
|
|
|
log(" -fast\n");
|
|
|
|
log(" use different default scripts that are slightly faster (at the cost\n");
|
|
|
|
log(" of output quality):\n");
|
2020-01-11 14:11:35 -06:00
|
|
|
log("%s\n", fold_abc9_cmd(RTLIL::constpad.at("abc9.script.default.fast").substr(1,std::string::npos)).c_str());
|
2019-12-28 07:07:46 -06:00
|
|
|
log("\n");
|
|
|
|
log(" -D <picoseconds>\n");
|
|
|
|
log(" set delay target. the string {D} in the default scripts above is\n");
|
|
|
|
log(" replaced by this option when used, and an empty string otherwise\n");
|
|
|
|
log(" (indicating best possible delay).\n");
|
|
|
|
log("\n");
|
|
|
|
// log(" -S <num>\n");
|
|
|
|
// log(" maximum number of LUT inputs shared.\n");
|
|
|
|
// log(" (replaces {S} in the default scripts above, default: -S 1)\n");
|
|
|
|
// log("\n");
|
|
|
|
log(" -lut <width>\n");
|
|
|
|
log(" generate netlist using luts of (max) the specified width.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -lut <w1>:<w2>\n");
|
|
|
|
log(" generate netlist using luts of (max) the specified width <w2>. All\n");
|
|
|
|
log(" luts with width <= <w1> have constant cost. for luts larger than <w1>\n");
|
|
|
|
log(" the area cost doubles with each additional input bit. the delay cost\n");
|
|
|
|
log(" is still constant for all lut widths.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -lut <file>\n");
|
|
|
|
log(" pass this file with lut library to ABC.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -luts <cost1>,<cost2>,<cost3>,<sizeN>:<cost4-N>,..\n");
|
|
|
|
log(" generate netlist using luts. Use the specified costs for luts with 1,\n");
|
|
|
|
log(" 2, 3, .. inputs.\n");
|
|
|
|
log("\n");
|
2020-02-11 10:34:13 -06:00
|
|
|
log(" -maxlut <width>\n");
|
|
|
|
log(" when auto-generating the lut library, discard all luts equal to or\n");
|
|
|
|
log(" greater than this size (applicable when neither -lut nor -luts is\n");
|
|
|
|
log(" specified).\n");
|
|
|
|
log("\n");
|
2020-01-02 14:36:54 -06:00
|
|
|
log(" -dff\n");
|
2020-04-13 11:38:07 -05:00
|
|
|
log(" also pass $_DFF_[NP]_ cells through to ABC. modules with many clock\n");
|
|
|
|
log(" domains are supported and automatically partitioned by ABC.\n");
|
2020-01-01 10:34:43 -06:00
|
|
|
log("\n");
|
2019-12-28 07:07:46 -06:00
|
|
|
log(" -nocleanup\n");
|
|
|
|
log(" when this option is used, the temporary files created by this pass\n");
|
|
|
|
log(" are not removed. this is useful for debugging.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -showtmp\n");
|
|
|
|
log(" print the temp dir name in log. usually this is suppressed so that the\n");
|
|
|
|
log(" command output is identical across runs.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -box <file>\n");
|
2020-01-13 11:22:42 -06:00
|
|
|
log(" pass this file with box library to ABC.\n");
|
2019-12-28 07:07:46 -06:00
|
|
|
log("\n");
|
|
|
|
log("Note that this is a logic optimization pass within Yosys that is calling ABC\n");
|
|
|
|
log("internally. This is not going to \"run ABC on your design\". It will instead run\n");
|
|
|
|
log("ABC on logic snippets extracted from your design. You will not get any useful\n");
|
|
|
|
log("output when passing an ABC script that writes a file. Instead write your full\n");
|
2020-01-02 14:41:57 -06:00
|
|
|
log("design as an XAIGER file with `write_xaiger' and then load that into ABC\n");
|
|
|
|
log("externally if you want to use ABC to convert your design into another format.\n");
|
2019-10-07 17:03:44 -05:00
|
|
|
log("\n");
|
2019-12-28 07:07:46 -06:00
|
|
|
log("[1] http://www.eecs.berkeley.edu/~alanmi/abc/\n");
|
|
|
|
log("\n");
|
|
|
|
help_script();
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
2020-01-06 17:52:59 -06:00
|
|
|
std::stringstream exe_cmd;
|
2020-01-02 17:57:35 -06:00
|
|
|
bool dff_mode, cleanup;
|
2020-02-11 10:34:13 -06:00
|
|
|
bool lut_mode;
|
|
|
|
int maxlut;
|
2020-01-10 13:45:41 -06:00
|
|
|
std::string box_file;
|
2019-12-28 07:07:46 -06:00
|
|
|
|
2020-06-18 18:34:52 -05:00
|
|
|
void clear_flags() override
|
2019-12-28 07:07:46 -06:00
|
|
|
{
|
2020-01-06 17:52:59 -06:00
|
|
|
exe_cmd.str("");
|
|
|
|
exe_cmd << "abc9_exe";
|
2020-01-02 17:57:35 -06:00
|
|
|
dff_mode = false;
|
2019-12-28 07:07:46 -06:00
|
|
|
cleanup = true;
|
2020-02-11 10:34:13 -06:00
|
|
|
lut_mode = false;
|
|
|
|
maxlut = 0;
|
2020-02-13 13:15:59 -06:00
|
|
|
box_file = "";
|
2019-12-28 07:07:46 -06:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2019-12-28 07:07:46 -06:00
|
|
|
{
|
|
|
|
std::string run_from, run_to;
|
|
|
|
clear_flags();
|
|
|
|
|
2020-01-03 07:11:41 -06:00
|
|
|
// get arguments from scratchpad first, then override by command arguments
|
2020-01-06 11:46:02 -06:00
|
|
|
dff_mode = design->scratchpad_get_bool("abc9.dff", dff_mode);
|
2020-01-06 03:46:10 -06:00
|
|
|
cleanup = !design->scratchpad_get_bool("abc9.nocleanup", !cleanup);
|
2020-01-03 07:11:41 -06:00
|
|
|
|
2020-01-10 17:04:13 -06:00
|
|
|
if (design->scratchpad_get_bool("abc9.debug")) {
|
|
|
|
cleanup = false;
|
2020-01-13 11:22:42 -06:00
|
|
|
exe_cmd << " -showtmp";
|
2020-01-10 17:04:13 -06:00
|
|
|
}
|
|
|
|
|
2019-12-28 07:07:46 -06:00
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if ((arg == "-exe" || arg == "-script" || arg == "-D" ||
|
2020-02-11 10:34:13 -06:00
|
|
|
/*arg == "-S" ||*/ arg == "-lut" || arg == "-luts" ||
|
2020-01-10 13:45:41 -06:00
|
|
|
/*arg == "-box" ||*/ arg == "-W") &&
|
2019-12-28 07:07:46 -06:00
|
|
|
argidx+1 < args.size()) {
|
2020-02-11 10:34:13 -06:00
|
|
|
if (arg == "-lut" || arg == "-luts")
|
|
|
|
lut_mode = true;
|
2020-01-06 17:52:59 -06:00
|
|
|
exe_cmd << " " << arg << " " << args[++argidx];
|
2019-12-28 07:07:46 -06:00
|
|
|
continue;
|
|
|
|
}
|
2020-01-02 17:57:35 -06:00
|
|
|
if (arg == "-fast" || /* arg == "-dff" || */
|
2020-01-13 11:22:42 -06:00
|
|
|
/* arg == "-nocleanup" || */ arg == "-showtmp") {
|
2020-01-06 17:52:59 -06:00
|
|
|
exe_cmd << " " << arg;
|
2019-12-28 07:07:46 -06:00
|
|
|
continue;
|
|
|
|
}
|
2020-01-02 14:36:54 -06:00
|
|
|
if (arg == "-dff") {
|
2020-01-02 17:57:35 -06:00
|
|
|
dff_mode = true;
|
2020-01-13 21:22:23 -06:00
|
|
|
exe_cmd << " " << arg;
|
2020-01-01 10:34:43 -06:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-28 07:07:46 -06:00
|
|
|
if (arg == "-nocleanup") {
|
|
|
|
cleanup = false;
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-10 13:45:41 -06:00
|
|
|
if (arg == "-box" && argidx+1 < args.size()) {
|
|
|
|
box_file = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-11 10:34:13 -06:00
|
|
|
if (arg == "-maxlut" && argidx+1 < args.size()) {
|
|
|
|
maxlut = atoi(args[++argidx].c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-13 21:22:23 -06:00
|
|
|
if (arg == "-run" && argidx+1 < args.size()) {
|
|
|
|
size_t pos = args[argidx+1].find(':');
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
break;
|
|
|
|
run_from = args[++argidx].substr(0, pos);
|
|
|
|
run_to = args[argidx].substr(pos+1);
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-28 07:07:46 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2020-02-11 10:34:13 -06:00
|
|
|
if (maxlut && lut_mode)
|
|
|
|
log_cmd_error("abc9 '-maxlut' option only applicable without '-lut' nor '-luts'.\n");
|
|
|
|
|
2020-01-23 21:08:51 -06:00
|
|
|
log_assert(design);
|
|
|
|
if (design->selected_modules().empty()) {
|
|
|
|
log_warning("No modules selected for ABC9 techmapping.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-28 07:07:46 -06:00
|
|
|
log_header(design, "Executing ABC9 pass.\n");
|
2020-01-17 14:00:14 -06:00
|
|
|
log_push();
|
2019-12-28 07:07:46 -06:00
|
|
|
|
|
|
|
run_script(design, run_from, run_to);
|
2020-01-17 14:00:14 -06:00
|
|
|
|
|
|
|
log_pop();
|
2019-12-28 07:07:46 -06:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:34:52 -05:00
|
|
|
void script() override
|
2019-12-28 07:07:46 -06:00
|
|
|
{
|
2020-04-13 11:38:07 -05:00
|
|
|
if (check_label("check")) {
|
2020-04-21 14:22:39 -05:00
|
|
|
if (help_mode)
|
|
|
|
run("abc9_ops -check [-dff]", "(option if -dff)");
|
|
|
|
else
|
|
|
|
run(stringf("abc9_ops -check %s", dff_mode ? "-dff" : ""));
|
2020-04-13 11:38:07 -05:00
|
|
|
}
|
|
|
|
|
2020-04-21 14:22:39 -05:00
|
|
|
if (check_label("map")) {
|
|
|
|
if (help_mode)
|
|
|
|
run("abc9_ops -prep_hier -prep_bypass [-prep_dff -dff]", "(option if -dff)");
|
|
|
|
else
|
|
|
|
run(stringf("abc9_ops -prep_hier -prep_bypass %s", dff_mode ? "-prep_dff -dff" : ""));
|
|
|
|
if (dff_mode) {
|
|
|
|
run("design -copy-to $abc9_map @$abc9_flops", "(only if -dff)");
|
|
|
|
run("select -unset $abc9_flops", " (only if -dff)");
|
|
|
|
}
|
|
|
|
run("design -stash $abc9");
|
|
|
|
run("design -load $abc9_map");
|
|
|
|
run("proc");
|
|
|
|
run("wbflip");
|
2020-05-26 10:37:26 -05:00
|
|
|
run("techmap -wb -map %$abc9 -map +/techmap.v");
|
2020-04-21 14:22:39 -05:00
|
|
|
run("opt");
|
2020-04-21 14:42:09 -05:00
|
|
|
if (dff_mode || help_mode) {
|
2020-04-15 17:41:55 -05:00
|
|
|
if (!help_mode)
|
2020-04-21 14:30:25 -05:00
|
|
|
active_design->scratchpad_unset("abc9_ops.prep_dff_submod.did_something");
|
2020-04-21 14:42:09 -05:00
|
|
|
run("abc9_ops -prep_dff_submod", " (only if -dff)"); // rewrite specify
|
2020-04-21 14:30:25 -05:00
|
|
|
bool did_something = help_mode || active_design->scratchpad_get_bool("abc9_ops.prep_dff_submod.did_something");
|
2020-04-15 17:41:55 -05:00
|
|
|
if (did_something) {
|
|
|
|
// select all $_DFF_[NP]_
|
|
|
|
// then select all its fanins
|
|
|
|
// then select all fanouts of all that
|
|
|
|
// lastly remove $_DFF_[NP]_ cells
|
2020-04-21 14:42:09 -05:00
|
|
|
run("setattr -set submod \"$abc9_flop\" t:$_DFF_?_ %ci* %co* t:$_DFF_?_ %d", " (only if -dff)");
|
|
|
|
run("submod", " (only if -dff)");
|
|
|
|
run("setattr -mod -set whitebox 1 -set abc9_flop 1 -set abc9_box 1 *_$abc9_flop", "(only if -dff)");
|
2020-04-15 17:41:55 -05:00
|
|
|
if (help_mode) {
|
|
|
|
run("foreach module in design");
|
2020-04-21 14:42:09 -05:00
|
|
|
run(" rename <module-name>_$abc9_flop _TECHMAP_REPLACE_", " (only if -dff)");
|
2020-04-15 17:41:55 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Rename all submod-s to _TECHMAP_REPLACE_ to inherit name + attrs
|
|
|
|
for (auto module : active_design->selected_modules()) {
|
|
|
|
active_design->selected_active_module = module->name.str();
|
|
|
|
if (module->cell(stringf("%s_$abc9_flop", module->name.c_str())))
|
|
|
|
run(stringf("rename %s_$abc9_flop _TECHMAP_REPLACE_", module->name.c_str()));
|
|
|
|
}
|
2020-04-21 19:25:15 -05:00
|
|
|
active_design->selected_active_module.clear();
|
2020-04-15 17:41:55 -05:00
|
|
|
}
|
2020-04-21 19:25:15 -05:00
|
|
|
run("abc9_ops -prep_dff_unmap", " (only if -dff)");
|
2020-04-22 19:37:07 -05:00
|
|
|
run("design -copy-to $abc9 =*_$abc9_flop", " (only if -dff)"); // copy submod out
|
|
|
|
run("delete =*_$abc9_flop", " (only if -dff)");
|
2020-04-13 11:38:07 -05:00
|
|
|
}
|
|
|
|
}
|
2020-04-21 14:22:39 -05:00
|
|
|
run("design -stash $abc9_map");
|
|
|
|
run("design -load $abc9");
|
|
|
|
run("design -delete $abc9");
|
2020-04-21 19:54:24 -05:00
|
|
|
if (help_mode)
|
|
|
|
run("techmap -wb -max_iter 1 -map %$abc9_map -map +/abc9_map.v [-D DFF]", "(option if -dff)");
|
|
|
|
else
|
2020-04-22 19:37:07 -05:00
|
|
|
run(stringf("techmap -wb -max_iter 1 -map %%$abc9_map -map +/abc9_map.v %s", dff_mode ? "-D DFF" : ""));
|
2020-04-21 14:22:39 -05:00
|
|
|
run("design -delete $abc9_map");
|
2020-04-13 11:38:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (check_label("pre")) {
|
2020-04-16 12:24:02 -05:00
|
|
|
run("read_verilog -icells -lib -specify +/abc9_model.v");
|
2020-01-08 12:00:50 -06:00
|
|
|
run("scc -set_attr abc9_scc_id {}");
|
|
|
|
if (help_mode)
|
2020-01-14 15:21:58 -06:00
|
|
|
run("abc9_ops -mark_scc -prep_delays -prep_xaiger [-dff]", "(option for -dff)");
|
2020-01-07 10:00:32 -06:00
|
|
|
else
|
2020-04-13 11:38:07 -05:00
|
|
|
run("abc9_ops -mark_scc -prep_delays -prep_xaiger" + std::string(dff_mode ? " -dff" : ""));
|
2020-02-11 10:34:13 -06:00
|
|
|
if (help_mode)
|
|
|
|
run("abc9_ops -prep_lut <maxlut>", "(skip if -lut or -luts)");
|
|
|
|
else if (!lut_mode)
|
|
|
|
run(stringf("abc9_ops -prep_lut %d", maxlut));
|
2020-02-11 10:54:13 -06:00
|
|
|
if (help_mode)
|
2020-04-13 11:38:07 -05:00
|
|
|
run("abc9_ops -prep_box", "(skip if -box)");
|
2020-04-21 14:42:09 -05:00
|
|
|
else if (box_file.empty())
|
2020-04-13 11:38:07 -05:00
|
|
|
run("abc9_ops -prep_box");
|
2020-04-21 14:42:09 -05:00
|
|
|
if (saved_designs.count("$abc9_holes") || help_mode) {
|
|
|
|
run("design -stash $abc9");
|
|
|
|
run("design -load $abc9_holes");
|
|
|
|
run("techmap -wb -map %$abc9 -map +/techmap.v");
|
|
|
|
run("opt -purge");
|
2020-04-21 17:42:05 -05:00
|
|
|
run("aigmap");
|
2020-04-21 14:42:09 -05:00
|
|
|
run("design -stash $abc9_holes");
|
|
|
|
run("design -load $abc9");
|
|
|
|
run("design -delete $abc9");
|
2020-04-13 11:38:07 -05:00
|
|
|
}
|
2020-01-08 12:00:50 -06:00
|
|
|
}
|
2019-12-28 07:07:46 -06:00
|
|
|
|
2020-04-21 14:22:39 -05:00
|
|
|
if (check_label("exe")) {
|
2020-04-15 18:13:57 -05:00
|
|
|
run("aigmap");
|
2020-01-08 12:00:50 -06:00
|
|
|
if (help_mode) {
|
|
|
|
run("foreach module in selection");
|
2020-02-11 10:34:13 -06:00
|
|
|
run(" abc9_ops -write_lut <abc-temp-dir>/input.lut", "(skip if '-lut' or '-luts')");
|
2020-04-09 16:42:43 -05:00
|
|
|
run(" abc9_ops -write_box <abc-temp-dir>/input.box", "(skip if '-box')");
|
2020-04-13 11:38:07 -05:00
|
|
|
run(" write_xaiger -map <abc-temp-dir>/input.sym [-dff] <abc-temp-dir>/input.xaig");
|
|
|
|
run(" abc9_exe [options] -cwd <abc-temp-dir> -lut [<abc-temp-dir>/input.lut] -box [<abc-temp-dir>/input.box]");
|
2020-01-08 12:00:50 -06:00
|
|
|
run(" read_aiger -xaiger -wideports -module_name <module-name>$abc9 -map <abc-temp-dir>/input.sym <abc-temp-dir>/output.aig");
|
2020-04-13 11:38:07 -05:00
|
|
|
run(" abc9_ops -reintegrate [-dff]");
|
2019-12-28 07:07:46 -06:00
|
|
|
}
|
2020-01-08 12:00:50 -06:00
|
|
|
else {
|
|
|
|
auto selected_modules = active_design->selected_modules();
|
|
|
|
active_design->selection_stack.emplace_back(false);
|
2019-12-28 07:07:46 -06:00
|
|
|
|
2020-01-08 12:00:50 -06:00
|
|
|
for (auto mod : selected_modules) {
|
|
|
|
if (mod->processes.size() > 0) {
|
|
|
|
log("Skipping module %s as it contains processes.\n", log_id(mod));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-01-17 14:00:14 -06:00
|
|
|
log_push();
|
2020-01-08 12:00:50 -06:00
|
|
|
active_design->selection().select(mod);
|
|
|
|
|
|
|
|
if (!active_design->selected_whole_module(mod))
|
|
|
|
log_error("Can't handle partially selected module %s!\n", log_id(mod));
|
2019-12-28 07:07:46 -06:00
|
|
|
|
2020-04-10 03:38:40 -05:00
|
|
|
std::string tempdir_name = "/tmp/" + proc_program_prefix() + "yosys-abc-XXXXXX";
|
2020-01-08 12:00:50 -06:00
|
|
|
if (!cleanup)
|
|
|
|
tempdir_name[0] = tempdir_name[4] = '_';
|
|
|
|
tempdir_name = make_temp_dir(tempdir_name);
|
|
|
|
|
2020-02-11 10:34:13 -06:00
|
|
|
if (!lut_mode)
|
2020-03-09 09:34:22 -05:00
|
|
|
run_nocheck(stringf("abc9_ops -write_lut %s/input.lut", tempdir_name.c_str()));
|
2020-04-09 16:42:43 -05:00
|
|
|
if (box_file.empty())
|
|
|
|
run_nocheck(stringf("abc9_ops -write_box %s/input.box", tempdir_name.c_str()));
|
2020-04-13 11:38:07 -05:00
|
|
|
run_nocheck(stringf("write_xaiger -map %s/input.sym %s %s/input.xaig", tempdir_name.c_str(), dff_mode ? "-dff" : "", tempdir_name.c_str()));
|
2020-01-08 12:00:50 -06:00
|
|
|
|
|
|
|
int num_outputs = active_design->scratchpad_get_int("write_xaiger.num_outputs");
|
2020-01-13 11:43:57 -06:00
|
|
|
|
|
|
|
log("Extracted %d AND gates and %d wires from module `%s' to a netlist network with %d inputs and %d outputs.\n",
|
2020-01-08 12:00:50 -06:00
|
|
|
active_design->scratchpad_get_int("write_xaiger.num_ands"),
|
|
|
|
active_design->scratchpad_get_int("write_xaiger.num_wires"),
|
2020-01-13 11:43:57 -06:00
|
|
|
log_id(mod),
|
2020-01-08 12:00:50 -06:00
|
|
|
active_design->scratchpad_get_int("write_xaiger.num_inputs"),
|
|
|
|
num_outputs);
|
|
|
|
if (num_outputs) {
|
2020-02-11 10:34:13 -06:00
|
|
|
std::string abc9_exe_cmd;
|
|
|
|
abc9_exe_cmd += stringf("%s -cwd %s", exe_cmd.str().c_str(), tempdir_name.c_str());
|
|
|
|
if (!lut_mode)
|
|
|
|
abc9_exe_cmd += stringf(" -lut %s/input.lut", tempdir_name.c_str());
|
2020-04-09 16:42:43 -05:00
|
|
|
if (box_file.empty())
|
|
|
|
abc9_exe_cmd += stringf(" -box %s/input.box", tempdir_name.c_str());
|
|
|
|
else
|
|
|
|
abc9_exe_cmd += stringf(" -box %s", box_file.c_str());
|
2020-03-09 09:34:22 -05:00
|
|
|
run_nocheck(abc9_exe_cmd);
|
|
|
|
run_nocheck(stringf("read_aiger -xaiger -wideports -module_name %s$abc9 -map %s/input.sym %s/output.aig", log_id(mod), tempdir_name.c_str(), tempdir_name.c_str()));
|
2020-04-13 11:38:07 -05:00
|
|
|
run_nocheck(stringf("abc9_ops -reintegrate %s", dff_mode ? "-dff" : ""));
|
2020-01-08 12:00:50 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
log("Don't call ABC as there is nothing to map.\n");
|
|
|
|
|
|
|
|
if (cleanup) {
|
|
|
|
log("Removing temp directory.\n");
|
|
|
|
remove_directory(tempdir_name);
|
|
|
|
}
|
2020-03-09 09:34:22 -05:00
|
|
|
mod->check();
|
2020-01-08 12:00:50 -06:00
|
|
|
active_design->selection().selected_modules.clear();
|
2020-01-17 14:00:14 -06:00
|
|
|
log_pop();
|
2020-01-08 12:00:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
active_design->selection_stack.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 11:38:07 -05:00
|
|
|
|
2020-04-21 14:22:39 -05:00
|
|
|
if (check_label("unmap")) {
|
|
|
|
run("techmap -wb -map %$abc9_unmap -map +/abc9_unmap.v"); // techmap user design from submod back to original cell
|
2020-04-13 11:38:07 -05:00
|
|
|
// ($_DFF_[NP]_ already shorted by -reintegrate)
|
2020-04-21 14:22:39 -05:00
|
|
|
run("design -delete $abc9_unmap");
|
2020-04-15 18:13:57 -05:00
|
|
|
if (saved_designs.count("$abc9_holes") || help_mode)
|
|
|
|
run("design -delete $abc9_holes");
|
2020-04-13 11:38:07 -05:00
|
|
|
}
|
2019-12-28 07:07:46 -06:00
|
|
|
}
|
|
|
|
} Abc9Pass;
|
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|