Skip to content

Commit

Permalink
dump color count and better handling of unknown IOs
Browse files Browse the repository at this point in the history
  • Loading branch information
renau committed Dec 29, 2023
1 parent 09004c6 commit e55af88
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 18 deletions.
69 changes: 51 additions & 18 deletions inou/yosys/lgyosys_tolg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static Node resolve_memory(Lgraph *g, RTLIL::Cell *cell) {
return node;
}

static bool is_black_box_output(const RTLIL::Module *mod, const RTLIL::Cell *cell, const RTLIL::IdString &port_name) {
static bool is_black_box_output(const RTLIL::Cell *cell, const RTLIL::IdString &port_name) {
const RTLIL::Wire *wire = cell->getPort(port_name).chunks()[0].wire;

// constant
Expand Down Expand Up @@ -644,17 +644,10 @@ static bool is_black_box_output(const RTLIL::Module *mod, const RTLIL::Cell *cel
return false;
}

::Lgraph::error(
"Could not find a definition for module {}, treating as a blackbox but could not determine whether {} is an output",
cell->type.str(),
port_name.str());

log_error("output unknown port %s at module %s cell %s\n", port_name.c_str(), mod->name.c_str(), cell->type.c_str());
I(false); // TODO: is it possible to resolve this case?
return false;
}

static bool is_black_box_input(const RTLIL::Module *mod, const RTLIL::Cell *cell, const RTLIL::IdString &port_name) {
static bool is_black_box_input(const RTLIL::Cell *cell, const RTLIL::IdString &port_name) {
const RTLIL::Wire *wire = cell->getPort(port_name).chunks()[0].wire;

// constant
Expand Down Expand Up @@ -683,13 +676,6 @@ static bool is_black_box_input(const RTLIL::Module *mod, const RTLIL::Cell *cell
return true;
}

::Lgraph::error(
"Could not find a definition for module {}, treating as a blackbox but could not determine whether {} is an input",
cell->type.str(),
port_name.str());

log_error("input unknown port %s at module %s cell %s\n", port_name.c_str(), mod->name.c_str(), cell->type.c_str());
I(false); // TODO: is it possible to resolve this case?
return false;
}

Expand Down Expand Up @@ -774,10 +760,43 @@ static void process_cell_drivers_intialization(RTLIL::Module *mod, Lgraph *g) {
#endif
} else {
if (!sub->has_pin(pin_name)) {
if (cell->input(conn.first) || is_black_box_input(mod, cell, conn.first)) {
if (cell->input(conn.first) || is_black_box_input(cell, conn.first)) {
sub->add_input_pin(pin_name);
} else if (cell->output(conn.first) || is_black_box_output(mod, cell, conn.first)) {
} else if (cell->output(conn.first) || is_black_box_output(cell, conn.first)) {
sub->add_output_pin(pin_name);
} else if (conn.second.is_fully_undef()) {
sub->add_output_pin(pin_name);
} else if (conn.second.is_fully_const()) {
sub->add_input_pin(pin_name);
} else {
bool is_input = false;
bool is_output = false;
for (auto &chunk : conn.second.chunks()) {
const RTLIL::Wire *wire = chunk.wire;
if (wire->port_input) {
is_input = true;
}
// WARNING: Not always
if (wire->port_output) {
is_output = true;
}
if (driven_signals.count(wire->hash()) != 0) {
is_input = true;
}
}
if (is_input && !is_output) {
sub->add_input_pin(pin_name);
} else if (!is_input && is_output) {
sub->add_output_pin(pin_name);
} else {
log_error("unknown port %s at module %s cell %s\n", conn.first.c_str(), mod->name.c_str(), cell->type.c_str());

::Lgraph::error(
"Could not find a definition for module {}, treating as a blackbox but could not determine whether {} is an "
"output",
cell->type.str(),
conn.first.str());
}
}
}

Expand Down Expand Up @@ -2514,6 +2533,20 @@ struct Yosys2lg_Pass : public Yosys::Pass {

TRACE_EVENT("inou", nullptr, [&mod_name](perfetto::EventContext ctx) { ctx.event()->set_name("YOSYS_tolg_" + mod_name); });

// Populate the driven_signals (only needed for unknown modules)
for (const auto &conn : mod->connections()) {
const RTLIL::SigSpec lhs = conn.first;
for (auto &lchunk : lhs.chunks()) {
const RTLIL::Wire *lhs_wire = lchunk.wire;

if (lchunk.width == 0) {
continue;
}
// fmt::print("Assignment to {}\n", lhs_wire->name.c_str());
driven_signals.insert(lhs_wire->hash());
}
}

for (const auto &port : mod->ports) {
RTLIL::Wire *wire = mod->wire(port);
// std::string wire_name(&wire->name.c_str()[1]);
Expand Down
10 changes: 10 additions & 0 deletions lgraph/lgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,13 @@ void Lgraph::dump(bool hier) {

fmt::print("\n");

absl::flat_hash_map<int, int> color_count;

for (auto node : fast(hier)) {
if (node.has_color()) {
++color_count[node.get_color()];
}

node.dump();
}

Expand All @@ -1728,6 +1734,10 @@ void Lgraph::dump(bool hier) {

return true;
});

for (const auto cit : color_count) {
fmt::print("color:{} count:{}\n", cit.first, cit.second);
}
}

void Lgraph::dump_down_nodes() {
Expand Down

0 comments on commit e55af88

Please sign in to comment.