Skip to content

Commit

Permalink
flatten: add -barriers flag
Browse files Browse the repository at this point in the history
* This uses $barrier optimization barriers to connect wires into the
  flattened module instead of connections
  • Loading branch information
georgerennie committed Nov 20, 2024
1 parent 73ba5da commit c352f71
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion passes/techmap/flatten.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct FlattenWorker
bool ignore_wb = false;
bool create_scopeinfo = true;
bool create_scopename = false;
bool barriers = false;

template<class T>
void map_attributes(RTLIL::Cell *cell, T *object, IdString orig_object_name)
Expand Down Expand Up @@ -246,7 +247,27 @@ struct FlattenWorker
log_error("Cell port %s.%s.%s is driving constant bits: %s <= %s\n",
log_id(module), log_id(cell), log_id(port_it.first), log_signal(new_conn.first), log_signal(new_conn.second));

module->connect(new_conn);
if (barriers) {
// Drive public output wires with barriers and the rest with
// connections
RTLIL::SigSig skip_conn, barrier_conn;

for (int i = 0; i < GetSize(new_conn.first); i++) {
const auto lhs = new_conn.first[i], rhs = new_conn.second[i];
auto& sigsig = !lhs.is_wire() || !lhs.wire->name.isPublic() ? skip_conn : barrier_conn;
sigsig.first.append(lhs);
sigsig.second.append(rhs);
}

if (!skip_conn.first.empty())
module->connect(skip_conn);

if (!barrier_conn.first.empty())
module->addBarrier(NEW_ID, barrier_conn.second, barrier_conn.first);
} else {
module->connect(new_conn);
}

sigmap.add(new_conn.first, new_conn.second);
}

Expand Down Expand Up @@ -345,6 +366,10 @@ struct FlattenPass : public Pass {
log(" with a public name the enclosing scope can be found via their\n");
log(" 'hdlname' attribute.\n");
log("\n");
log(" -barriers\n");
log(" Use $barrier cells to connect flattened modules to their surrounding\n");
log(" scope instead of connections for public wires.\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
Expand All @@ -367,6 +392,10 @@ struct FlattenPass : public Pass {
worker.create_scopename = true;
continue;
}
if (args[argidx] == "-barriers") {
worker.barriers = true;
continue;
}
break;
}
extra_args(args, argidx, design);
Expand Down

0 comments on commit c352f71

Please sign in to comment.