Skip to content

Commit

Permalink
Use hashlib for core netlist structures
Browse files Browse the repository at this point in the history
Signed-off-by: gatecat <[email protected]>
  • Loading branch information
gatecat committed Jun 2, 2021
1 parent ff72454 commit 579b98c
Show file tree
Hide file tree
Showing 49 changed files with 383 additions and 368 deletions.
26 changes: 13 additions & 13 deletions common/basectx.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ struct BaseCtx
mutable StrRingBuffer log_strs;

// Project settings and config switches
std::unordered_map<IdString, Property> settings;
dict<IdString, Property> settings;

// Placed nets and cells.
std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets;
std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
dict<IdString, std::unique_ptr<NetInfo>> nets;
dict<IdString, std::unique_ptr<CellInfo>> cells;

// Hierarchical (non-leaf) cells by full path
std::unordered_map<IdString, HierarchicalCell> hierarchy;
dict<IdString, HierarchicalCell> hierarchy;
// This is the root of the above structure
IdString top_module;

// Aliases for nets, which may have more than one name due to assignments and hierarchy
std::unordered_map<IdString, IdString> net_aliases;
dict<IdString, IdString> net_aliases;

// Top-level ports
std::unordered_map<IdString, PortInfo> ports;
std::unordered_map<IdString, CellInfo *> port_cells;
dict<IdString, PortInfo> ports;
dict<IdString, CellInfo *> port_cells;

// Floorplanning regions
std::unordered_map<IdString, std::unique_ptr<Region>> region;
dict<IdString, std::unique_ptr<Region>> region;

// Context meta data
std::unordered_map<IdString, Property> attrs;
dict<IdString, Property> attrs;

Context *as_ctx = nullptr;

Expand Down Expand Up @@ -186,10 +186,10 @@ struct BaseCtx

bool allUiReload = true;
bool frameUiReload = false;
std::unordered_set<BelId> belUiReload;
std::unordered_set<WireId> wireUiReload;
std::unordered_set<PipId> pipUiReload;
std::unordered_set<GroupId> groupUiReload;
pool<BelId> belUiReload;
pool<WireId> wireUiReload;
pool<PipId> pipUiReload;
pool<GroupId> groupUiReload;

void refreshUi() { allUiReload = true; }

Expand Down
4 changes: 2 additions & 2 deletions common/chain_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ std::vector<CellChain> find_chains(const Context *ctx, F1 cell_type_predicate, F
{
std::set<IdString> chained;
std::vector<CellChain> chains;
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
if (chained.find(cell.first) != chained.end())
continue;
CellInfo *ci = cell.second;
CellInfo *ci = cell.second.get();
if (cell_type_predicate(ctx, ci)) {
CellInfo *start = ci;
CellInfo *prev_start = ci;
Expand Down
4 changes: 2 additions & 2 deletions common/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ struct FixupHierarchyWorker
// Update hierarchy structure for nets and cells that have hiercell set
void rebuild_hierarchy()
{
for (auto cell : sorted(ctx->cells)) {
CellInfo *ci = cell.second;
for (auto &cell : ctx->cells) {
CellInfo *ci = cell.second.get();
if (ci->hierpath == IdString())
ci->hierpath = ctx->top_module;
auto &hc = ctx->hierarchy.at(ci->hierpath);
Expand Down
4 changes: 4 additions & 0 deletions common/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ template <typename K, typename T, typename OPS> class dict
}

public:
using key_type = K;
using mapped_type = T;
using value_type = std::pair<K, T>;

class const_iterator : public std::iterator<std::forward_iterator_tag, std::pair<K, T>>
{
friend class dict;
Expand Down
23 changes: 12 additions & 11 deletions common/nextpnr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unordered_set>

#include "archdefs.h"
#include "hashlib.h"
#include "nextpnr_base_types.h"
#include "nextpnr_namespaces.h"
#include "property.h"
Expand Down Expand Up @@ -56,9 +57,9 @@ struct Region
bool constr_wires = false;
bool constr_pips = false;

std::unordered_set<BelId> bels;
std::unordered_set<WireId> wires;
std::unordered_set<Loc> piplocs;
pool<BelId> bels;
pool<WireId> wires;
pool<Loc> piplocs;
};

struct PipMap
Expand Down Expand Up @@ -128,10 +129,10 @@ struct NetInfo : ArchNetInfo

PortRef driver;
std::vector<PortRef> users;
std::unordered_map<IdString, Property> attrs;
dict<IdString, Property> attrs;

// wire -> uphill_pip
std::unordered_map<WireId, PipMap> wires;
dict<WireId, PipMap> wires;

std::vector<IdString> aliases; // entries in net_aliases that point to this net

Expand Down Expand Up @@ -159,8 +160,8 @@ struct CellInfo : ArchCellInfo
IdString name, type, hierpath;
int32_t udata;

std::unordered_map<IdString, PortInfo> ports;
std::unordered_map<IdString, Property> attrs, params;
dict<IdString, PortInfo> ports;
dict<IdString, Property> attrs, params;

BelId bel;
PlaceStrength belStrength = STRENGTH_NONE;
Expand Down Expand Up @@ -232,13 +233,13 @@ struct HierarchicalCell
{
IdString name, type, parent, fullpath;
// Name inside cell instance -> global name
std::unordered_map<IdString, IdString> leaf_cells, nets;
dict<IdString, IdString> leaf_cells, nets;
// Global name -> name inside cell instance
std::unordered_map<IdString, IdString> leaf_cells_by_gname, nets_by_gname;
dict<IdString, IdString> leaf_cells_by_gname, nets_by_gname;
// Cell port to net
std::unordered_map<IdString, HierarchicalPort> ports;
dict<IdString, HierarchicalPort> ports;
// Name inside cell instance -> global name
std::unordered_map<IdString, IdString> hier_cells;
dict<IdString, IdString> hier_cells;
};

NEXTPNR_NAMESPACE_END
Expand Down
14 changes: 7 additions & 7 deletions common/place_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ class ConstraintLegaliseWorker
public:
ConstraintLegaliseWorker(Context *ctx) : ctx(ctx)
{
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
if (cell.second->cluster != ClusterId())
cluster2cells[cell.second->cluster].push_back(cell.second);
cluster2cells[cell.second->cluster].push_back(cell.second.get());
}
};

Expand Down Expand Up @@ -414,11 +414,11 @@ class ConstraintLegaliseWorker
int legalise_constraints()
{
log_info("Legalising relative constraints...\n");
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
oldLocations[cell.first] = ctx->getBelLocation(cell.second->bel);
}
for (auto cell : sorted(ctx->cells)) {
bool res = legalise_cell(cell.second);
for (auto &cell : ctx->cells) {
bool res = legalise_cell(cell.second.get());
if (!res) {
log_error("failed to place chain starting at cell '%s'\n", cell.first.c_str(ctx));
return -1;
Expand All @@ -434,8 +434,8 @@ class ConstraintLegaliseWorker
}
}
auto score = print_stats("replacing ripped up cells");
for (auto cell : sorted(ctx->cells))
if (get_constraints_distance(ctx, cell.second) != 0)
for (auto &cell : ctx->cells)
if (get_constraints_distance(ctx, cell.second.get()) != 0)
log_error("constraint satisfaction check failed for cell '%s' at Bel '%s'\n", cell.first.c_str(ctx),
ctx->nameOfBel(cell.second->bel));
return score;
Expand Down
30 changes: 15 additions & 15 deletions common/placer1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SAPlacer
diameter = std::max(max_x, max_y) + 1;

std::unordered_set<IdString> cell_types_in_use;
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
IdString cell_type = cell.second->type;
cell_types_in_use.insert(cell_type);
}
Expand All @@ -108,8 +108,8 @@ class SAPlacer
net.second->udata = n++;
net_by_udata.push_back(net.second.get());
}
for (auto &region : sorted(ctx->region)) {
Region *r = region.second;
for (auto &region : ctx->region) {
Region *r = region.second.get();
BoundingBox bb;
if (r->constr_bels) {
bb.x0 = std::numeric_limits<int>::max();
Expand Down Expand Up @@ -360,12 +360,12 @@ class SAPlacer
// Only increase temperature if something was moved
autoplaced.clear();
chain_basis.clear();
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
if (cell.second->belStrength <= STRENGTH_STRONG && cell.second->cluster != ClusterId() &&
ctx->getClusterRootCell(cell.second->cluster) == cell.second)
chain_basis.push_back(cell.second);
ctx->getClusterRootCell(cell.second->cluster) == cell.second.get())
chain_basis.push_back(cell.second.get());
else if (cell.second->belStrength < STRENGTH_STRONG)
autoplaced.push_back(cell.second);
autoplaced.push_back(cell.second.get());
}
// temp = post_legalise_temp;
// diameter = std::min<int>(M, diameter * post_legalise_dia_scale);
Expand Down Expand Up @@ -421,8 +421,8 @@ class SAPlacer
}
}
}
for (auto cell : sorted(ctx->cells))
if (get_constraints_distance(ctx, cell.second) != 0)
for (auto &cell : ctx->cells)
if (get_constraints_distance(ctx, cell.second.get()) != 0)
log_error("constraint satisfaction check failed for cell '%s' at Bel '%s'\n", cell.first.c_str(ctx),
ctx->nameOfBel(cell.second->bel));
timing_analysis(ctx);
Expand Down Expand Up @@ -831,8 +831,8 @@ class SAPlacer
// Set up the cost maps
void setup_costs()
{
for (auto net : sorted(ctx->nets)) {
NetInfo *ni = net.second;
for (auto &net : ctx->nets) {
NetInfo *ni = net.second.get();
if (ignore_net(ni))
continue;
net_bounds[ni->udata] = get_net_bounds(ni);
Expand Down Expand Up @@ -1118,8 +1118,8 @@ class SAPlacer
// Build the cell port -> user index
void build_port_index()
{
for (auto net : sorted(ctx->nets)) {
NetInfo *ni = net.second;
for (auto &net : ctx->nets) {
NetInfo *ni = net.second.get();
for (size_t i = 0; i < ni->users.size(); i++) {
auto &usr = ni->users.at(i);
fast_port_to_user[&(usr.cell->ports.at(usr.port))] = i;
Expand All @@ -1135,8 +1135,8 @@ class SAPlacer
{
total_net_share = 0;
nets_by_tile.resize(max_x + 1, std::vector<std::unordered_map<IdString, int>>(max_y + 1));
for (auto cell : sorted(ctx->cells)) {
CellInfo *ci = cell.second;
for (auto &cell : ctx->cells) {
CellInfo *ci = cell.second.get();
if (int(ci->ports.size()) > large_cell_thresh)
continue;
Loc loc = ctx->getBelLocation(ci->bel);
Expand Down
38 changes: 19 additions & 19 deletions common/placer_heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class HeAPPlacer
tmg.setup_only = true;
tmg.setup();

for (auto cell : sorted(ctx->cells))
for (auto &cell : ctx->cells)
if (cell.second->cluster != ClusterId())
cluster2cells[cell.second->cluster].push_back(cell.second);
cluster2cells[cell.second->cluster].push_back(cell.second.get());
}

bool place()
Expand Down Expand Up @@ -283,8 +283,8 @@ class HeAPPlacer
stalled = 0;
// Save solution
solution.clear();
for (auto cell : sorted(ctx->cells)) {
solution.emplace_back(cell.second, cell.second->bel, cell.second->belStrength);
for (auto &cell : ctx->cells) {
solution.emplace_back(cell.second.get(), cell.second->bel, cell.second->belStrength);
}
} else {
++stalled;
Expand All @@ -311,10 +311,10 @@ class HeAPPlacer
ctx->bindBel(bel, cell, strength);
}

for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
if (cell.second->bel == BelId())
log_error("Found unbound cell %s\n", cell.first.c_str(ctx));
if (ctx->getBoundBelCell(cell.second->bel) != cell.second)
if (ctx->getBoundBelCell(cell.second->bel) != cell.second.get())
log_error("Found cell %s with mismatched binding\n", cell.first.c_str(ctx));
if (ctx->debug)
log_info("AP soln: %s -> %s\n", cell.first.c_str(ctx), ctx->nameOfBel(cell.second->bel));
Expand Down Expand Up @@ -450,7 +450,7 @@ class HeAPPlacer

std::unordered_set<IdString> cell_types_in_use;
std::unordered_set<BelBucketId> buckets_in_use;
for (auto cell : sorted(ctx->cells)) {
for (auto &cell : ctx->cells) {
IdString cell_type = cell.second->type;
cell_types_in_use.insert(cell_type);
BelBucketId bucket = ctx->getBelBucketForCellType(cell_type);
Expand All @@ -465,8 +465,8 @@ class HeAPPlacer
}

// Determine bounding boxes of region constraints
for (auto &region : sorted(ctx->region)) {
Region *r = region.second;
for (auto &region : ctx->region) {
Region *r = region.second.get();
BoundingBox bb;
if (r->constr_bels) {
bb.x0 = std::numeric_limits<int>::max();
Expand Down Expand Up @@ -539,8 +539,8 @@ class HeAPPlacer
ctx->shuffle(t.second.begin(), t.second.end());
}

for (auto cell : sorted(ctx->cells)) {
CellInfo *ci = cell.second;
for (auto &cell : ctx->cells) {
CellInfo *ci = cell.second.get();
if (ci->bel != BelId()) {
Loc loc = ctx->getBelLocation(ci->bel);
cell_locs[cell.first].x = loc.x;
Expand Down Expand Up @@ -591,7 +591,7 @@ class HeAPPlacer
cell_locs[cell.first].global = ctx->getBelGlobalBuf(bel);

// FIXME
if (has_connectivity(cell.second) && !cfg.ioBufTypes.count(ci->type)) {
if (has_connectivity(cell.second.get()) && !cfg.ioBufTypes.count(ci->type)) {
bels_used.insert(bel);
place_cells.push_back(ci);
placed = true;
Expand All @@ -617,7 +617,7 @@ class HeAPPlacer
int row = 0;
solve_cells.clear();
// First clear the udata of all cells
for (auto cell : sorted(ctx->cells))
for (auto &cell : ctx->cells)
cell.second->udata = dont_solve;
// Then update cells to be placed, which excludes cell children
for (auto cell : place_cells) {
Expand Down Expand Up @@ -671,8 +671,8 @@ class HeAPPlacer

es.reset();

for (auto net : sorted(ctx->nets)) {
NetInfo *ni = net.second;
for (auto &net : ctx->nets) {
NetInfo *ni = net.second.get();
if (ni->driver.cell == nullptr)
continue;
if (ni->users.empty())
Expand Down Expand Up @@ -783,8 +783,8 @@ class HeAPPlacer
wirelen_t total_hpwl()
{
wirelen_t hpwl = 0;
for (auto net : sorted(ctx->nets)) {
NetInfo *ni = net.second;
for (auto &net : ctx->nets) {
NetInfo *ni = net.second.get();
if (ni->driver.cell == nullptr)
continue;
CellLocation &drvloc = cell_locs.at(ni->driver.cell->name);
Expand All @@ -809,8 +809,8 @@ class HeAPPlacer
auto startt = std::chrono::high_resolution_clock::now();

// Unbind all cells placed in this solution
for (auto cell : sorted(ctx->cells)) {
CellInfo *ci = cell.second;
for (auto &cell : ctx->cells) {
CellInfo *ci = cell.second.get();
if (ci->bel != BelId() &&
(ci->udata != dont_solve ||
(ci->cluster != ClusterId() && ctx->getClusterRootCell(ci->cluster)->udata != dont_solve)))
Expand Down
Loading

0 comments on commit 579b98c

Please sign in to comment.