Skip to content

Commit 2a3f60b

Browse files
committed
abc_new: Support abc9_box mode on ordinary design hierarchy
Previously the `abc9_box` mode was reserved to modules with the `blackbox` or `whitebox` attribute. Allow `abc9_box` on ordinary modules when doing hierarchical synthesis.
1 parent 285f24d commit 2a3f60b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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: 37 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};
@@ -154,6 +183,13 @@ struct AbcNewPass : public ScriptPass {
154183
if (!help_mode) {
155184
active_design->selection().selected_modules.clear();
156185
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+
}
157193
}
158194
}
159195

0 commit comments

Comments
 (0)