aboutsummaryrefslogtreecommitdiffstats
path: root/fpga_interchange
diff options
context:
space:
mode:
authorAlessandro Comodi <acomodi@antmicro.com>2021-07-12 16:02:51 +0200
committerAlessandro Comodi <acomodi@antmicro.com>2021-07-12 16:45:08 +0200
commitd9668df818d801b0c24ae8c372c6e7149352a388 (patch)
tree5e96a5da2de786f174c85c7a2a60a572ccb36605 /fpga_interchange
parent24b7084feb6beecacbe447a15f9b2de04b14d685 (diff)
downloadnextpnr-d9668df818d801b0c24ae8c372c6e7149352a388.tar.gz
nextpnr-d9668df818d801b0c24ae8c372c6e7149352a388.tar.bz2
nextpnr-d9668df818d801b0c24ae8c372c6e7149352a388.zip
interchange: add constraints constraints application routine
Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
Diffstat (limited to 'fpga_interchange')
-rw-r--r--fpga_interchange/arch.cc1
-rw-r--r--fpga_interchange/arch.h3
-rw-r--r--fpga_interchange/arch_place_constr.cc102
3 files changed, 106 insertions, 0 deletions
diff --git a/fpga_interchange/arch.cc b/fpga_interchange/arch.cc
index 901725d4..ccd2dfb2 100644
--- a/fpga_interchange/arch.cc
+++ b/fpga_interchange/arch.cc
@@ -787,6 +787,7 @@ bool Arch::place()
getCtx()->check();
#endif
+ place_constraints();
place_globals();
std::string placer = str_or_default(settings, id("placer"), defaultPlacer);
diff --git a/fpga_interchange/arch.h b/fpga_interchange/arch.h
index 630c4480..8afb71e1 100644
--- a/fpga_interchange/arch.h
+++ b/fpga_interchange/arch.h
@@ -720,6 +720,9 @@ struct Arch : ArchAPI<ArchRanges>
void prepare_cluster(const ClusterPOD *cluster, uint32_t index);
dict<ClusterId, Cluster> clusters;
+ // User constraints
+ void place_constraints();
+
void decode_lut_cells();
const GlobalCellPOD *global_cell_info(IdString cell_type) const;
diff --git a/fpga_interchange/arch_place_constr.cc b/fpga_interchange/arch_place_constr.cc
new file mode 100644
index 00000000..2a3118bd
--- /dev/null
+++ b/fpga_interchange/arch_place_constr.cc
@@ -0,0 +1,102 @@
+/*
+ * nextpnr -- Next Generation Place and Route
+ *
+ * Copyright (C) 2021 Symbiflow Authors
+ *
+ *
+ * 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.
+ *
+ */
+
+#include "log.h"
+#include "nextpnr.h"
+#include "util.h"
+
+NEXTPNR_NAMESPACE_BEGIN
+
+void Arch::place_constraints()
+{
+ std::vector<std::pair<IdString, BelId>> constrained_cells;
+ for (auto &cell_pair : cells) {
+ CellInfo *cell = cell_pair.second.get();
+ auto loc_constr = cell->attrs.find(id("LOC"));
+ auto bel_constr = cell->attrs.find(id("BEL"));
+
+ if (loc_constr == cell->attrs.end() || bel_constr == cell->attrs.end())
+ continue;
+
+ IdString loc_name = id(loc_constr->second.as_string());
+ IdString bel_name = id(bel_constr->second.as_string());
+
+ BelId bel;
+ for (size_t i = 0; i < chip_info->tiles.size(); ++i) {
+ const auto &tile = chip_info->tiles[i];
+ bool site_found = false;
+ for (size_t j = 0; j < tile.sites.size(); ++j) {
+ auto &site_data = chip_info->sites[tile.sites[j]];
+ if (loc_name == id(site_data.site_name.get())) {
+ site_found = true;
+ break;
+ }
+ }
+
+ if (!site_found)
+ continue;
+
+ const auto &tile_type = chip_info->tile_types[tile.type];
+ bool bel_found = false;
+ for (size_t j = 0; j < tile_type.bel_data.size(); ++j) {
+ const BelInfoPOD &bel_data = tile_type.bel_data[j];
+ if (bel_name == IdString(bel_data.name)) {
+ bel.tile = i;
+ bel.index = j;
+ bel_found = true;
+ break;
+ }
+ }
+
+ if (bel_found)
+ break;
+ else
+ log_error("No bel found for user constraint \'%s/%s\' for cell \'%s\'\n", loc_name.c_str(getCtx()),
+ bel_name.c_str(getCtx()), cell->name.c_str(getCtx()));
+ }
+
+ if (!isValidBelForCellType(cell->type, bel))
+ log_error("Bel \'%s\' is invalid for cell \'%s\' (%s)\n", nameOfBel(bel), cell->name.c_str(getCtx()),
+ cell->type.c_str(getCtx()));
+
+ auto bound_cell = getBoundBelCell(bel);
+ if (bound_cell)
+ log_error("Cell \'%s\' cannot be bound to bel \'%s\' "
+ "since it is already bound to cell \'%s\'\n",
+ cell->name.c_str(getCtx()), nameOfBel(bel), bound_cell->name.c_str(getCtx()));
+
+ bindBel(bel, cell, STRENGTH_USER);
+ if (!isBelLocationValid(bel))
+ log_error("Bel \'%s\' is not valid for cell "
+ "\'%s\' of type \'%s\'\n",
+ nameOfBel(bel), cell->name.c_str(getCtx()), cell->type.c_str(getCtx()));
+
+ constrained_cells.emplace_back(cell->name, bel);
+ }
+
+ if (constrained_cells.empty())
+ return;
+
+ log_info("Cell placed via user constraints:\n");
+ for (auto cell_bel : constrained_cells)
+ log_info(" - %s placed at %s\n", cell_bel.first.c_str(getCtx()), nameOfBel(cell_bel.second));
+}
+
+NEXTPNR_NAMESPACE_END