mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-13 01:16:16 +00:00
kernel/mem: defer port removal to emit()
This commit is contained in:
parent
8c734e07b8
commit
ff9e0394b8
2 changed files with 38 additions and 18 deletions
|
@ -52,6 +52,40 @@ void Mem::remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mem::emit() {
|
void Mem::emit() {
|
||||||
|
std::vector<int> rd_left;
|
||||||
|
for (int i = 0; i < GetSize(rd_ports); i++) {
|
||||||
|
auto &port = rd_ports[i];
|
||||||
|
if (port.removed) {
|
||||||
|
if (port.cell) {
|
||||||
|
module->remove(port.cell);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rd_left.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<int> wr_left;
|
||||||
|
for (int i = 0; i < GetSize(wr_ports); i++) {
|
||||||
|
auto &port = wr_ports[i];
|
||||||
|
if (port.removed) {
|
||||||
|
if (port.cell) {
|
||||||
|
module->remove(port.cell);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wr_left.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < GetSize(rd_left); i++)
|
||||||
|
if (i != rd_left[i])
|
||||||
|
std::swap(rd_ports[i], rd_ports[rd_left[i]]);
|
||||||
|
rd_ports.resize(GetSize(rd_left));
|
||||||
|
for (int i = 0; i < GetSize(wr_left); i++)
|
||||||
|
if (i != wr_left[i])
|
||||||
|
std::swap(wr_ports[i], wr_ports[wr_left[i]]);
|
||||||
|
wr_ports.resize(GetSize(wr_left));
|
||||||
|
|
||||||
|
// for future: handle transparency mask here
|
||||||
|
// for future: handle priority mask here
|
||||||
|
|
||||||
if (packed) {
|
if (packed) {
|
||||||
if (mem) {
|
if (mem) {
|
||||||
module->memories.erase(mem->name);
|
module->memories.erase(mem->name);
|
||||||
|
@ -205,20 +239,6 @@ void Mem::emit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mem::remove_wr_port(int idx) {
|
|
||||||
if (wr_ports[idx].cell) {
|
|
||||||
module->remove(wr_ports[idx].cell);
|
|
||||||
}
|
|
||||||
wr_ports.erase(wr_ports.begin() + idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mem::remove_rd_port(int idx) {
|
|
||||||
if (rd_ports[idx].cell) {
|
|
||||||
module->remove(rd_ports[idx].cell);
|
|
||||||
}
|
|
||||||
rd_ports.erase(rd_ports.begin() + idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mem::clear_inits() {
|
void Mem::clear_inits() {
|
||||||
for (auto &init : inits)
|
for (auto &init : inits)
|
||||||
if (init.cell)
|
if (init.cell)
|
||||||
|
|
|
@ -25,20 +25,22 @@
|
||||||
YOSYS_NAMESPACE_BEGIN
|
YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
struct MemRd {
|
struct MemRd {
|
||||||
|
bool removed;
|
||||||
dict<IdString, Const> attributes;
|
dict<IdString, Const> attributes;
|
||||||
Cell *cell;
|
Cell *cell;
|
||||||
bool clk_enable, clk_polarity;
|
bool clk_enable, clk_polarity;
|
||||||
bool transparent;
|
bool transparent;
|
||||||
SigSpec clk, en, addr, data;
|
SigSpec clk, en, addr, data;
|
||||||
MemRd() : cell(nullptr) {}
|
MemRd() : removed(false), cell(nullptr) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MemWr {
|
struct MemWr {
|
||||||
|
bool removed;
|
||||||
dict<IdString, Const> attributes;
|
dict<IdString, Const> attributes;
|
||||||
Cell *cell;
|
Cell *cell;
|
||||||
bool clk_enable, clk_polarity;
|
bool clk_enable, clk_polarity;
|
||||||
SigSpec clk, en, addr, data;
|
SigSpec clk, en, addr, data;
|
||||||
MemWr() : cell(nullptr) {}
|
MemWr() : removed(false), cell(nullptr) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MemInit {
|
struct MemInit {
|
||||||
|
@ -63,8 +65,6 @@ struct Mem {
|
||||||
|
|
||||||
void remove();
|
void remove();
|
||||||
void emit();
|
void emit();
|
||||||
void remove_wr_port(int idx);
|
|
||||||
void remove_rd_port(int idx);
|
|
||||||
void clear_inits();
|
void clear_inits();
|
||||||
Const get_init_data() const;
|
Const get_init_data() const;
|
||||||
static std::vector<Mem> get_all_memories(Module *module);
|
static std::vector<Mem> get_all_memories(Module *module);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue