aboutsummaryrefslogtreecommitdiffstats
path: root/ice40
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2022-02-16 13:53:47 +0000
committergatecat <gatecat@ds0.me>2022-02-16 15:10:57 +0000
commit30fd86ce69fa65e89dec119e23b5bccb54de70a3 (patch)
tree7700f5ce4d8b40255aa54e08d2c4489e74b906ff /ice40
parent02e6d2dbca0433e6f873c6af635cee701e84f5f5 (diff)
downloadnextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.tar.gz
nextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.tar.bz2
nextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.zip
refactor: New NetInfo and CellInfo constructors
Diffstat (limited to 'ice40')
-rw-r--r--ice40/bitstream.cc4
-rw-r--r--ice40/cells.cc20
-rw-r--r--ice40/chains.cc32
-rw-r--r--ice40/pack.cc22
4 files changed, 26 insertions, 52 deletions
diff --git a/ice40/bitstream.cc b/ice40/bitstream.cc
index 3c7e7415..8caa9dc6 100644
--- a/ice40/bitstream.cc
+++ b/ice40/bitstream.cc
@@ -979,9 +979,7 @@ void read_config(Context *ctx, std::istream &in, chipconfig_t &config)
IdString netName = ctx->id(name);
if (ctx->nets.find(netName) == ctx->nets.end()) {
- std::unique_ptr<NetInfo> created_net = std::unique_ptr<NetInfo>(new NetInfo);
- created_net->name = netName;
- ctx->nets[netName] = std::move(created_net);
+ ctx->createNet(netName);
}
WireId wire;
diff --git a/ice40/cells.cc b/ice40/cells.cc
index a7e5b067..9a75118f 100644
--- a/ice40/cells.cc
+++ b/ice40/cells.cc
@@ -36,13 +36,10 @@ void add_port(const Context *ctx, CellInfo *cell, std::string name, PortType dir
std::unique_ptr<CellInfo> create_ice_cell(Context *ctx, IdString type, std::string name)
{
static int auto_idx = 0;
- std::unique_ptr<CellInfo> new_cell = std::unique_ptr<CellInfo>(new CellInfo());
- if (name.empty()) {
- new_cell->name = ctx->id("$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++));
- } else {
- new_cell->name = ctx->id(name);
- }
- new_cell->type = type;
+ IdString name_id =
+ name.empty() ? ctx->id("$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++)) : ctx->id(name);
+ auto new_cell = std::make_unique<CellInfo>(ctx, name_id, type);
+
if (type == ctx->id("ICESTORM_LC")) {
new_cell->params[ctx->id("LUT_INIT")] = Property(0, 16);
new_cell->params[ctx->id("NEG_CLK")] = Property::State::S0;
@@ -459,11 +456,10 @@ void nxio_to_sb(Context *ctx, CellInfo *nxio, CellInfo *sbio, pool<IdString> &to
if (ctx->ports.count(nxio->name)) {
IdString tn_netname = nxio->name;
NPNR_ASSERT(!ctx->nets.count(tn_netname));
- std::unique_ptr<NetInfo> toplevel_net{new NetInfo};
- toplevel_net->name = tn_netname;
- connect_port(ctx, toplevel_net.get(), sbio, ctx->id("PACKAGE_PIN"));
- ctx->ports[nxio->name].net = toplevel_net.get();
- ctx->nets[tn_netname] = std::move(toplevel_net);
+ ctx->net_aliases.erase(tn_netname);
+ NetInfo *toplevel_net = ctx->createNet(tn_netname);
+ connect_port(ctx, toplevel_net, sbio, ctx->id("PACKAGE_PIN"));
+ ctx->ports[nxio->name].net = toplevel_net;
}
CellInfo *tbuf = net_driven_by(
diff --git a/ice40/chains.cc b/ice40/chains.cc
index d0d8b043..fa4ce413 100644
--- a/ice40/chains.cc
+++ b/ice40/chains.cc
@@ -114,8 +114,7 @@ class ChainConstrainer
lc->params[ctx->id("LUT_INIT")] = Property(65280, 16); // 0xff00: O = I3
lc->params[ctx->id("CARRY_ENABLE")] = Property::State::S1;
lc->ports.at(id_O).net = cout_port.net;
- std::unique_ptr<NetInfo> co_i3_net(new NetInfo());
- co_i3_net->name = ctx->id(lc->name.str(ctx) + "$I3");
+ NetInfo *co_i3_net = ctx->createNet(ctx->id(lc->name.str(ctx) + "$I3"));
co_i3_net->driver = cout_port.net->driver;
PortRef i3_r;
i3_r.port = id_I3;
@@ -125,17 +124,12 @@ class ChainConstrainer
o_r.port = id_O;
o_r.cell = lc.get();
cout_port.net->driver = o_r;
- lc->ports.at(id_I3).net = co_i3_net.get();
- cout_port.net = co_i3_net.get();
-
- IdString co_i3_name = co_i3_net->name;
- NPNR_ASSERT(ctx->nets.find(co_i3_name) == ctx->nets.end());
- ctx->nets[co_i3_name] = std::move(co_i3_net);
+ lc->ports.at(id_I3).net = co_i3_net;
+ cout_port.net = co_i3_net;
// If COUT also connects to a CIN; preserve the carry chain
if (cin_cell) {
- std::unique_ptr<NetInfo> co_cin_net(new NetInfo());
- co_cin_net->name = ctx->id(lc->name.str(ctx) + "$COUT");
+ NetInfo *co_cin_net = ctx->createNet(ctx->id(lc->name.str(ctx) + "$COUT"));
// Connect I1 to 1 to preserve carry chain
NetInfo *vcc = ctx->nets.at(ctx->id("$PACKER_VCC_NET")).get();
@@ -150,7 +144,7 @@ class ChainConstrainer
co_r.port = id_COUT;
co_r.cell = lc.get();
co_cin_net->driver = co_r;
- lc->ports.at(id_COUT).net = co_cin_net.get();
+ lc->ports.at(id_COUT).net = co_cin_net;
// Find the user corresponding to the next CIN
int replaced_ports = 0;
@@ -166,14 +160,11 @@ class ChainConstrainer
if (fnd_user != usr.end()) {
co_cin_net->users.push_back(*fnd_user);
usr.erase(fnd_user);
- cin_cell->ports.at(port).net = co_cin_net.get();
+ cin_cell->ports.at(port).net = co_cin_net;
++replaced_ports;
}
}
NPNR_ASSERT(replaced_ports > 0);
- IdString co_cin_name = co_cin_net->name;
- NPNR_ASSERT(ctx->nets.find(co_cin_name) == ctx->nets.end());
- ctx->nets[co_cin_name] = std::move(co_cin_net);
}
IdString name = lc->name;
@@ -201,24 +192,19 @@ class ChainConstrainer
i1_ref.port = ctx->id("I1");
lc->ports.at(ctx->id("I1")).net->users.push_back(i1_ref);
- std::unique_ptr<NetInfo> out_net(new NetInfo());
- out_net->name = ctx->id(lc->name.str(ctx) + "$O");
+ NetInfo *out_net = ctx->createNet(ctx->id(lc->name.str(ctx) + "$O"));
PortRef drv_ref;
drv_ref.port = ctx->id("COUT");
drv_ref.cell = lc.get();
out_net->driver = drv_ref;
- lc->ports.at(ctx->id("COUT")).net = out_net.get();
+ lc->ports.at(ctx->id("COUT")).net = out_net;
PortRef usr_ref;
usr_ref.port = cin_port.name;
usr_ref.cell = cin_cell;
out_net->users.push_back(usr_ref);
- cin_cell->ports.at(cin_port.name).net = out_net.get();
-
- IdString out_net_name = out_net->name;
- NPNR_ASSERT(ctx->nets.find(out_net_name) == ctx->nets.end());
- ctx->nets[out_net_name] = std::move(out_net);
+ cin_cell->ports.at(cin_port.name).net = out_net;
IdString name = lc->name;
ctx->assignCellInfo(lc.get());
diff --git a/ice40/pack.cc b/ice40/pack.cc
index 921e73e0..fcbdf2bd 100644
--- a/ice40/pack.cc
+++ b/ice40/pack.cc
@@ -354,8 +354,7 @@ static void pack_constants(Context *ctx)
std::unique_ptr<CellInfo> gnd_cell = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), "$PACKER_GND");
gnd_cell->params[ctx->id("LUT_INIT")] = Property(0, 16);
- std::unique_ptr<NetInfo> gnd_net = std::unique_ptr<NetInfo>(new NetInfo);
- gnd_net->name = ctx->id("$PACKER_GND_NET");
+ auto gnd_net = std::make_unique<NetInfo>(ctx->id("$PACKER_GND_NET"));
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();
@@ -367,8 +366,7 @@ static void pack_constants(Context *ctx)
std::unique_ptr<CellInfo> vcc_cell = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), "$PACKER_VCC");
vcc_cell->params[ctx->id("LUT_INIT")] = Property(1, 16);
- std::unique_ptr<NetInfo> vcc_net = std::unique_ptr<NetInfo>(new NetInfo);
- vcc_net->name = ctx->id("$PACKER_VCC_NET");
+ auto vcc_net = std::make_unique<NetInfo>(ctx->id("$PACKER_VCC_NET"));
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();
@@ -606,15 +604,14 @@ static void insert_global(Context *ctx, NetInfo *net, bool is_reset, bool is_cen
pr.cell = gb.get();
pr.port = ctx->id("GLOBAL_BUFFER_OUTPUT");
- std::unique_ptr<NetInfo> glbnet = std::unique_ptr<NetInfo>(new NetInfo());
- glbnet->name = ctx->id(glb_name);
+ NetInfo *glbnet = ctx->createNet(ctx->id(glb_name));
glbnet->driver = pr;
- gb->ports[ctx->id("GLOBAL_BUFFER_OUTPUT")].net = glbnet.get();
+ gb->ports[ctx->id("GLOBAL_BUFFER_OUTPUT")].net = glbnet;
std::vector<PortRef> keep_users;
for (auto user : net->users) {
if (is_clock_port(ctx, user) || (is_reset && is_reset_port(ctx, user)) ||
(is_cen && is_enable_port(ctx, user)) || (is_logic && is_logic_port(ctx, user))) {
- user.cell->ports[user.port].net = glbnet.get();
+ user.cell->ports[user.port].net = glbnet;
glbnet->users.push_back(user);
} else {
keep_users.push_back(user);
@@ -629,7 +626,6 @@ static void insert_global(Context *ctx, NetInfo *net, bool is_reset, bool is_cen
glbnet->clkconstr->period = net->clkconstr->period;
}
- ctx->nets[glbnet->name] = std::move(glbnet);
ctx->cells[gb->name] = std::move(gb);
}
@@ -1026,11 +1022,10 @@ static std::unique_ptr<CellInfo> spliceLUT(Context *ctx, CellInfo *ci, IdString
pt->params[ctx->id("LUT_INIT")] = Property(65280, 16); // output is always I3
// Create LUT output net.
- std::unique_ptr<NetInfo> out_net = std::unique_ptr<NetInfo>(new NetInfo);
- out_net->name = ctx->id(ci->name.str(ctx) + "$nextnr_" + portId.str(ctx) + "_lut_through_net");
+ NetInfo *out_net = ctx->createNet(ctx->id(ci->name.str(ctx) + "$nextnr_" + portId.str(ctx) + "_lut_through_net"));
out_net->driver.cell = pt.get();
out_net->driver.port = ctx->id("O");
- pt->ports.at(ctx->id("O")).net = out_net.get();
+ pt->ports.at(ctx->id("O")).net = out_net;
// New users of the original cell's port
std::vector<PortRef> new_users;
@@ -1040,7 +1035,7 @@ static std::unique_ptr<CellInfo> spliceLUT(Context *ctx, CellInfo *ci, IdString
continue;
}
// Rewrite pointer into net in user.
- user.cell->ports[user.port].net = out_net.get();
+ user.cell->ports[user.port].net = out_net;
// Add user to net.
PortRef pr;
pr.cell = user.cell;
@@ -1058,7 +1053,6 @@ static std::unique_ptr<CellInfo> spliceLUT(Context *ctx, CellInfo *ci, IdString
// Replace users of the original net.
port.net->users = new_users;
- ctx->nets[out_net->name] = std::move(out_net);
return pt;
}