From 07b21c51299d7ec38aca2a7994542e3c50f93aa3 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 7 Jun 2019 13:58:21 +0200 Subject: Add vcc and gnd nets and cells only if needed --- ice40/pack.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'ice40/pack.cc') diff --git a/ice40/pack.cc b/ice40/pack.cc index bc57e7d0..0a62a5ca 100644 --- a/ice40/pack.cc +++ b/ice40/pack.cc @@ -340,6 +340,12 @@ static void pack_constants(Context *ctx) gnd_net->driver.cell = gnd_cell.get(); gnd_net->driver.port = ctx->id("O"); gnd_cell->ports.at(ctx->id("O")).net = gnd_net.get(); + + NetInfo* gnd_net_info = gnd_net.get(); + if (ctx->nets.find(ctx->id("$PACKER_GND_NET"))!=ctx->nets.end()) + { + gnd_net_info = ctx->nets.find(ctx->id("$PACKER_GND_NET"))->second.get(); + } std::unique_ptr vcc_cell = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), "$PACKER_VCC"); vcc_cell->params[ctx->id("LUT_INIT")] = "1"; @@ -348,6 +354,12 @@ static void pack_constants(Context *ctx) vcc_net->driver.cell = vcc_cell.get(); vcc_net->driver.port = ctx->id("O"); vcc_cell->ports.at(ctx->id("O")).net = vcc_net.get(); + + NetInfo* vcc_net_info = vcc_net.get(); + if (ctx->nets.find(ctx->id("$PACKER_VCC_NET"))!=ctx->nets.end()) + { + vcc_net_info = ctx->nets.find(ctx->id("$PACKER_VCC_NET"))->second.get(); + } std::vector dead_nets; @@ -357,26 +369,29 @@ static void pack_constants(Context *ctx) NetInfo *ni = net.second; if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("GND")) { IdString drv_cell = ni->driver.cell->name; - set_net_constant(ctx, ni, gnd_net.get(), false); + set_net_constant(ctx, ni, gnd_net_info, false); gnd_used = true; dead_nets.push_back(net.first); ctx->cells.erase(drv_cell); } else if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("VCC")) { IdString drv_cell = ni->driver.cell->name; - set_net_constant(ctx, ni, vcc_net.get(), true); + set_net_constant(ctx, ni, vcc_net_info, true); dead_nets.push_back(net.first); ctx->cells.erase(drv_cell); } } - if (gnd_used) { + if (gnd_used && (gnd_net_info == gnd_net.get())) { ctx->cells[gnd_cell->name] = std::move(gnd_cell); ctx->nets[gnd_net->name] = std::move(gnd_net); } // Vcc cell always inserted for now, as it may be needed during carry legalisation (TODO: trim later if actually // never used?) - ctx->cells[vcc_cell->name] = std::move(vcc_cell); - ctx->nets[vcc_net->name] = std::move(vcc_net); + if (vcc_net_info == vcc_net.get()) + { + ctx->cells[vcc_cell->name] = std::move(vcc_cell); + ctx->nets[vcc_net->name] = std::move(vcc_net); + } for (auto dn : dead_nets) { ctx->nets.erase(dn); -- cgit v1.2.3