From ad76625d4d828cb093b55aa9f5aae59b7ba9724f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miodrag=20Milanovi=C4=87?= Date: Thu, 2 Oct 2025 11:27:44 +0200 Subject: [PATCH] gatemate: respect keep attribute and prevent crash with BEL set (#1566) --- himbaechel/uarch/gatemate/pack.cc | 20 ++++++++++++++++++++ himbaechel/uarch/gatemate/pack.h | 1 + 2 files changed, 21 insertions(+) diff --git a/himbaechel/uarch/gatemate/pack.cc b/himbaechel/uarch/gatemate/pack.cc index 354e86d1..1ae99985 100644 --- a/himbaechel/uarch/gatemate/pack.cc +++ b/himbaechel/uarch/gatemate/pack.cc @@ -137,6 +137,8 @@ void GateMatePacker::optimize_lut() CellInfo &ci = *cell.second; if (!ci.type.in(id_CC_LUT1, id_CC_LUT2)) continue; + if (ci.attrs.count(ctx->id("keep"))) + continue; NetInfo *o_net = ci.getPort(id_O); if (!o_net) { count_cell(ci); @@ -176,6 +178,8 @@ void GateMatePacker::optimize_mx() CellInfo &ci = *cell.second; if (!ci.type.in(id_CC_MX2, id_CC_MX4)) continue; + if (ci.attrs.count(ctx->id("keep"))) + continue; NetInfo *y_net = ci.getPort(id_Y); if (!y_net) { count_cell(ci); @@ -220,6 +224,8 @@ void GateMatePacker::optimize_ff() CellInfo &ci = *cell.second; if (!ci.type.in(id_CC_DFF, id_CC_DLT)) continue; + if (ci.attrs.count(ctx->id("keep"))) + continue; NetInfo *q_net = ci.getPort(id_Q); if (!q_net) { @@ -378,6 +384,19 @@ void GateMatePacker::repack_cpe() flush_cells(); } +void GateMatePacker::remove_double_constrained() +{ + for (auto &cell : ctx->cells) { + CellInfo &ci = *cell.second; + if (!ci.attrs.count(ctx->id("BEL"))) + continue; + if (ci.cluster != ClusterId()) { + log_warning("Removing BEL attribute for cell '%s'.\n", ci.name.c_str(ctx)); + ci.unsetAttr(ctx->id("BEL")); + } + } +} + void GateMateImpl::pack() { const ArchArgs &args = ctx->args; @@ -404,6 +423,7 @@ void GateMateImpl::pack() packer.pack_cpe(); packer.copy_clocks(); packer.remove_constants(); + packer.remove_double_constrained(); if (forced_die != IdString()) { for (auto &cell : ctx->cells) { diff --git a/himbaechel/uarch/gatemate/pack.h b/himbaechel/uarch/gatemate/pack.h index 65ab9baf..7e247ffb 100644 --- a/himbaechel/uarch/gatemate/pack.h +++ b/himbaechel/uarch/gatemate/pack.h @@ -64,6 +64,7 @@ struct GateMatePacker void remove_constants(); void remove_clocking(); + void remove_double_constrained(); void cleanup(); void repack_cpe();