kernel/mem: Use delayed removal for inits as well.

This commit is contained in:
Marcelina Kościelnicka 2021-07-12 17:10:40 +02:00
parent 6d7d9ab077
commit 0565c642a0
2 changed files with 20 additions and 4 deletions

View File

@ -76,6 +76,17 @@ void Mem::emit() {
wr_left.push_back(i); wr_left.push_back(i);
} }
} }
std::vector<int> init_left;
for (int i = 0; i < GetSize(inits); i++) {
auto &init = inits[i];
if (init.removed) {
if (init.cell) {
module->remove(init.cell);
}
} else {
init_left.push_back(i);
}
}
for (int i = 0; i < GetSize(rd_left); i++) for (int i = 0; i < GetSize(rd_left); i++)
if (i != rd_left[i]) if (i != rd_left[i])
std::swap(rd_ports[i], rd_ports[rd_left[i]]); std::swap(rd_ports[i], rd_ports[rd_left[i]]);
@ -84,6 +95,10 @@ void Mem::emit() {
if (i != wr_left[i]) if (i != wr_left[i])
std::swap(wr_ports[i], wr_ports[wr_left[i]]); std::swap(wr_ports[i], wr_ports[wr_left[i]]);
wr_ports.resize(GetSize(wr_left)); wr_ports.resize(GetSize(wr_left));
for (int i = 0; i < GetSize(init_left); i++)
if (i != init_left[i])
std::swap(inits[i], inits[init_left[i]]);
inits.resize(GetSize(init_left));
// for future: handle transparency mask here // for future: handle transparency mask here
@ -264,14 +279,14 @@ void Mem::emit() {
void Mem::clear_inits() { void Mem::clear_inits() {
for (auto &init : inits) for (auto &init : inits)
if (init.cell) init.removed = true;
module->remove(init.cell);
inits.clear();
} }
Const Mem::get_init_data() const { Const Mem::get_init_data() const {
Const init_data(State::Sx, width * size); Const init_data(State::Sx, width * size);
for (auto &init : inits) { for (auto &init : inits) {
if (init.removed)
continue;
int offset = (init.addr.as_int() - start_offset) * width; int offset = (init.addr.as_int() - start_offset) * width;
for (int i = 0; i < GetSize(init.data); i++) for (int i = 0; i < GetSize(init.data); i++)
if (0 <= i+offset && i+offset < GetSize(init_data)) if (0 <= i+offset && i+offset < GetSize(init_data))

View File

@ -65,10 +65,11 @@ struct MemWr : RTLIL::AttrObject {
}; };
struct MemInit : RTLIL::AttrObject { struct MemInit : RTLIL::AttrObject {
bool removed;
Cell *cell; Cell *cell;
Const addr; Const addr;
Const data; Const data;
MemInit() : cell(nullptr) {} MemInit() : removed(false), cell(nullptr) {}
}; };
struct Mem : RTLIL::AttrObject { struct Mem : RTLIL::AttrObject {