aboutsummaryrefslogtreecommitdiffstats
path: root/common/place.cc
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-06-13 19:10:12 +0200
committerDavid Shah <davey1576@gmail.com>2018-06-16 14:44:10 +0200
commit3ef45d2a27416ee14239dde6a69b43c870ea07b7 (patch)
tree189a1a8c9b38ededbec1bd38ed60b69bf27b96db /common/place.cc
parentb1e08fa064f58bce759cbd8d341554d5ec4dc14c (diff)
downloadnextpnr-3ef45d2a27416ee14239dde6a69b43c870ea07b7.tar.gz
nextpnr-3ef45d2a27416ee14239dde6a69b43c870ea07b7.tar.bz2
nextpnr-3ef45d2a27416ee14239dde6a69b43c870ea07b7.zip
Another heuristic experiment
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'common/place.cc')
-rw-r--r--common/place.cc95
1 files changed, 18 insertions, 77 deletions
diff --git a/common/place.cc b/common/place.cc
index fbb74395..d28d7ce9 100644
--- a/common/place.cc
+++ b/common/place.cc
@@ -123,45 +123,32 @@ void place_design(Design *design)
}
}
-static void place_cell(Design *design, CellInfo *cell, BelId closeTo,
- size_t &placed_cells,
- std::queue<CellInfo *> &visit_cells)
+static void place_cell(Design *design, CellInfo *cell)
{
assert(cell->bel == BelId());
float best_distance = std::numeric_limits<float>::infinity();
BelId best_bel = BelId();
Chip &chip = design->chip;
BelType targetType = belTypeFromId(cell->type);
- PosInfo origin;
- if (closeTo != BelId()) {
- origin = chip.getBelPosition(closeTo);
- for (auto bel : chip.getBelsAtSameTile(closeTo)) {
- if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
- isValidBelForCell(design, cell, bel)) {
- // prefer same tile
- best_bel = bel;
- goto placed;
- }
- }
- }
for (auto bel : chip.getBels()) {
if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
isValidBelForCell(design, cell, bel)) {
- if (closeTo == BelId()) {
- best_distance = 0;
- best_bel = bel;
- goto placed;
- } else {
- float distance =
- chip.estimateDelay(origin, chip.getBelPosition(bel));
- if (distance < best_distance) {
- best_distance = distance;
- best_bel = bel;
+ float distance = 0;
+ PosInfo belPosition = chip.getBelPosition(bel);
+ for (auto port : cell->ports) {
+ const PortInfo &pi = port.second;
+ if(pi.net != nullptr && pi.type == PORT_IN) {
+ CellInfo *drv = pi.net->driver.cell;
+ if (drv != nullptr && drv->bel != BelId())
+ distance += chip.estimateDelay(chip.getBelPosition(drv->bel), belPosition);
}
}
+ if (distance < best_distance) {
+ best_distance = distance;
+ best_bel = bel;
+ }
}
}
-placed:
if (best_bel == BelId()) {
log_error("failed to place cell '%s' of type '%s'\n",
cell->name.c_str(), cell->type.c_str());
@@ -171,42 +158,6 @@ placed:
// Back annotate location
cell->attrs["BEL"] = chip.getBelName(cell->bel).str();
- placed_cells++;
- visit_cells.push(cell);
-}
-
-static void place_cell_neighbours(Design *design, CellInfo *cell,
- size_t &placed_cells,
- std::queue<CellInfo *> &visit_cells)
-{
- if (cell->bel == BelId())
- return;
- int placed_count = 0;
- const int count_thresh = 15;
- for (auto port : cell->ports) {
- NetInfo *net = port.second.net;
- if (net != nullptr) {
- for (auto user : net->users) {
- if (net->users.size() > 3)
- continue;
- if (user.cell != nullptr && user.cell->bel == BelId()) {
- place_cell(design, user.cell, cell->bel, placed_cells,
- visit_cells);
- placed_count++;
- if (placed_count > count_thresh)
- return;
- }
- }
- if (net->driver.cell != nullptr && net->driver.cell->bel == BelId()) {
- place_cell(design, net->driver.cell, cell->bel, placed_cells,
- visit_cells);
- placed_count++;
- }
- if (placed_count > count_thresh)
- return;
- }
- }
-
}
void place_design_heuristic(Design *design)
@@ -241,21 +192,11 @@ void place_design_heuristic(Design *design)
}
}
log_info("place_constraints placed %d\n", placed_cells);
- while (placed_cells < total_cells) {
- if (!visit_cells.empty()) {
- CellInfo *next = visit_cells.front();
- visit_cells.pop();
- place_cell_neighbours(design, next, placed_cells, visit_cells);
- } else {
- // Nothing to visit (netlist is split), pick the next unplaced cell
- for (auto cell : design->cells) {
- CellInfo *ci = cell.second;
- if (ci->bel == BelId()) {
- place_cell(design, ci, BelId(), placed_cells, visit_cells);
- break;
- }
- }
- }
+ for (auto cell : design->cells) {
+ CellInfo *ci = cell.second;
+ if (ci->bel == BelId())
+ place_cell(design, ci);
+ placed_cells++;
log_info("placed %d/%d\n", placed_cells, total_cells);
}
}