From dc4ab55b27a2ada341b060bfe12dade99bf94daf Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 3 Aug 2018 16:59:45 +0200 Subject: [PATCH] Adding constraint satisfaction checks for debugging Signed-off-by: David Shah --- common/nextpnr.h | 2 +- common/place_common.cc | 6 +++++- common/placer1.cc | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/common/nextpnr.h b/common/nextpnr.h index f01173e6..f49b982e 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -281,7 +281,7 @@ struct CellInfo : ArchCellInfo std::unordered_map pins; // placement constraints - CellInfo *constr_parent; + CellInfo *constr_parent = nullptr; std::vector constr_children; const int UNCONSTR = INT_MIN; int constr_x = UNCONSTR; // this.x - parent.x diff --git a/common/place_common.cc b/common/place_common.cc index 8a30f592..11823360 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -438,13 +438,17 @@ class ConstraintLegaliseWorker } } for (auto rippedCell : rippedCells) { - bool res = place_single_cell(ctx, rippedCell, STRENGTH_WEAK); + bool res = place_single_cell(ctx, rippedCell, true); if (!res) { log_error("failed to place cell '%s' after relative constraint legalisation\n", rippedCell->name.c_str(ctx)); return false; } } + for (auto cell : sorted(ctx->cells)) + if (get_constraints_distance(ctx, cell.second) != 0) + log_error("constraint satisfaction check failed for cell '%s' at Bel '%s'\n", cell.first.c_str(ctx), + ctx->getBelName(cell.second->bel).c_str(ctx)); return true; } }; diff --git a/common/placer1.cc b/common/placer1.cc index 27206139..601a0245 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -40,11 +40,12 @@ #include "place_common.h" #include "timing.h" #include "util.h" + NEXTPNR_NAMESPACE_BEGIN class SAPlacer { - public: +public: SAPlacer(Context *ctx) : ctx(ctx) { int num_bel_types = 0; @@ -59,11 +60,11 @@ class SAPlacer type_idx = bel_types.at(type); } if (int(fast_bels.size()) < type_idx + 1) - fast_bels.resize(type_idx + 1); + fast_bels.resize(type_idx + 1); if (int(fast_bels.at(type_idx).size()) < (loc.x + 1)) - fast_bels.at(type_idx).resize(loc.x + 1); + fast_bels.at(type_idx).resize(loc.x + 1); if (int(fast_bels.at(type_idx).at(loc.x).size()) < (loc.y + 1)) - fast_bels.at(type_idx).at(loc.x).resize(loc.y + 1); + fast_bels.at(type_idx).at(loc.x).resize(loc.y + 1); max_x = std::max(max_x, loc.x); max_y = std::max(max_y, loc.y); fast_bels.at(type_idx).at(loc.x).at(loc.y).push_back(bel); @@ -272,12 +273,16 @@ class SAPlacer } } } + for (auto cell : sorted(ctx->cells)) + if (get_constraints_distance(ctx, cell.second) != 0) + log_error("constraint satisfaction check failed for cell '%s' at Bel '%s'\n", cell.first.c_str(ctx), + ctx->getBelName(cell.second->bel).c_str(ctx)); timing_analysis(ctx, true /* print_fmax */); ctx->unlock(); return true; } - private: +private: // Initial random placement void place_initial(CellInfo *cell) { @@ -286,7 +291,7 @@ class SAPlacer while (!all_placed) { BelId best_bel = BelId(); uint64_t best_score = std::numeric_limits::max(), - best_ripup_score = std::numeric_limits::max(); + best_ripup_score = std::numeric_limits::max(); CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { @@ -397,7 +402,7 @@ class SAPlacer metrics.at(new_wl.first) = new_wl.second; return true; - swap_fail: + swap_fail: ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { ctx->bindBel(newBel, other, STRENGTH_WEAK);