Skip to content

Commit ea38fcc

Browse files
authored
Merge pull request #4737 from povik/abc_new-design-boxes
Support `abc9_box` on ordinary modules in abc_new
2 parents e9c7967 + 0bb139d commit ea38fcc

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

backends/aiger2/aiger.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,8 @@ struct XAigerAnalysis : Index<XAigerAnalysis, int, 0, 0> {
832832
return false;
833833

834834
Cell *driver = bit.wire->driverCell();
835-
if (!driver->type.isPublic())
836-
return false;
837-
838835
Module *mod = design->module(driver->type);
839-
log_assert(mod);
840-
if (!mod->has_attribute(ID::abc9_box_id))
836+
if (!mod || !mod->has_attribute(ID::abc9_box_id))
841837
return false;
842838

843839
int max = 1;
@@ -870,7 +866,7 @@ struct XAigerAnalysis : Index<XAigerAnalysis, int, 0, 0> {
870866
HierCursor cursor;
871867
for (auto box : top_minfo->found_blackboxes) {
872868
Module *def = design->module(box->type);
873-
if (!box->type.isPublic() || (def && !def->has_attribute(ID::abc9_box_id)))
869+
if (!(def && def->has_attribute(ID::abc9_box_id)))
874870
for (auto &conn : box->connections_)
875871
if (box->output(conn.first))
876872
for (auto bit : conn.second)
@@ -885,7 +881,7 @@ struct XAigerAnalysis : Index<XAigerAnalysis, int, 0, 0> {
885881

886882
for (auto box : top_minfo->found_blackboxes) {
887883
Module *def = design->module(box->type);
888-
if (!box->type.isPublic() || (def && !def->has_attribute(ID::abc9_box_id)))
884+
if (!(def && def->has_attribute(ID::abc9_box_id)))
889885
for (auto &conn : box->connections_)
890886
if (box->input(conn.first))
891887
for (auto bit : conn.second)
@@ -1106,7 +1102,7 @@ struct XAigerWriter : AigerWriter {
11061102
holes_module->ports.push_back(w->name);
11071103
holes_pis.push_back(w);
11081104
}
1109-
in_conn.append(holes_pis[i]);
1105+
in_conn.append(holes_pis[holes_pi_idx]);
11101106
holes_pi_idx++;
11111107
}
11121108
holes_wb->setPort(port_id, in_conn);

frontends/aiger2/xaiger.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ struct Xaiger2Frontend : public Frontend {
203203
/* unused box_id = */ read_be32(*f);
204204
auto box_seq = read_be32(*f);
205205

206-
log("box_seq=%d boxes.size=%d\n", box_seq, (int) boxes.size());
207206
log_assert(box_seq < boxes.size());
208207

209208
auto [cell, def] = boxes[box_seq];

passes/techmap/abc9_ops.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,8 @@ void prep_box(RTLIL::Design *design)
10781078
}
10791079

10801080
ss << log_id(module) << " " << module->attributes.at(ID::abc9_box_id).as_int();
1081-
ss << " " << (module->get_bool_attribute(ID::whitebox) ? "1" : "0");
1081+
bool has_model = module->get_bool_attribute(ID::whitebox) || !module->get_bool_attribute(ID::blackbox);
1082+
ss << " " << (has_model ? "1" : "0");
10821083
ss << " " << GetSize(inputs) << " " << GetSize(outputs) << std::endl;
10831084

10841085
bool first = true;

passes/techmap/abc_new.cc

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,29 @@
1919

2020
#include "kernel/register.h"
2121
#include "kernel/rtlil.h"
22+
#include "kernel/utils.h"
2223

2324
USING_YOSYS_NAMESPACE
2425
PRIVATE_NAMESPACE_BEGIN
2526

27+
std::vector<Module*> order_modules(Design *design, std::vector<Module *> modules)
28+
{
29+
std::set<Module *> modules_set(modules.begin(), modules.end());
30+
TopoSort<Module*> sort;
31+
32+
for (auto m : modules) {
33+
sort.node(m);
34+
35+
for (auto cell : m->cells()) {
36+
Module *submodule = design->module(cell->type);
37+
if (modules_set.count(submodule))
38+
sort.edge(submodule, m);
39+
}
40+
}
41+
log_assert(sort.sort());
42+
return sort.sorted;
43+
}
44+
2645
struct AbcNewPass : public ScriptPass {
2746
AbcNewPass() : ScriptPass("abc_new", "(experimental) use ABC for SC technology mapping (new)")
2847
{
@@ -101,6 +120,15 @@ struct AbcNewPass : public ScriptPass {
101120
}
102121

103122
if (check_label("prep_boxes")) {
123+
if (!help_mode) {
124+
for (auto mod : active_design->selected_whole_modules_warn()) {
125+
if (mod->get_bool_attribute(ID::abc9_box)) {
126+
mod->set_bool_attribute(ID::abc9_box, false);
127+
mod->set_bool_attribute(ID(abc9_deferred_box), true);
128+
}
129+
}
130+
}
131+
104132
run("box_derive");
105133
run("abc9_ops -prep_box");
106134
}
@@ -109,7 +137,8 @@ struct AbcNewPass : public ScriptPass {
109137
std::vector<Module *> selected_modules;
110138

111139
if (!help_mode) {
112-
selected_modules = active_design->selected_whole_modules_warn();
140+
selected_modules = order_modules(active_design,
141+
active_design->selected_whole_modules_warn());
113142
active_design->selection_stack.emplace_back(false);
114143
} else {
115144
selected_modules = {nullptr};
@@ -131,15 +160,36 @@ struct AbcNewPass : public ScriptPass {
131160
active_design->selection().select(mod);
132161
}
133162

163+
std::string script_save;
164+
if (!help_mode && mod->has_attribute(ID(abc9_script))) {
165+
script_save = active_design->scratchpad_get_string("abc9.script");
166+
active_design->scratchpad_set_string("abc9.script",
167+
mod->get_string_attribute(ID(abc9_script)));
168+
}
169+
134170
run(stringf(" abc9_ops -write_box %s/input.box", tmpdir.c_str()));
135171
run(stringf(" write_xaiger2 -mapping_prep -map2 %s/input.map2 %s/input.xaig", tmpdir.c_str(), tmpdir.c_str()));
136172
run(stringf(" abc9_exe %s -cwd %s -box %s/input.box", exe_options.c_str(), tmpdir.c_str(), tmpdir.c_str()));
137173
run(stringf(" read_xaiger2 -sc_mapping -module_name %s -map2 %s/input.map2 %s/output.aig",
138174
modname.c_str(), tmpdir.c_str(), tmpdir.c_str()));
139175

176+
if (!help_mode && mod->has_attribute(ID(abc9_script))) {
177+
if (script_save.empty())
178+
active_design->scratchpad_unset("abc9.script");
179+
else
180+
active_design->scratchpad_set_string("abc9.script", script_save);
181+
}
182+
140183
if (!help_mode) {
141184
active_design->selection().selected_modules.clear();
142185
log_pop();
186+
187+
if (mod->get_bool_attribute(ID(abc9_deferred_box))) {
188+
mod->set_bool_attribute(ID(abc9_deferred_box), false);
189+
mod->set_bool_attribute(ID::abc9_box, true);
190+
Pass::call_on_module(active_design, mod, "portarcs -draw -write");
191+
run("abc9_ops -prep_box");
192+
}
143193
}
144194
}
145195

0 commit comments

Comments
 (0)