Make PnR use Unlocked methods

This commit is contained in:
Sergiusz Bazanski 2018-07-13 14:50:58 +01:00
parent 0816f447b7
commit 9e4f97290a
7 changed files with 173 additions and 78 deletions

View File

@ -36,7 +36,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns)
if (driver_cell->bel == BelId()) if (driver_cell->bel == BelId())
return 0; return 0;
ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb);
WireId drv_wire = ctx->getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port)); WireId drv_wire = ctx->getWireBelPinUnlocked(driver_cell->bel, ctx->portPinFromId(net->driver.port));
if (driver_gb) if (driver_gb)
return 0; return 0;
float worst_slack = 1000; float worst_slack = 1000;
@ -48,7 +48,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns)
if (load_cell->bel == BelId()) if (load_cell->bel == BelId())
continue; continue;
if (ctx->timing_driven) { if (ctx->timing_driven) {
WireId user_wire = ctx->getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port)); WireId user_wire = ctx->getWireBelPinUnlocked(load_cell->bel, ctx->portPinFromId(load.port));
delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire);
float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl);
if (slack < 0) if (slack < 0)
@ -112,12 +112,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality)
CellInfo *ripup_target = nullptr; CellInfo *ripup_target = nullptr;
BelId ripup_bel = BelId(); BelId ripup_bel = BelId();
if (cell->bel != BelId()) { if (cell->bel != BelId()) {
ctx->unbindBel(cell->bel); ctx->unbindBelUnlocked(cell->bel);
} }
BelType targetType = ctx->belTypeFromId(cell->type); BelType targetType = ctx->belTypeFromId(cell->type);
for (auto bel : ctx->getBels()) { for (auto bel : ctx->getBels()) {
if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) { if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) {
if (ctx->checkBelAvail(bel)) { if (ctx->checkBelAvailUnlocked(bel)) {
wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel);
if (iters >= 4) if (iters >= 4)
wirelen += ctx->rng(25); wirelen += ctx->rng(25);
@ -130,7 +130,7 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality)
if (iters >= 4) if (iters >= 4)
wirelen += ctx->rng(25); wirelen += ctx->rng(25);
if (wirelen <= best_ripup_wirelen) { if (wirelen <= best_ripup_wirelen) {
ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get();
if (ripup_target->belStrength < STRENGTH_STRONG) { if (ripup_target->belStrength < STRENGTH_STRONG) {
best_ripup_wirelen = wirelen; best_ripup_wirelen = wirelen;
ripup_bel = bel; ripup_bel = bel;
@ -148,12 +148,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality)
log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx));
} }
--iters; --iters;
ctx->unbindBel(ripup_target->bel); ctx->unbindBelUnlocked(ripup_target->bel);
best_bel = ripup_bel; best_bel = ripup_bel;
} else { } else {
all_placed = true; all_placed = true;
} }
ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK);
cell = ripup_target; cell = ripup_target;
} }

View File

@ -85,7 +85,7 @@ class SAPlacer
auto loc = cell->attrs.find(ctx->id("BEL")); auto loc = cell->attrs.find(ctx->id("BEL"));
if (loc != cell->attrs.end()) { if (loc != cell->attrs.end()) {
std::string loc_name = loc->second; std::string loc_name = loc->second;
BelId bel = ctx->getBelByName(ctx->id(loc_name)); BelId bel = ctx->getBelByNameUnlocked(ctx->id(loc_name));
if (bel == BelId()) { if (bel == BelId()) {
log_error("No Bel named \'%s\' located for " log_error("No Bel named \'%s\' located for "
"this chip (processing BEL attribute on \'%s\')\n", "this chip (processing BEL attribute on \'%s\')\n",
@ -100,7 +100,7 @@ class SAPlacer
cell->type.c_str(ctx)); cell->type.c_str(ctx));
} }
ctx->bindBel(bel, cell->name, STRENGTH_USER); ctx->bindBelUnlocked(bel, cell->name, STRENGTH_USER);
locked_bels.insert(bel); locked_bels.insert(bel);
placed_cells++; placed_cells++;
} }
@ -235,7 +235,7 @@ class SAPlacer
} }
// Final post-pacement validitiy check // Final post-pacement validitiy check
for (auto bel : ctx->getBels()) { for (auto bel : ctx->getBels()) {
IdString cell = ctx->getBoundBelCell(bel); IdString cell = ctx->getBoundBelCellUnlocked(bel);
if (!ctx->isBelLocationValid(bel)) { if (!ctx->isBelLocationValid(bel)) {
std::string cell_text = "no cell"; std::string cell_text = "no cell";
if (cell != IdString()) if (cell != IdString())
@ -267,12 +267,12 @@ class SAPlacer
CellInfo *ripup_target = nullptr; CellInfo *ripup_target = nullptr;
BelId ripup_bel = BelId(); BelId ripup_bel = BelId();
if (cell->bel != BelId()) { if (cell->bel != BelId()) {
ctx->unbindBel(cell->bel); ctx->unbindBelUnlocked(cell->bel);
} }
BelType targetType = ctx->belTypeFromId(cell->type); BelType targetType = ctx->belTypeFromId(cell->type);
for (auto bel : ctx->getBels()) { for (auto bel : ctx->getBels()) {
if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) {
if (ctx->checkBelAvail(bel)) { if (ctx->checkBelAvailUnlocked(bel)) {
uint64_t score = ctx->rng64(); uint64_t score = ctx->rng64();
if (score <= best_score) { if (score <= best_score) {
best_score = score; best_score = score;
@ -282,7 +282,7 @@ class SAPlacer
uint64_t score = ctx->rng64(); uint64_t score = ctx->rng64();
if (score <= best_ripup_score) { if (score <= best_ripup_score) {
best_ripup_score = score; best_ripup_score = score;
ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get();
ripup_bel = bel; ripup_bel = bel;
} }
} }
@ -292,12 +292,12 @@ class SAPlacer
if (iters == 0 || ripup_bel == BelId()) if (iters == 0 || ripup_bel == BelId())
log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx));
--iters; --iters;
ctx->unbindBel(ripup_target->bel); ctx->unbindBelUnlocked(ripup_target->bel);
best_bel = ripup_bel; best_bel = ripup_bel;
} else { } else {
all_placed = true; all_placed = true;
} }
ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK);
// Back annotate location // Back annotate location
cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx);
@ -313,7 +313,7 @@ class SAPlacer
new_lengths.clear(); new_lengths.clear();
update.clear(); update.clear();
BelId oldBel = cell->bel; BelId oldBel = cell->bel;
IdString other = ctx->getBoundBelCell(newBel); IdString other = ctx->getBoundBelCellUnlocked(newBel);
CellInfo *other_cell = nullptr; CellInfo *other_cell = nullptr;
if (other != IdString()) { if (other != IdString()) {
other_cell = ctx->cells[other].get(); other_cell = ctx->cells[other].get();
@ -321,9 +321,9 @@ class SAPlacer
return false; return false;
} }
wirelen_t new_wirelength = 0, delta; wirelen_t new_wirelength = 0, delta;
ctx->unbindBel(oldBel); ctx->unbindBelUnlocked(oldBel);
if (other != IdString()) { if (other != IdString()) {
ctx->unbindBel(newBel); ctx->unbindBelUnlocked(newBel);
} }
for (const auto &port : cell->ports) for (const auto &port : cell->ports)
@ -336,16 +336,16 @@ class SAPlacer
update.insert(port.second.net); update.insert(port.second.net);
} }
ctx->bindBel(newBel, cell->name, STRENGTH_WEAK); ctx->bindBelUnlocked(newBel, cell->name, STRENGTH_WEAK);
if (other != IdString()) { if (other != IdString()) {
ctx->bindBel(oldBel, other_cell->name, STRENGTH_WEAK); ctx->bindBelUnlocked(oldBel, other_cell->name, STRENGTH_WEAK);
} }
if (require_legal) { if (require_legal) {
if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) {
ctx->unbindBel(newBel); ctx->unbindBelUnlocked(newBel);
if (other != IdString()) if (other != IdString())
ctx->unbindBel(oldBel); ctx->unbindBelUnlocked(oldBel);
goto swap_fail; goto swap_fail;
} }
} }
@ -369,8 +369,8 @@ class SAPlacer
improved = true; improved = true;
} else { } else {
if (other != IdString()) if (other != IdString())
ctx->unbindBel(oldBel); ctx->unbindBelUnlocked(oldBel);
ctx->unbindBel(newBel); ctx->unbindBelUnlocked(newBel);
goto swap_fail; goto swap_fail;
} }
curr_wirelength = new_wirelength; curr_wirelength = new_wirelength;
@ -379,9 +379,9 @@ class SAPlacer
return true; return true;
swap_fail: swap_fail:
ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); ctx->bindBelUnlocked(oldBel, cell->name, STRENGTH_WEAK);
if (other != IdString()) { if (other != IdString()) {
ctx->bindBel(newBel, other, STRENGTH_WEAK); ctx->bindBelUnlocked(newBel, other, STRENGTH_WEAK);
} }
return false; return false;
} }

View File

@ -90,10 +90,10 @@ void ripup_net(Context *ctx, IdString net_name)
} }
for (auto pip : pips) for (auto pip : pips)
ctx->unbindPip(pip); ctx->unbindPipUnlocked(pip);
for (auto wire : wires) for (auto wire : wires)
ctx->unbindWire(wire); ctx->unbindWireUnlocked(wire);
NPNR_ASSERT(net_info->wires.empty()); NPNR_ASSERT(net_info->wires.empty());
} }
@ -148,10 +148,10 @@ struct Router
bool foundRipupNet = false; bool foundRipupNet = false;
thisVisitCnt++; thisVisitCnt++;
if (!ctx->checkWireAvail(next_wire)) { if (!ctx->checkWireAvailUnlocked(next_wire)) {
if (!ripup) if (!ripup)
continue; continue;
IdString ripupWireNet = ctx->getConflictingWireNet(next_wire); IdString ripupWireNet = ctx->getConflictingWireNetUnlocked(next_wire);
if (ripupWireNet == net_name || ripupWireNet == IdString()) if (ripupWireNet == net_name || ripupWireNet == IdString())
continue; continue;
@ -166,10 +166,10 @@ struct Router
foundRipupNet = true; foundRipupNet = true;
} }
if (!ctx->checkPipAvail(pip)) { if (!ctx->checkPipAvailUnlocked(pip)) {
if (!ripup) if (!ripup)
continue; continue;
IdString ripupPipNet = ctx->getConflictingPipNet(pip); IdString ripupPipNet = ctx->getConflictingPipNetUnlocked(pip);
if (ripupPipNet == net_name || ripupPipNet == IdString()) if (ripupPipNet == net_name || ripupPipNet == IdString())
continue; continue;
@ -272,7 +272,7 @@ struct Router
if (driver_port_it != net_info->driver.cell->pins.end()) if (driver_port_it != net_info->driver.cell->pins.end())
driver_port = driver_port_it->second; driver_port = driver_port_it->second;
auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port));
if (src_wire == WireId()) if (src_wire == WireId())
log_error("No wire found for port %s (pin %s) on source cell %s " log_error("No wire found for port %s (pin %s) on source cell %s "
@ -287,7 +287,7 @@ struct Router
src_wires[src_wire] = 0; src_wires[src_wire] = 0;
ripup_net(ctx, net_name); ripup_net(ctx, net_name);
ctx->bindWire(src_wire, net_name, STRENGTH_WEAK); ctx->bindWireUnlocked(src_wire, net_name, STRENGTH_WEAK);
std::vector<PortRef> users_array = net_info->users; std::vector<PortRef> users_array = net_info->users;
ctx->shuffle(users_array); ctx->shuffle(users_array);
@ -312,7 +312,7 @@ struct Router
if (user_port_it != user_it.cell->pins.end()) if (user_port_it != user_it.cell->pins.end())
user_port = user_port_it->second; user_port = user_port_it->second;
auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port));
if (dst_wire == WireId()) if (dst_wire == WireId())
log_error("No wire found for port %s (pin %s) on destination " log_error("No wire found for port %s (pin %s) on destination "
@ -355,14 +355,14 @@ struct Router
if (src_wires.count(cursor)) if (src_wires.count(cursor))
break; break;
IdString conflicting_wire_net = ctx->getConflictingWireNet(cursor); IdString conflicting_wire_net = ctx->getConflictingWireNetUnlocked(cursor);
if (conflicting_wire_net != IdString()) { if (conflicting_wire_net != IdString()) {
NPNR_ASSERT(ripup); NPNR_ASSERT(ripup);
NPNR_ASSERT(conflicting_wire_net != net_name); NPNR_ASSERT(conflicting_wire_net != net_name);
ctx->unbindWire(cursor); ctx->unbindWireUnlocked(cursor);
if (!ctx->checkWireAvail(cursor)) if (!ctx->checkWireAvailUnlocked(cursor))
ripup_net(ctx, conflicting_wire_net); ripup_net(ctx, conflicting_wire_net);
rippedNets.insert(conflicting_wire_net); rippedNets.insert(conflicting_wire_net);
@ -372,14 +372,14 @@ struct Router
} }
PipId pip = visited[cursor].pip; PipId pip = visited[cursor].pip;
IdString conflicting_pip_net = ctx->getConflictingPipNet(pip); IdString conflicting_pip_net = ctx->getConflictingPipNetUnlocked(pip);
if (conflicting_pip_net != IdString()) { if (conflicting_pip_net != IdString()) {
NPNR_ASSERT(ripup); NPNR_ASSERT(ripup);
NPNR_ASSERT(conflicting_pip_net != net_name); NPNR_ASSERT(conflicting_pip_net != net_name);
ctx->unbindPip(pip); ctx->unbindPipUnlocked(pip);
if (!ctx->checkPipAvail(pip)) if (!ctx->checkPipAvailUnlocked(pip))
ripup_net(ctx, conflicting_pip_net); ripup_net(ctx, conflicting_pip_net);
rippedNets.insert(conflicting_pip_net); rippedNets.insert(conflicting_pip_net);
@ -388,7 +388,7 @@ struct Router
scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++;
} }
ctx->bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); ctx->bindPipUnlocked(visited[cursor].pip, net_name, STRENGTH_WEAK);
src_wires[cursor] = visited[cursor].delay; src_wires[cursor] = visited[cursor].delay;
cursor = ctx->getPipSrcWire(visited[cursor].pip); cursor = ctx->getPipSrcWire(visited[cursor].pip);
} }
@ -451,7 +451,7 @@ bool router1(Context *ctx)
if (driver_port_it != net_info->driver.cell->pins.end()) if (driver_port_it != net_info->driver.cell->pins.end())
driver_port = driver_port_it->second; driver_port = driver_port_it->second;
auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port));
if (src_wire == WireId()) if (src_wire == WireId())
continue; continue;
@ -469,7 +469,7 @@ bool router1(Context *ctx)
if (user_port_it != user_it.cell->pins.end()) if (user_port_it != user_it.cell->pins.end())
user_port = user_port_it->second; user_port = user_port_it->second;
auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port));
if (dst_wire == WireId()) if (dst_wire == WireId())
continue; continue;

View File

@ -242,6 +242,11 @@ IdString Arch::archArgsToId(ArchArgs args) const
BelId Arch::getBelByName(IdString name) const BelId Arch::getBelByName(IdString name) const
{ {
boost::lock_guard<boost::shared_mutex> lock(mtx_); boost::lock_guard<boost::shared_mutex> lock(mtx_);
return getBelByNameUnlocked(name);
}
BelId Arch::getBelByNameUnlocked(IdString name) const
{
BelId ret; BelId ret;
if (bel_by_name.empty()) { if (bel_by_name.empty()) {
@ -276,8 +281,13 @@ BelRange Arch::getBelsAtSameTile(BelId bel) const
WireId Arch::getWireBelPin(BelId bel, PortPin pin) const WireId Arch::getWireBelPin(BelId bel, PortPin pin) const
{ {
WireId ret;
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getWireBelPinUnlocked(bel, pin);
}
WireId Arch::getWireBelPinUnlocked(BelId bel, PortPin pin) const
{
WireId ret;
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
@ -297,8 +307,13 @@ WireId Arch::getWireBelPin(BelId bel, PortPin pin) const
WireId Arch::getWireByName(IdString name) const WireId Arch::getWireByName(IdString name) const
{ {
WireId ret;
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getWireByNameUnlocked(name);
}
WireId Arch::getWireByNameUnlocked(IdString name) const
{
WireId ret;
if (wire_by_name.empty()) { if (wire_by_name.empty()) {
for (int i = 0; i < chip_info->num_wires; i++) for (int i = 0; i < chip_info->num_wires; i++)
@ -316,8 +331,13 @@ WireId Arch::getWireByName(IdString name) const
PipId Arch::getPipByName(IdString name) const PipId Arch::getPipByName(IdString name) const
{ {
PipId ret;
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getPipByNameUnlocked(name);
}
PipId Arch::getPipByNameUnlocked(IdString name) const
{
PipId ret;
if (pip_by_name.empty()) { if (pip_by_name.empty()) {
for (int i = 0; i < chip_info->num_pips; i++) { for (int i = 0; i < chip_info->num_pips; i++) {

View File

@ -362,6 +362,7 @@ public:
// ------------------------------------------------- // -------------------------------------------------
BelId getBelByName(IdString name) const; BelId getBelByName(IdString name) const;
BelId getBelByNameUnlocked(IdString name) const;
IdString getBelName(BelId bel) const IdString getBelName(BelId bel) const
{ {
@ -371,21 +372,30 @@ public:
uint32_t getBelChecksum(BelId bel) const { return bel.index; } uint32_t getBelChecksum(BelId bel) const { return bel.index; }
void bindBel(BelId bel, IdString cell, PlaceStrength strength) void bindBel(BelId bel, IdString cell, PlaceStrength strength) {
boost::lock_guard<boost::shared_mutex> lock(mtx_);
bindBelUnlocked(bel, cell, strength);
}
void bindBelUnlocked(BelId bel, IdString cell, PlaceStrength strength)
{ {
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
NPNR_ASSERT(bel_to_cell[bel.index] == IdString()); NPNR_ASSERT(bel_to_cell[bel.index] == IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
bel_to_cell[bel.index] = cell; bel_to_cell[bel.index] = cell;
cells[cell]->bel = bel; cells[cell]->bel = bel;
cells[cell]->belStrength = strength; cells[cell]->belStrength = strength;
} }
void unbindBel(BelId bel) void unbindBel(BelId bel)
{
boost::lock_guard<boost::shared_mutex> lock(mtx_);
unbindBelUnlocked(bel);
}
void unbindBelUnlocked(BelId bel)
{ {
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
NPNR_ASSERT(bel_to_cell[bel.index] != IdString()); NPNR_ASSERT(bel_to_cell[bel.index] != IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
cells[bel_to_cell[bel.index]]->bel = BelId(); cells[bel_to_cell[bel.index]]->bel = BelId();
cells[bel_to_cell[bel.index]]->belStrength = STRENGTH_NONE; cells[bel_to_cell[bel.index]]->belStrength = STRENGTH_NONE;
bel_to_cell[bel.index] = IdString(); bel_to_cell[bel.index] = IdString();
@ -393,22 +403,37 @@ public:
bool checkBelAvail(BelId bel) const bool checkBelAvail(BelId bel) const
{ {
NPNR_ASSERT(bel != BelId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return checkBelAvailUnlocked(bel);
}
bool checkBelAvailUnlocked(BelId bel) const
{
NPNR_ASSERT(bel != BelId());
return bel_to_cell[bel.index] == IdString(); return bel_to_cell[bel.index] == IdString();
} }
IdString getBoundBelCell(BelId bel) const IdString getBoundBelCell(BelId bel) const
{ {
NPNR_ASSERT(bel != BelId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getBoundBelCellUnlocked(bel);
}
IdString getBoundBelCellUnlocked(BelId bel) const
{
NPNR_ASSERT(bel != BelId());
return bel_to_cell[bel.index]; return bel_to_cell[bel.index];
} }
IdString getConflictingBelCell(BelId bel) const IdString getConflictingBelCell(BelId bel) const
{ {
NPNR_ASSERT(bel != BelId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getConflictingBelCellUnlocked(bel);
}
IdString getConflictingBelCellUnlocked(BelId bel) const
{
NPNR_ASSERT(bel != BelId());
return bel_to_cell[bel.index]; return bel_to_cell[bel.index];
} }
@ -425,11 +450,11 @@ public:
BelRange range; BelRange range;
// FIXME // FIXME
#if 0 #if 0
if (type == "TYPE_A") { if (type == "TYPE_A") {
range.b.cursor = bels_type_a_begin; range.b.cursor = bels_type_a_begin;
range.e.cursor = bels_type_a_end; range.e.cursor = bels_type_a_end;
} }
... ...
#endif #endif
return range; return range;
} }
@ -443,6 +468,7 @@ public:
} }
WireId getWireBelPin(BelId bel, PortPin pin) const; WireId getWireBelPin(BelId bel, PortPin pin) const;
WireId getWireBelPinUnlocked(BelId bel, PortPin pin) const;
BelPin getBelPinUphill(WireId wire) const BelPin getBelPinUphill(WireId wire) const
{ {
@ -469,6 +495,7 @@ public:
// ------------------------------------------------- // -------------------------------------------------
WireId getWireByName(IdString name) const; WireId getWireByName(IdString name) const;
WireId getWireByNameUnlocked(IdString name) const;
IdString getWireName(WireId wire) const IdString getWireName(WireId wire) const
{ {
@ -479,10 +506,15 @@ public:
uint32_t getWireChecksum(WireId wire) const { return wire.index; } uint32_t getWireChecksum(WireId wire) const { return wire.index; }
void bindWire(WireId wire, IdString net, PlaceStrength strength) void bindWire(WireId wire, IdString net, PlaceStrength strength)
{
boost::lock_guard<boost::shared_mutex> lock(mtx_);
bindWireUnlocked(wire, net, strength);
}
void bindWireUnlocked(WireId wire, IdString net, PlaceStrength strength)
{ {
NPNR_ASSERT(wire != WireId()); NPNR_ASSERT(wire != WireId());
NPNR_ASSERT(wire_to_net[wire.index] == IdString()); NPNR_ASSERT(wire_to_net[wire.index] == IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
wire_to_net[wire.index] = net; wire_to_net[wire.index] = net;
nets[net]->wires[wire].pip = PipId(); nets[net]->wires[wire].pip = PipId();
@ -490,10 +522,15 @@ public:
} }
void unbindWire(WireId wire) void unbindWire(WireId wire)
{
boost::lock_guard<boost::shared_mutex> lock(mtx_);
unbindWireUnlocked(wire);
}
void unbindWireUnlocked(WireId wire)
{ {
NPNR_ASSERT(wire != WireId()); NPNR_ASSERT(wire != WireId());
NPNR_ASSERT(wire_to_net[wire.index] != IdString()); NPNR_ASSERT(wire_to_net[wire.index] != IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
auto &net_wires = nets[wire_to_net[wire.index]]->wires; auto &net_wires = nets[wire_to_net[wire.index]]->wires;
auto it = net_wires.find(wire); auto it = net_wires.find(wire);
@ -511,25 +548,37 @@ public:
bool checkWireAvail(WireId wire) const bool checkWireAvail(WireId wire) const
{ {
NPNR_ASSERT(wire != WireId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return checkWireAvailUnlocked(wire);
}
bool checkWireAvailUnlocked(WireId wire) const
{
NPNR_ASSERT(wire != WireId());
return wire_to_net[wire.index] == IdString(); return wire_to_net[wire.index] == IdString();
} }
IdString getBoundWireNet(WireId wire) const IdString getBoundWireNet(WireId wire) const
{ {
NPNR_ASSERT(wire != WireId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getBoundWireNetUnlocked(wire);
}
IdString getBoundWireNetUnlocked(WireId wire) const
{
NPNR_ASSERT(wire != WireId());
return wire_to_net[wire.index]; return wire_to_net[wire.index];
} }
IdString getConflictingWireNet(WireId wire) const IdString getConflictingWireNet(WireId wire) const
{ {
NPNR_ASSERT(wire != WireId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getConflictingWireNetUnlocked(wire);
}
IdString getConflictingWireNetUnlocked(WireId wire) const
{
NPNR_ASSERT(wire != WireId());
return wire_to_net[wire.index]; return wire_to_net[wire.index];
} }
@ -544,16 +593,22 @@ public:
// ------------------------------------------------- // -------------------------------------------------
PipId getPipByName(IdString name) const; PipId getPipByName(IdString name) const;
PipId getPipByNameUnlocked(IdString name) const;
IdString getPipName(PipId pip) const; IdString getPipName(PipId pip) const;
uint32_t getPipChecksum(PipId pip) const { return pip.index; } uint32_t getPipChecksum(PipId pip) const { return pip.index; }
void bindPip(PipId pip, IdString net, PlaceStrength strength) void bindPip(PipId pip, IdString net, PlaceStrength strength)
{
boost::lock_guard<boost::shared_mutex> lock(mtx_);
bindPipUnlocked(pip, net, strength);
}
void bindPipUnlocked(PipId pip, IdString net, PlaceStrength strength)
{ {
NPNR_ASSERT(pip != PipId()); NPNR_ASSERT(pip != PipId());
NPNR_ASSERT(pip_to_net[pip.index] == IdString()); NPNR_ASSERT(pip_to_net[pip.index] == IdString());
NPNR_ASSERT(switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString()); NPNR_ASSERT(switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
pip_to_net[pip.index] = net; pip_to_net[pip.index] = net;
switches_locked[chip_info->pip_data[pip.index].switch_index] = net; switches_locked[chip_info->pip_data[pip.index].switch_index] = net;
@ -567,11 +622,16 @@ public:
} }
void unbindPip(PipId pip) void unbindPip(PipId pip)
{
boost::lock_guard<boost::shared_mutex> lock(mtx_);
unbindPipUnlocked(pip);
}
void unbindPipUnlocked(PipId pip)
{ {
NPNR_ASSERT(pip != PipId()); NPNR_ASSERT(pip != PipId());
NPNR_ASSERT(pip_to_net[pip.index] != IdString()); NPNR_ASSERT(pip_to_net[pip.index] != IdString());
NPNR_ASSERT(switches_locked[chip_info->pip_data[pip.index].switch_index] != IdString()); NPNR_ASSERT(switches_locked[chip_info->pip_data[pip.index].switch_index] != IdString());
boost::lock_guard<boost::shared_mutex> lock(mtx_);
WireId dst; WireId dst;
dst.index = chip_info->pip_data[pip.index].dst; dst.index = chip_info->pip_data[pip.index].dst;
@ -585,22 +645,37 @@ public:
bool checkPipAvail(PipId pip) const bool checkPipAvail(PipId pip) const
{ {
NPNR_ASSERT(pip != PipId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return checkPipAvailUnlocked(pip);
}
bool checkPipAvailUnlocked(PipId pip) const
{
NPNR_ASSERT(pip != PipId());
return switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString(); return switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString();
} }
IdString getBoundPipNet(PipId pip) const IdString getBoundPipNet(PipId pip) const
{ {
NPNR_ASSERT(pip != PipId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getBoundPipNetUnlocked(pip);
}
IdString getBoundPipNetUnlocked(PipId pip) const
{
NPNR_ASSERT(pip != PipId());
return pip_to_net[pip.index]; return pip_to_net[pip.index];
} }
IdString getConflictingPipNet(PipId pip) const IdString getConflictingPipNet(PipId pip) const
{ {
NPNR_ASSERT(pip != PipId());
boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); boost::shared_lock_guard<boost::shared_mutex> lock(mtx_);
return getConflictingPipNetUnlocked(pip);
}
IdString getConflictingPipNetUnlocked(PipId pip) const
{
NPNR_ASSERT(pip != PipId());
return switches_locked[chip_info->pip_data[pip.index].switch_index]; return switches_locked[chip_info->pip_data[pip.index].switch_index];
} }

View File

@ -80,7 +80,7 @@ bool Arch::isBelLocationValid(BelId bel) const
if (getBelType(bel) == TYPE_ICESTORM_LC) { if (getBelType(bel) == TYPE_ICESTORM_LC) {
std::vector<const CellInfo *> bel_cells; std::vector<const CellInfo *> bel_cells;
for (auto bel_other : getBelsAtSameTile(bel)) { for (auto bel_other : getBelsAtSameTile(bel)) {
IdString cell_other = getBoundBelCell(bel_other); IdString cell_other = getBoundBelCellUnlocked(bel_other);
if (cell_other != IdString()) { if (cell_other != IdString()) {
const CellInfo *ci_other = cells.at(cell_other).get(); const CellInfo *ci_other = cells.at(cell_other).get();
bel_cells.push_back(ci_other); bel_cells.push_back(ci_other);
@ -88,7 +88,7 @@ bool Arch::isBelLocationValid(BelId bel) const
} }
return logicCellsCompatible(bel_cells); return logicCellsCompatible(bel_cells);
} else { } else {
IdString cellId = getBoundBelCell(bel); IdString cellId = getBoundBelCellUnlocked(bel);
if (cellId == IdString()) if (cellId == IdString())
return true; return true;
else else
@ -104,7 +104,7 @@ bool Arch::isValidBelForCell(CellInfo *cell, BelId bel) const
std::vector<const CellInfo *> bel_cells; std::vector<const CellInfo *> bel_cells;
for (auto bel_other : getBelsAtSameTile(bel)) { for (auto bel_other : getBelsAtSameTile(bel)) {
IdString cell_other = getBoundBelCell(bel_other); IdString cell_other = getBoundBelCellUnlocked(bel_other);
if (cell_other != IdString() && bel_other != bel) { if (cell_other != IdString() && bel_other != bel) {
const CellInfo *ci_other = cells.at(cell_other).get(); const CellInfo *ci_other = cells.at(cell_other).get();
bel_cells.push_back(ci_other); bel_cells.push_back(ci_other);

View File

@ -143,7 +143,7 @@ class PlacementLegaliser
// Using the non-standard API here to get (x, y, z) rather than just (x, y) // Using the non-standard API here to get (x, y, z) rather than just (x, y)
auto bi = ctx->chip_info->bel_data[bel.index]; auto bi = ctx->chip_info->bel_data[bel.index];
int x = bi.x, y = bi.y, z = bi.z; int x = bi.x, y = bi.y, z = bi.z;
IdString cell = ctx->getBoundBelCell(bel); IdString cell = ctx->getBoundBelCellUnlocked(bel);
if (cell != IdString() && ctx->cells.at(cell)->belStrength >= STRENGTH_FIXED) if (cell != IdString() && ctx->cells.at(cell)->belStrength >= STRENGTH_FIXED)
logic_bels.at(x).at(y).at(z) = std::make_pair(bel, true); // locked out of use logic_bels.at(x).at(y).at(z) = std::make_pair(bel, true); // locked out of use
else else
@ -331,16 +331,16 @@ class PlacementLegaliser
NPNR_ASSERT(!loc.second); NPNR_ASSERT(!loc.second);
BelId bel = loc.first; BelId bel = loc.first;
// Check if there is a cell presently at the location, which we will need to rip up // Check if there is a cell presently at the location, which we will need to rip up
IdString existing = ctx->getBoundBelCell(bel); IdString existing = ctx->getBoundBelCellUnlocked(bel);
if (existing != IdString()) { if (existing != IdString()) {
// TODO: keep track of the previous position of the ripped up cell, as a hint // TODO: keep track of the previous position of the ripped up cell, as a hint
rippedCells.insert(existing); rippedCells.insert(existing);
ctx->unbindBel(bel); ctx->unbindBelUnlocked(bel);
} }
if (cell->bel != BelId()) { if (cell->bel != BelId()) {
ctx->unbindBel(cell->bel); ctx->unbindBelUnlocked(cell->bel);
} }
ctx->bindBel(bel, cell->name, STRENGTH_LOCKED); ctx->bindBelUnlocked(bel, cell->name, STRENGTH_LOCKED);
rippedCells.erase(cell->name); // If cell was ripped up previously, no need to re-place rippedCells.erase(cell->name); // If cell was ripped up previously, no need to re-place
loc.second = true; // Bel is now unavailable for further use loc.second = true; // Bel is now unavailable for further use
} }
@ -435,7 +435,7 @@ class PlacementLegaliser
CellInfo *target = nullptr; CellInfo *target = nullptr;
for (int z = 0; z < 8; z++) { for (int z = 0; z < 8; z++) {
BelId bel = logic_bels.at(x).at(y).at(z).first; BelId bel = logic_bels.at(x).at(y).at(z).first;
IdString cell = ctx->getBoundBelCell(bel); IdString cell = ctx->getBoundBelCellUnlocked(bel);
if (cell != IdString()) { if (cell != IdString()) {
CellInfo *ci = ctx->cells.at(cell).get(); CellInfo *ci = ctx->cells.at(cell).get();
if (ci->belStrength >= STRENGTH_STRONG) if (ci->belStrength >= STRENGTH_STRONG)
@ -448,7 +448,7 @@ class PlacementLegaliser
} }
} }
if (target != nullptr) { if (target != nullptr) {
ctx->unbindBel(target->bel); ctx->unbindBelUnlocked(target->bel);
rippedCells.insert(target->name); rippedCells.insert(target->name);
changed = true; changed = true;
} }