ecp5: Refactor skeleton of packer
Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
parent
0e31a8e266
commit
ac4cdd6604
@ -38,6 +38,8 @@ inline bool is_carry(const BaseCtx *ctx, const CellInfo *cell) { return cell->ty
|
|||||||
|
|
||||||
inline bool is_lc(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_LC"); }
|
inline bool is_lc(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_LC"); }
|
||||||
|
|
||||||
|
inline bool is_trellis_io(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_IO"); }
|
||||||
|
|
||||||
inline bool is_dpram(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_DPR16X4"); }
|
inline bool is_dpram(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_DPR16X4"); }
|
||||||
|
|
||||||
inline bool is_pfumx(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("PFUMX"); }
|
inline bool is_pfumx(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("PFUMX"); }
|
||||||
|
94
ecp5/pack.cc
94
ecp5/pack.cc
@ -20,6 +20,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include "cells.h"
|
||||||
#include "design_utils.h"
|
#include "design_utils.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -32,55 +33,66 @@ static bool is_nextpnr_iob(Context *ctx, CellInfo *cell)
|
|||||||
cell->type == ctx->id("$nextpnr_iobuf");
|
cell->type == ctx->id("$nextpnr_iobuf");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_trellis_io(const Context *ctx, const CellInfo *cell) { return cell->type == ctx->id("TRELLIS_IO"); }
|
class Ecp5Packer
|
||||||
|
|
||||||
// Simple "packer" to remove nextpnr IOBUFs, this assumes IOBUFs are manually instantiated
|
|
||||||
void pack_io(Context *ctx)
|
|
||||||
{
|
{
|
||||||
std::unordered_set<IdString> packed_cells;
|
public:
|
||||||
std::vector<std::unique_ptr<CellInfo>> new_cells;
|
Ecp5Packer(Context *ctx) : ctx(ctx){};
|
||||||
log_info("Packing IOs..\n");
|
|
||||||
|
|
||||||
for (auto cell : sorted(ctx->cells)) {
|
private:
|
||||||
CellInfo *ci = cell.second;
|
// Simple "packer" to remove nextpnr IOBUFs, this assumes IOBUFs are manually instantiated
|
||||||
if (is_nextpnr_iob(ctx, ci)) {
|
void pack_io(Context *ctx)
|
||||||
CellInfo *trio = nullptr;
|
{
|
||||||
if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf")) {
|
std::unordered_set<IdString> packed_cells;
|
||||||
trio = net_only_drives(ctx, ci->ports.at(ctx->id("O")).net, is_trellis_io, ctx->id("B"), true, ci);
|
std::vector<std::unique_ptr<CellInfo>> new_cells;
|
||||||
|
log_info("Packing IOs..\n");
|
||||||
|
|
||||||
} else if (ci->type == ctx->id("$nextpnr_obuf")) {
|
for (auto cell : sorted(ctx->cells)) {
|
||||||
trio = net_only_drives(ctx, ci->ports.at(ctx->id("I")).net, is_trellis_io, ctx->id("B"), true, ci);
|
CellInfo *ci = cell.second;
|
||||||
}
|
if (is_nextpnr_iob(ctx, ci)) {
|
||||||
if (trio != nullptr) {
|
CellInfo *trio = nullptr;
|
||||||
// Trivial case, TRELLIS_IO used. Just destroy the net and the
|
if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf")) {
|
||||||
// iobuf
|
trio = net_only_drives(ctx, ci->ports.at(ctx->id("O")).net, is_trellis_io, ctx->id("B"), true, ci);
|
||||||
log_info("%s feeds TRELLIS_IO %s, removing %s %s.\n", ci->name.c_str(ctx), trio->name.c_str(ctx),
|
|
||||||
ci->type.c_str(ctx), ci->name.c_str(ctx));
|
} else if (ci->type == ctx->id("$nextpnr_obuf")) {
|
||||||
NetInfo *net = trio->ports.at(ctx->id("B")).net;
|
trio = net_only_drives(ctx, ci->ports.at(ctx->id("I")).net, is_trellis_io, ctx->id("B"), true, ci);
|
||||||
if (net != nullptr) {
|
|
||||||
ctx->nets.erase(net->name);
|
|
||||||
trio->ports.at(ctx->id("B")).net = nullptr;
|
|
||||||
}
|
}
|
||||||
if (ci->type == ctx->id("$nextpnr_iobuf")) {
|
if (trio != nullptr) {
|
||||||
NetInfo *net2 = ci->ports.at(ctx->id("I")).net;
|
// Trivial case, TRELLIS_IO used. Just destroy the net and the
|
||||||
if (net2 != nullptr) {
|
// iobuf
|
||||||
ctx->nets.erase(net2->name);
|
log_info("%s feeds TRELLIS_IO %s, removing %s %s.\n", ci->name.c_str(ctx), trio->name.c_str(ctx),
|
||||||
|
ci->type.c_str(ctx), ci->name.c_str(ctx));
|
||||||
|
NetInfo *net = trio->ports.at(ctx->id("B")).net;
|
||||||
|
if (net != nullptr) {
|
||||||
|
ctx->nets.erase(net->name);
|
||||||
|
trio->ports.at(ctx->id("B")).net = nullptr;
|
||||||
}
|
}
|
||||||
|
if (ci->type == ctx->id("$nextpnr_iobuf")) {
|
||||||
|
NetInfo *net2 = ci->ports.at(ctx->id("I")).net;
|
||||||
|
if (net2 != nullptr) {
|
||||||
|
ctx->nets.erase(net2->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_error("TRELLIS_IO required on all top level IOs...\n");
|
||||||
}
|
}
|
||||||
} else {
|
packed_cells.insert(ci->name);
|
||||||
log_error("TRELLIS_IO required on all top level IOs...\n");
|
std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(trio->attrs, trio->attrs.begin()));
|
||||||
}
|
}
|
||||||
packed_cells.insert(ci->name);
|
}
|
||||||
std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(trio->attrs, trio->attrs.begin()));
|
for (auto pcell : packed_cells) {
|
||||||
|
ctx->cells.erase(pcell);
|
||||||
|
}
|
||||||
|
for (auto &ncell : new_cells) {
|
||||||
|
ctx->cells[ncell->name] = std::move(ncell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto pcell : packed_cells) {
|
|
||||||
ctx->cells.erase(pcell);
|
public:
|
||||||
}
|
void pack() { pack_io(ctx); }
|
||||||
for (auto &ncell : new_cells) {
|
|
||||||
ctx->cells[ncell->name] = std::move(ncell);
|
private:
|
||||||
}
|
Context *ctx;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Main pack function
|
// Main pack function
|
||||||
bool Arch::pack()
|
bool Arch::pack()
|
||||||
@ -88,7 +100,7 @@ bool Arch::pack()
|
|||||||
Context *ctx = getCtx();
|
Context *ctx = getCtx();
|
||||||
try {
|
try {
|
||||||
log_break();
|
log_break();
|
||||||
pack_io(ctx);
|
Ecp5Packer(ctx).pack();
|
||||||
log_info("Checksum: 0x%08x\n", ctx->checksum());
|
log_info("Checksum: 0x%08x\n", ctx->checksum());
|
||||||
return true;
|
return true;
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
|
Loading…
Reference in New Issue
Block a user