refactor to use create_cell_ptr only

This commit is contained in:
Miodrag Milanovic 2024-11-28 08:11:25 +01:00
parent f88532147b
commit ea478eec2c
3 changed files with 17 additions and 43 deletions

View File

@ -25,31 +25,6 @@
NEXTPNR_NAMESPACE_BEGIN
std::unique_ptr<CellInfo> NgUltraPacker::create_cell(IdString type, IdString name)
{
auto cell = std::make_unique<CellInfo>(ctx, name, type);
auto add_port = [&](const IdString id, PortType dir) {
cell->ports[id].name = id;
cell->ports[id].type = dir;
};
if (type == id_BEYOND_FE) {
add_port(id_I1, PORT_IN);
add_port(id_I2, PORT_IN);
add_port(id_I3, PORT_IN);
add_port(id_I4, PORT_IN);
add_port(id_LO, PORT_OUT);
add_port(id_DI, PORT_IN);
add_port(id_L, PORT_IN);
add_port(id_CK, PORT_IN);
add_port(id_R, PORT_IN);
add_port(id_DO, PORT_OUT);
} else {
log_error("Trying to create unknown cell type %s\n", type.c_str(ctx));
}
return cell;
}
CellInfo *NgUltraPacker::create_cell_ptr(IdString type, IdString name)
{
CellInfo *cell = ctx->createCell(name, type);

View File

@ -65,11 +65,7 @@ void NgUltraPacker::flush_cells()
}
ctx->cells.erase(pcell);
}
for (auto &ncell : new_cells) {
ctx->cells[ncell->name] = std::move(ncell);
}
packed_cells.clear();
new_cells.clear();
}
void NgUltraPacker::pack_constants(void)
@ -581,26 +577,29 @@ void NgUltraPacker::pack_lut_dffs(void)
log_info("Pack LUT-DFFs...\n");
int lut_only = 0, lut_and_ff = 0;
std::vector<CellInfo*> lut_list;
for (auto &cell : ctx->cells) {
CellInfo &ci = *cell.second;
if (!ci.type.in(id_NX_LUT))
continue;
if (!ci.params.count(id_lut_table))
log_error("Cell '%s' missing lut_table\n", ci.name.c_str(ctx));
std::unique_ptr<CellInfo> packed = create_cell(id_BEYOND_FE, ctx->idf("%s$fe", ci.name.c_str(ctx)));
packed_cells.insert(ci.name);
bind_attr_loc(packed.get(), &ci.attrs);
lut_list.push_back(&ci);
}
for (auto ci : lut_list) {
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx)));
bind_attr_loc(packed, &ci->attrs);
bool packed_dff = false;
NetInfo *o = ci.getPort(id_O);
NetInfo *o = ci->getPort(id_O);
if (o) {
CellInfo *dff = net_only_drives(ctx, o, is_dff, id_I, true);
if (dff) {
if (ctx->verbose)
log_info("found attached dff %s\n", dff->name.c_str(ctx));
lut_to_fe(&ci, packed.get(), false, ci.params[id_lut_table]);
dff_to_fe(dff, packed.get(), false);
lut_to_fe(ci, packed, false, ci->params[id_lut_table]);
dff_to_fe(dff, packed, false);
++lut_and_ff;
packed_cells.insert(dff->name);
if (ctx->verbose)
@ -609,10 +608,9 @@ void NgUltraPacker::pack_lut_dffs(void)
}
}
if (!packed_dff) {
lut_to_fe(&ci, packed.get(), true, ci.params[id_lut_table]);
lut_to_fe(ci, packed, true, ci->params[id_lut_table]);
++lut_only;
}
new_cells.push_back(std::move(packed));
}
if (lut_only)
log_info(" %6d FEs used as LUT only\n", lut_only);
@ -624,16 +622,19 @@ void NgUltraPacker::pack_lut_dffs(void)
void NgUltraPacker::pack_dffs(void)
{
int dff_only = 0;
std::vector<CellInfo*> dff_list;
for (auto &cell : ctx->cells) {
CellInfo &ci = *cell.second;
if (!ci.type.in(id_NX_DFF, id_NX_BFF))
continue;
std::unique_ptr<CellInfo> packed = create_cell(id_BEYOND_FE, ctx->idf("%s$fe", ci.name.c_str(ctx)));
packed_cells.insert(ci.name);
dff_to_fe(&ci, packed.get(), true);
bind_attr_loc(packed.get(), &ci.attrs);
dff_list.push_back(&ci);
}
for (auto ci : dff_list) {
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx)));
dff_to_fe(ci, packed, true);
bind_attr_loc(packed, &ci->attrs);
++dff_only;
new_cells.push_back(std::move(packed));
}
if (dff_only)
log_info(" %6d FEs used as DFF only\n", dff_only);

View File

@ -112,14 +112,12 @@ TESTABLE_PRIVATE:
void constrain_location(CellInfo *cell);
void extract_lowskew_signals(CellInfo *cell, dict<IdString,dict<IdString,std::vector<PortRef>>> &lowskew_signals);
// Cell creating
std::unique_ptr<CellInfo> create_cell(IdString type, IdString name);
CellInfo *create_cell_ptr(IdString type, IdString name);
Context *ctx;
NgUltraImpl *uarch;
pool<IdString> packed_cells;
std::vector<std::unique_ptr<CellInfo>> new_cells;
pool<IdString> global_lowskew;
HimbaechelHelpers h;