2018-06-10 00:19:20 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-13 22:52:21 +08:00
|
|
|
#include <cmath>
|
2018-06-10 00:19:20 +08:00
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "route.h"
|
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
USING_NEXTPNR_NAMESPACE
|
2018-06-12 20:24:59 +08:00
|
|
|
|
2018-06-10 00:19:20 +08:00
|
|
|
struct QueuedWire
|
|
|
|
{
|
|
|
|
WireId wire;
|
|
|
|
PipId pip;
|
2018-06-13 22:52:21 +08:00
|
|
|
|
2018-06-16 21:23:04 +08:00
|
|
|
delay_t delay = 0, togo = 0;
|
2018-06-19 18:49:40 +08:00
|
|
|
int randtag = 0;
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-12 20:24:59 +08:00
|
|
|
struct Greater
|
2018-06-10 00:19:20 +08:00
|
|
|
{
|
2018-06-12 20:24:59 +08:00
|
|
|
bool operator()(const QueuedWire &lhs, const QueuedWire &rhs) const
|
|
|
|
noexcept
|
|
|
|
{
|
2018-06-19 18:49:40 +08:00
|
|
|
delay_t l = lhs.delay + lhs.togo, r = rhs.delay + rhs.togo;
|
|
|
|
return l == r ? lhs.randtag > rhs.randtag : l > r;
|
2018-06-12 20:24:59 +08:00
|
|
|
}
|
|
|
|
};
|
2018-06-10 00:19:20 +08:00
|
|
|
};
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
void ripup_net(Context *ctx, IdString net_name)
|
2018-06-10 00:19:20 +08:00
|
|
|
{
|
2018-06-18 20:06:37 +08:00
|
|
|
auto net_info = ctx->nets.at(net_name);
|
2018-06-13 22:52:21 +08:00
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
for (auto &it : net_info->wires) {
|
|
|
|
if (it.second != PipId())
|
2018-06-18 20:06:37 +08:00
|
|
|
ctx->unbindPip(it.second);
|
|
|
|
ctx->unbindWire(it.first);
|
2018-06-14 21:09:13 +08:00
|
|
|
}
|
2018-06-14 00:28:02 +08:00
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
net_info->wires.clear();
|
|
|
|
}
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
struct Router
|
|
|
|
{
|
|
|
|
std::unordered_set<IdString> rippedNets;
|
|
|
|
int visitCnt = 0, revisitCnt = 0;
|
|
|
|
bool routedOkay = false;
|
2018-06-16 21:23:04 +08:00
|
|
|
delay_t maxDelay = 0.0;
|
2018-06-18 17:58:37 +08:00
|
|
|
WireId failedDest;
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 19:40:35 +08:00
|
|
|
Router(Context *ctx, IdString net_name, bool ripup = false,
|
|
|
|
delay_t ripup_penalty = 0)
|
2018-06-14 21:09:13 +08:00
|
|
|
{
|
2018-06-18 20:06:37 +08:00
|
|
|
auto net_info = ctx->nets.at(net_name);
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-18 21:53:18 +08:00
|
|
|
log("Routing net %s.\n", net_name.c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-18 21:53:18 +08:00
|
|
|
log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx),
|
|
|
|
net_info->driver.port.c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
auto src_bel = net_info->driver.cell->bel;
|
|
|
|
|
|
|
|
if (src_bel == BelId())
|
2018-06-13 23:26:03 +08:00
|
|
|
log_error("Source cell %s (%s) is not mapped to a bel.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
net_info->driver.cell->name.c_str(ctx),
|
|
|
|
net_info->driver.cell->type.c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-18 21:53:18 +08:00
|
|
|
log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-13 23:52:18 +08:00
|
|
|
IdString driver_port = net_info->driver.port;
|
|
|
|
|
|
|
|
auto driver_port_it = net_info->driver.cell->pins.find(driver_port);
|
|
|
|
if (driver_port_it != net_info->driver.cell->pins.end())
|
|
|
|
driver_port = driver_port_it->second;
|
|
|
|
|
2018-06-18 22:08:19 +08:00
|
|
|
auto src_wire =
|
|
|
|
ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
if (src_wire == WireId())
|
2018-06-14 00:10:09 +08:00
|
|
|
log_error("No wire found for port %s (pin %s) on source cell %s "
|
|
|
|
"(bel %s).\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
net_info->driver.port.c_str(ctx), driver_port.c_str(ctx),
|
|
|
|
net_info->driver.cell->name.c_str(ctx),
|
|
|
|
ctx->getBelName(src_bel).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-18 21:53:18 +08:00
|
|
|
log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-12 01:56:33 +08:00
|
|
|
std::unordered_map<WireId, DelayInfo> src_wires;
|
2018-06-10 00:19:20 +08:00
|
|
|
src_wires[src_wire] = DelayInfo();
|
|
|
|
net_info->wires[src_wire] = PipId();
|
2018-06-18 20:06:37 +08:00
|
|
|
ctx->bindWire(src_wire, net_name);
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
std::vector<PortRef> users_array = net_info->users;
|
|
|
|
ctx->shuffle(users_array);
|
|
|
|
|
|
|
|
for (auto &user_it : users_array) {
|
|
|
|
if (ctx->verbose)
|
2018-06-18 21:53:18 +08:00
|
|
|
log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx),
|
|
|
|
user_it.port.c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
auto dst_bel = user_it.cell->bel;
|
|
|
|
|
|
|
|
if (dst_bel == BelId())
|
2018-06-14 00:10:09 +08:00
|
|
|
log_error("Destination cell %s (%s) is not mapped to a bel.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
user_it.cell->name.c_str(ctx),
|
|
|
|
user_it.cell->type.c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-13 22:52:21 +08:00
|
|
|
log(" Destination bel: %s\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getBelName(dst_bel).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-13 23:52:18 +08:00
|
|
|
IdString user_port = user_it.port;
|
|
|
|
|
|
|
|
auto user_port_it = user_it.cell->pins.find(user_port);
|
|
|
|
|
|
|
|
if (user_port_it != user_it.cell->pins.end())
|
|
|
|
user_port = user_port_it->second;
|
|
|
|
|
2018-06-10 00:19:20 +08:00
|
|
|
auto dst_wire =
|
2018-06-18 22:08:19 +08:00
|
|
|
ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
if (dst_wire == WireId())
|
2018-06-14 00:10:09 +08:00
|
|
|
log_error("No wire found for port %s (pin %s) on destination "
|
|
|
|
"cell %s (bel %s).\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
user_it.port.c_str(ctx), user_port.c_str(ctx),
|
|
|
|
user_it.cell->name.c_str(ctx),
|
|
|
|
ctx->getBelName(dst_bel).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose) {
|
2018-06-13 22:52:21 +08:00
|
|
|
log(" Destination wire: %s\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getWireName(dst_wire).c_str(ctx));
|
2018-06-14 18:43:00 +08:00
|
|
|
log(" Path delay estimate: %.2f\n",
|
2018-06-18 20:06:37 +08:00
|
|
|
float(ctx->estimateDelay(src_wire, dst_wire)));
|
2018-06-14 18:43:00 +08:00
|
|
|
}
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-12 01:56:33 +08:00
|
|
|
std::unordered_map<WireId, QueuedWire> visited;
|
2018-06-10 00:19:20 +08:00
|
|
|
std::priority_queue<QueuedWire, std::vector<QueuedWire>,
|
2018-06-12 20:24:59 +08:00
|
|
|
QueuedWire::Greater>
|
2018-06-10 00:19:20 +08:00
|
|
|
queue;
|
|
|
|
|
|
|
|
for (auto &it : src_wires) {
|
|
|
|
QueuedWire qw;
|
|
|
|
qw.wire = it.first;
|
|
|
|
qw.pip = PipId();
|
2018-06-13 22:52:21 +08:00
|
|
|
qw.delay = it.second.avgDelay();
|
2018-06-18 20:06:37 +08:00
|
|
|
qw.togo = ctx->estimateDelay(qw.wire, dst_wire);
|
2018-06-19 18:49:40 +08:00
|
|
|
qw.randtag = ctx->rng();
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
queue.push(qw);
|
|
|
|
visited[qw.wire] = qw;
|
|
|
|
}
|
|
|
|
|
2018-06-16 02:54:57 +08:00
|
|
|
while (!queue.empty() && !visited.count(dst_wire)) {
|
2018-06-10 00:19:20 +08:00
|
|
|
QueuedWire qw = queue.top();
|
|
|
|
queue.pop();
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
for (auto pip : ctx->getPipsDownhill(qw.wire)) {
|
2018-06-16 21:23:04 +08:00
|
|
|
delay_t next_delay = qw.delay;
|
2018-06-18 17:58:37 +08:00
|
|
|
IdString ripupNet = net_name;
|
2018-06-16 02:54:57 +08:00
|
|
|
visitCnt++;
|
2018-06-14 21:09:13 +08:00
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
if (!ctx->checkPipAvail(pip)) {
|
2018-06-18 17:58:37 +08:00
|
|
|
if (!ripup)
|
|
|
|
continue;
|
2018-06-18 20:06:37 +08:00
|
|
|
ripupNet = ctx->getPipNet(pip, true);
|
2018-06-18 17:58:37 +08:00
|
|
|
if (ripupNet == net_name)
|
2018-06-14 21:09:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
WireId next_wire = ctx->getPipDstWire(pip);
|
|
|
|
next_delay += ctx->getPipDelay(pip).avgDelay();
|
2018-06-13 22:52:21 +08:00
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
if (!ctx->checkWireAvail(next_wire)) {
|
2018-06-18 17:58:37 +08:00
|
|
|
if (!ripup)
|
|
|
|
continue;
|
2018-06-18 20:06:37 +08:00
|
|
|
ripupNet = ctx->getWireNet(next_wire, true);
|
2018-06-18 17:58:37 +08:00
|
|
|
if (ripupNet == net_name)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ripupNet != net_name)
|
|
|
|
next_delay += ripup_penalty;
|
|
|
|
assert(next_delay >= 0);
|
|
|
|
|
2018-06-13 22:52:21 +08:00
|
|
|
if (visited.count(next_wire)) {
|
2018-06-20 18:50:38 +08:00
|
|
|
if (visited.at(next_wire).delay <=
|
|
|
|
next_delay + ctx->getDelayEpsilon())
|
2018-06-13 22:52:21 +08:00
|
|
|
continue;
|
2018-06-16 02:54:57 +08:00
|
|
|
#if 0 // FIXME
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-13 22:52:21 +08:00
|
|
|
log("Found better route to %s. Old vs new delay "
|
2018-06-20 18:50:38 +08:00
|
|
|
"estimate: %.3f %.3f\n",
|
2018-06-18 20:06:37 +08:00
|
|
|
ctx->getWireName(next_wire).c_str(),
|
2018-06-20 18:50:38 +08:00
|
|
|
ctx->getDelayNS(visited.at(next_wire).delay),
|
|
|
|
ctx->getDelayNS(next_delay));
|
2018-06-16 02:54:57 +08:00
|
|
|
#endif
|
2018-06-14 18:43:00 +08:00
|
|
|
revisitCnt++;
|
2018-06-14 21:09:13 +08:00
|
|
|
}
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
QueuedWire next_qw;
|
|
|
|
next_qw.wire = next_wire;
|
|
|
|
next_qw.pip = pip;
|
2018-06-13 22:52:21 +08:00
|
|
|
next_qw.delay = next_delay;
|
2018-06-18 20:06:37 +08:00
|
|
|
next_qw.togo = ctx->estimateDelay(next_wire, dst_wire);
|
2018-06-19 18:49:40 +08:00
|
|
|
qw.randtag = ctx->rng();
|
|
|
|
|
2018-06-10 00:19:20 +08:00
|
|
|
visited[next_qw.wire] = next_qw;
|
|
|
|
queue.push(next_qw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 00:28:02 +08:00
|
|
|
if (visited.count(dst_wire) == 0) {
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-14 21:09:13 +08:00
|
|
|
log("Failed to route %s -> %s.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getWireName(src_wire).c_str(ctx),
|
|
|
|
ctx->getWireName(dst_wire).c_str(ctx));
|
2018-06-14 21:09:13 +08:00
|
|
|
else if (ripup)
|
|
|
|
log_info("Failed to route %s -> %s.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getWireName(src_wire).c_str(ctx),
|
|
|
|
ctx->getWireName(dst_wire).c_str(ctx));
|
2018-06-18 20:06:37 +08:00
|
|
|
ripup_net(ctx, net_name);
|
2018-06-18 17:58:37 +08:00
|
|
|
failedDest = dst_wire;
|
2018-06-14 21:09:13 +08:00
|
|
|
return;
|
2018-06-14 00:28:02 +08:00
|
|
|
}
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-20 18:50:38 +08:00
|
|
|
log(" Final path delay: %.3f\n",
|
|
|
|
ctx->getDelayNS(visited[dst_wire].delay));
|
2018-06-13 22:52:21 +08:00
|
|
|
maxDelay = fmaxf(maxDelay, visited[dst_wire].delay);
|
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-13 22:52:21 +08:00
|
|
|
log(" Route (from destination to source):\n");
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
WireId cursor = dst_wire;
|
|
|
|
|
|
|
|
while (1) {
|
2018-06-19 18:49:40 +08:00
|
|
|
if (ctx->verbose)
|
2018-06-20 18:50:38 +08:00
|
|
|
log(" %8.3f %s\n",
|
|
|
|
ctx->getDelayNS(visited[cursor].delay),
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getWireName(cursor).c_str(ctx));
|
2018-06-10 00:19:20 +08:00
|
|
|
|
|
|
|
if (src_wires.count(cursor))
|
|
|
|
break;
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
IdString conflicting_net = ctx->getWireNet(cursor, true);
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
if (conflicting_net != IdString()) {
|
|
|
|
assert(ripup);
|
|
|
|
assert(conflicting_net != net_name);
|
2018-06-18 20:06:37 +08:00
|
|
|
ripup_net(ctx, conflicting_net);
|
2018-06-14 21:09:13 +08:00
|
|
|
rippedNets.insert(conflicting_net);
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
conflicting_net = ctx->getPipNet(visited[cursor].pip, true);
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
if (conflicting_net != IdString()) {
|
|
|
|
assert(ripup);
|
|
|
|
assert(conflicting_net != net_name);
|
2018-06-18 20:06:37 +08:00
|
|
|
ripup_net(ctx, conflicting_net);
|
2018-06-14 21:09:13 +08:00
|
|
|
rippedNets.insert(conflicting_net);
|
|
|
|
}
|
|
|
|
|
2018-06-10 00:19:20 +08:00
|
|
|
net_info->wires[cursor] = visited[cursor].pip;
|
2018-06-18 20:06:37 +08:00
|
|
|
ctx->bindWire(cursor, net_name);
|
|
|
|
ctx->bindPip(visited[cursor].pip, net_name);
|
2018-06-10 00:19:20 +08:00
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
src_wires[cursor] = ctx->getPipDelay(visited[cursor].pip);
|
|
|
|
cursor = ctx->getPipSrcWire(visited[cursor].pip);
|
2018-06-10 00:19:20 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
routedOkay = true;
|
2018-06-10 00:19:20 +08:00
|
|
|
}
|
2018-06-14 21:09:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
bool route_design(Context *ctx)
|
2018-06-14 21:09:13 +08:00
|
|
|
{
|
2018-06-18 17:58:37 +08:00
|
|
|
delay_t ripup_penalty = 5;
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
log_info("Routing..\n");
|
2018-06-13 22:52:21 +08:00
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
std::unordered_set<IdString> netsQueue;
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
for (auto &net_it : ctx->nets) {
|
2018-06-14 21:09:13 +08:00
|
|
|
auto net_name = net_it.first;
|
|
|
|
auto net_info = net_it.second;
|
|
|
|
|
|
|
|
if (net_info->driver.cell == nullptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!net_info->wires.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
netsQueue.insert(net_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netsQueue.empty()) {
|
|
|
|
log_info("found no unrouted nets. no routing necessary.\n");
|
2018-06-18 17:58:37 +08:00
|
|
|
return true;
|
2018-06-14 21:09:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log_info("found %d unrouted nets. starting routing procedure.\n",
|
|
|
|
int(netsQueue.size()));
|
|
|
|
|
2018-06-16 21:23:04 +08:00
|
|
|
delay_t estimatedTotalDelay = 0.0;
|
2018-06-15 01:13:14 +08:00
|
|
|
int estimatedTotalDelayCnt = 0;
|
|
|
|
|
|
|
|
for (auto net_name : netsQueue) {
|
2018-06-18 20:06:37 +08:00
|
|
|
auto net_info = ctx->nets.at(net_name);
|
2018-06-15 01:13:14 +08:00
|
|
|
|
|
|
|
auto src_bel = net_info->driver.cell->bel;
|
|
|
|
|
|
|
|
if (src_bel == BelId())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
IdString driver_port = net_info->driver.port;
|
|
|
|
|
|
|
|
auto driver_port_it = net_info->driver.cell->pins.find(driver_port);
|
|
|
|
if (driver_port_it != net_info->driver.cell->pins.end())
|
|
|
|
driver_port = driver_port_it->second;
|
|
|
|
|
2018-06-18 22:08:19 +08:00
|
|
|
auto src_wire =
|
|
|
|
ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port));
|
2018-06-15 01:13:14 +08:00
|
|
|
|
|
|
|
if (src_wire == WireId())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (auto &user_it : net_info->users) {
|
|
|
|
auto dst_bel = user_it.cell->bel;
|
|
|
|
|
|
|
|
if (dst_bel == BelId())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
IdString user_port = user_it.port;
|
|
|
|
|
|
|
|
auto user_port_it = user_it.cell->pins.find(user_port);
|
|
|
|
|
|
|
|
if (user_port_it != user_it.cell->pins.end())
|
|
|
|
user_port = user_port_it->second;
|
|
|
|
|
|
|
|
auto dst_wire =
|
2018-06-18 22:08:19 +08:00
|
|
|
ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
|
2018-06-15 01:13:14 +08:00
|
|
|
|
|
|
|
if (dst_wire == WireId())
|
|
|
|
continue;
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire);
|
2018-06-15 01:13:14 +08:00
|
|
|
estimatedTotalDelayCnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_info("estimated total wire delay: %.2f (avg %.2f)\n",
|
2018-06-16 21:23:04 +08:00
|
|
|
float(estimatedTotalDelay),
|
|
|
|
float(estimatedTotalDelay) / estimatedTotalDelayCnt);
|
2018-06-15 01:13:14 +08:00
|
|
|
|
2018-06-18 01:43:07 +08:00
|
|
|
int iterCnt = 0;
|
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
while (!netsQueue.empty()) {
|
2018-06-18 17:58:37 +08:00
|
|
|
if (iterCnt == 200) {
|
|
|
|
log_info("giving up after %d iterations.\n", iterCnt);
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-18 01:43:07 +08:00
|
|
|
log_info("-- %d --\n", ++iterCnt);
|
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
int visitCnt = 0, revisitCnt = 0, netCnt = 0;
|
|
|
|
|
|
|
|
std::unordered_set<IdString> ripupQueue;
|
|
|
|
|
2018-06-18 01:27:48 +08:00
|
|
|
log_info("routing queue contains %d nets.\n", int(netsQueue.size()));
|
|
|
|
bool printNets = netsQueue.size() < 10;
|
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
std::vector<IdString> netsArray(netsQueue.begin(), netsQueue.end());
|
2018-06-19 22:23:23 +08:00
|
|
|
ctx->sorted_shuffle(netsArray);
|
2018-06-19 18:49:40 +08:00
|
|
|
netsQueue.clear();
|
|
|
|
|
|
|
|
for (auto net_name : netsArray) {
|
2018-06-18 01:27:48 +08:00
|
|
|
if (printNets)
|
2018-06-18 21:53:18 +08:00
|
|
|
log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx),
|
2018-06-18 20:06:37 +08:00
|
|
|
int(ctx->nets.at(net_name)->users.size()));
|
2018-06-18 01:27:48 +08:00
|
|
|
|
2018-06-19 18:49:40 +08:00
|
|
|
Router router(ctx, net_name, false);
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
netCnt++;
|
|
|
|
visitCnt += router.visitCnt;
|
|
|
|
revisitCnt += router.revisitCnt;
|
|
|
|
|
2018-06-18 17:58:37 +08:00
|
|
|
if (!router.routedOkay) {
|
|
|
|
if (printNets)
|
|
|
|
log_info(" failed to route to %s.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
ctx->getWireName(router.failedDest).c_str(ctx));
|
2018-06-14 21:09:13 +08:00
|
|
|
ripupQueue.insert(net_name);
|
|
|
|
}
|
|
|
|
|
2018-06-18 01:27:48 +08:00
|
|
|
if (!printNets && netCnt % 100 == 0)
|
2018-06-14 21:09:13 +08:00
|
|
|
log_info(" processed %d nets. (%d routed, %d failed)\n",
|
|
|
|
netCnt, netCnt - int(ripupQueue.size()),
|
|
|
|
int(ripupQueue.size()));
|
|
|
|
}
|
|
|
|
|
2018-06-16 02:54:57 +08:00
|
|
|
if (netCnt % 100 != 0)
|
|
|
|
log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt,
|
|
|
|
netCnt - int(ripupQueue.size()), int(ripupQueue.size()));
|
2018-06-16 21:23:04 +08:00
|
|
|
log_info(" routing pass visited %d PIPs (%.2f%% revisits).\n",
|
|
|
|
visitCnt, (100.0 * revisitCnt) / visitCnt);
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
if (!ripupQueue.empty()) {
|
2018-06-18 01:27:48 +08:00
|
|
|
log_info("failed to route %d nets. re-routing in ripup mode.\n",
|
2018-06-14 21:09:13 +08:00
|
|
|
int(ripupQueue.size()));
|
|
|
|
|
2018-06-18 01:27:48 +08:00
|
|
|
printNets = ripupQueue.size() < 10;
|
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
visitCnt = 0;
|
|
|
|
revisitCnt = 0;
|
|
|
|
netCnt = 0;
|
|
|
|
int ripCnt = 0;
|
|
|
|
|
2018-06-19 19:40:35 +08:00
|
|
|
std::vector<IdString> ripupArray(ripupQueue.begin(),
|
|
|
|
ripupQueue.end());
|
2018-06-19 22:23:23 +08:00
|
|
|
ctx->sorted_shuffle(ripupArray);
|
2018-06-19 18:49:40 +08:00
|
|
|
|
|
|
|
for (auto net_name : ripupArray) {
|
2018-06-18 01:27:48 +08:00
|
|
|
if (printNets)
|
2018-06-18 21:53:18 +08:00
|
|
|
log_info(" routing net %s. (%d users)\n",
|
|
|
|
net_name.c_str(ctx),
|
2018-06-18 20:06:37 +08:00
|
|
|
int(ctx->nets.at(net_name)->users.size()));
|
2018-06-18 01:27:48 +08:00
|
|
|
|
2018-06-19 19:40:35 +08:00
|
|
|
Router router(ctx, net_name, true,
|
|
|
|
ripup_penalty * (iterCnt - 1));
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
netCnt++;
|
|
|
|
visitCnt += router.visitCnt;
|
|
|
|
revisitCnt += router.revisitCnt;
|
|
|
|
|
|
|
|
if (!router.routedOkay)
|
|
|
|
log_error("Net %s is impossible to route.\n",
|
2018-06-18 21:53:18 +08:00
|
|
|
net_name.c_str(ctx));
|
2018-06-14 21:09:13 +08:00
|
|
|
|
|
|
|
for (auto it : router.rippedNets)
|
|
|
|
netsQueue.insert(it);
|
|
|
|
|
2018-06-18 01:27:48 +08:00
|
|
|
if (printNets) {
|
|
|
|
if (router.rippedNets.size() < 10) {
|
|
|
|
log_info(" ripped up %d other nets:\n",
|
|
|
|
int(router.rippedNets.size()));
|
|
|
|
for (auto n : router.rippedNets)
|
2018-06-18 21:53:18 +08:00
|
|
|
log_info(" %s (%d users)\n", n.c_str(ctx),
|
2018-06-18 20:06:37 +08:00
|
|
|
int(ctx->nets.at(n)->users.size()));
|
2018-06-18 01:27:48 +08:00
|
|
|
} else {
|
|
|
|
log_info(" ripped up %d other nets.\n",
|
|
|
|
int(router.rippedNets.size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 21:09:13 +08:00
|
|
|
ripCnt += router.rippedNets.size();
|
|
|
|
|
2018-06-18 01:27:48 +08:00
|
|
|
if (!printNets && netCnt % 100 == 0)
|
2018-06-14 21:09:13 +08:00
|
|
|
log_info(" routed %d nets, ripped %d nets.\n", netCnt,
|
|
|
|
ripCnt);
|
|
|
|
}
|
|
|
|
|
2018-06-16 02:54:57 +08:00
|
|
|
if (netCnt % 100 != 0)
|
|
|
|
log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt);
|
2018-06-16 21:23:04 +08:00
|
|
|
|
|
|
|
log_info(" routing pass visited %d PIPs (%.2f%% revisits).\n",
|
2018-06-14 21:09:13 +08:00
|
|
|
visitCnt, (100.0 * revisitCnt) / visitCnt);
|
|
|
|
|
2018-06-16 21:23:04 +08:00
|
|
|
if (!netsQueue.empty())
|
|
|
|
log_info(" ripped up %d previously routed nets. continue "
|
|
|
|
"routing.\n",
|
|
|
|
int(netsQueue.size()));
|
2018-06-14 21:09:13 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-14 00:28:02 +08:00
|
|
|
|
2018-06-18 17:58:37 +08:00
|
|
|
log_info("routing complete after %d iterations.\n", iterCnt);
|
|
|
|
return true;
|
2018-06-10 00:19:20 +08:00
|
|
|
}
|
2018-06-12 20:24:59 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|