mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 14:13:23 +00:00
use sigmap
This commit is contained in:
parent
1abb8192df
commit
adcbc7f8a6
1 changed files with 75 additions and 34 deletions
|
@ -39,38 +39,56 @@ void lhs2rhs_rhs2lhs(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec,
|
||||||
for (auto it = module->connections().begin(); it != module->connections().end(); ++it) {
|
for (auto it = module->connections().begin(); it != module->connections().end(); ++it) {
|
||||||
RTLIL::SigSpec lhs = it->first;
|
RTLIL::SigSpec lhs = it->first;
|
||||||
RTLIL::SigSpec rhs = it->second;
|
RTLIL::SigSpec rhs = it->second;
|
||||||
std::vector<SigSpec> lhsBits;
|
if (lhs.is_chunk()) {
|
||||||
for (int i = 0; i < lhs.size(); i++) {
|
std::cout << "lhs ischunck: " << lhs.size() << std::endl;
|
||||||
SigSpec bit_sig = lhs.extract(i, 1);
|
} else {
|
||||||
lhsBits.push_back(bit_sig);
|
std::cout << "lhs isnotchunck: " << lhs.size() << std::endl;
|
||||||
}
|
}
|
||||||
std::vector<SigSpec> rhsBits;
|
if (rhs.is_chunk()) {
|
||||||
for (int i = 0; i < rhs.size(); i++) {
|
std::cout << "rhs ischunck: " << rhs.size() << std::endl;
|
||||||
SigSpec bit_sig = rhs.extract(i, 1);
|
} else {
|
||||||
rhsBits.push_back(bit_sig);
|
std::cout << "rhs isnotchunck" << std::endl;
|
||||||
}
|
}
|
||||||
|
if (!lhs.is_chunk()) {
|
||||||
for (uint32_t i = 0; i < lhsBits.size(); i++) {
|
std::vector<SigSpec> lhsBits;
|
||||||
if (i < rhsBits.size()) {
|
for (int i = 0; i < lhs.size(); i++) {
|
||||||
rhsSig2LhsSig[sigmap(rhsBits[i])].insert(sigmap(lhsBits[i]));
|
SigSpec bit_sig = lhs.extract(i, 1);
|
||||||
lhsSig2rhsSig[sigmap(lhsBits[i])] = sigmap(rhsBits[i]);
|
lhsBits.push_back(bit_sig);
|
||||||
|
std::cout << "li:" << i << std::endl;
|
||||||
}
|
}
|
||||||
|
std::vector<SigSpec> rhsBits;
|
||||||
|
for (int i = 0; i < rhs.size(); i++) {
|
||||||
|
SigSpec bit_sig = rhs.extract(i, 1);
|
||||||
|
rhsBits.push_back(bit_sig);
|
||||||
|
std::cout << "ri:" << i << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < lhsBits.size(); i++) {
|
||||||
|
if (i < rhsBits.size()) {
|
||||||
|
std::cout << "lri:" << i << std::endl;
|
||||||
|
rhsSig2LhsSig[sigmap(rhsBits[i])].insert(sigmap(lhsBits[i]));
|
||||||
|
lhsSig2rhsSig[sigmap(lhsBits[i])] = sigmap(rhsBits[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rhsSig2LhsSig[sigmap(rhs)].insert(sigmap(lhs));
|
||||||
|
lhsSig2rhsSig[sigmap(lhs)] = sigmap(rhs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect transitive fanin of a sig
|
// Collect transitive fanin of a sig
|
||||||
void collectTransitiveFanin(RTLIL::SigSpec &sig, dict<RTLIL::SigSpec, std::set<Cell *>> &sig2CellsInFanin,
|
void collectTransitiveFanin(RTLIL::SigSpec &sig, SigMap& sigmap, dict<RTLIL::SigSpec, std::set<Cell *>> &sig2CellsInFanin,
|
||||||
dict<RTLIL::SigSpec, RTLIL::SigSpec> &lhsSig2RhsSig, std::set<Cell *> &visitedCells,
|
dict<RTLIL::SigSpec, RTLIL::SigSpec> &lhsSig2RhsSig, std::set<Cell *> &visitedCells,
|
||||||
std::set<RTLIL::SigSpec> &visitedSigSpec)
|
std::set<RTLIL::SigSpec> &visitedSigSpec)
|
||||||
{
|
{
|
||||||
if (visitedSigSpec.count(sig)) {
|
if (visitedSigSpec.count(sigmap(sig))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
visitedSigSpec.insert(sig);
|
visitedSigSpec.insert(sigmap(sig));
|
||||||
|
|
||||||
if (sig2CellsInFanin.count(sig)) {
|
if (sig2CellsInFanin.count(sigmap(sig))) {
|
||||||
for (Cell *cell : sig2CellsInFanin[sig]) {
|
for (Cell *cell : sig2CellsInFanin[sigmap(sig)]) {
|
||||||
if (visitedCells.count(cell)) {
|
if (visitedCells.count(cell)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -79,27 +97,30 @@ void collectTransitiveFanin(RTLIL::SigSpec &sig, dict<RTLIL::SigSpec, std::set<C
|
||||||
IdString portName = conn.first;
|
IdString portName = conn.first;
|
||||||
RTLIL::SigSpec actual = conn.second;
|
RTLIL::SigSpec actual = conn.second;
|
||||||
if (cell->input(portName)) {
|
if (cell->input(portName)) {
|
||||||
collectTransitiveFanin(actual, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(actual, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
for (int i = 0; i < actual.size(); i++) {
|
for (int i = 0; i < actual.size(); i++) {
|
||||||
SigSpec bit_sig = actual.extract(i, 1);
|
SigSpec bit_sig = actual.extract(i, 1);
|
||||||
collectTransitiveFanin(bit_sig, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(bit_sig, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lhsSig2RhsSig.count(sig)) {
|
std::cout << "HERE\n";
|
||||||
RTLIL::SigSpec rhs = lhsSig2RhsSig[sig];
|
if (lhsSig2RhsSig.count(sigmap(sig))) {
|
||||||
collectTransitiveFanin(rhs, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
std::cout << "THERE\n";
|
||||||
|
RTLIL::SigSpec rhs = lhsSig2RhsSig[sigmap(sig)];
|
||||||
|
collectTransitiveFanin(rhs, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
for (int i = 0; i < rhs.size(); i++) {
|
for (int i = 0; i < rhs.size(); i++) {
|
||||||
|
std::cout << "THERE: " << i << "\n";
|
||||||
SigSpec bit_sig = rhs.extract(i, 1);
|
SigSpec bit_sig = rhs.extract(i, 1);
|
||||||
collectTransitiveFanin(bit_sig, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(bit_sig, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only keep the cells and wires that are visited using the transitive fanin reached from output ports
|
// Only keep the cells and wires that are visited using the transitive fanin reached from output ports or keep signals
|
||||||
void observabilityClean(RTLIL::Module *module, dict<RTLIL::SigSpec, std::set<Cell *>> &sig2CellsInFanin,
|
void observabilityClean(RTLIL::Module *module, SigMap& sigmap, dict<RTLIL::SigSpec, std::set<Cell *>> &sig2CellsInFanin,
|
||||||
dict<RTLIL::SigSpec, RTLIL::SigSpec> &lhsSig2RhsSig)
|
dict<RTLIL::SigSpec, RTLIL::SigSpec> &lhsSig2RhsSig)
|
||||||
{
|
{
|
||||||
if (module->get_bool_attribute(ID::keep))
|
if (module->get_bool_attribute(ID::keep))
|
||||||
|
@ -110,39 +131,59 @@ void observabilityClean(RTLIL::Module *module, dict<RTLIL::SigSpec, std::set<Cel
|
||||||
for (auto elt : sig2CellsInFanin) {
|
for (auto elt : sig2CellsInFanin) {
|
||||||
RTLIL::SigSpec po = elt.first;
|
RTLIL::SigSpec po = elt.first;
|
||||||
RTLIL::Wire *w = po[0].wire;
|
RTLIL::Wire *w = po[0].wire;
|
||||||
if (w && !w->port_output) {
|
if (w && (!w->port_output) && (!w->get_bool_attribute(ID::keep))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
collectTransitiveFanin(po, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(po, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
for (int i = 0; i < po.size(); i++) {
|
for (int i = 0; i < po.size(); i++) {
|
||||||
SigSpec bit_sig = po.extract(i, 1);
|
SigSpec bit_sig = po.extract(i, 1);
|
||||||
collectTransitiveFanin(bit_sig, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(bit_sig, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto elt : lhsSig2RhsSig) {
|
for (auto elt : lhsSig2RhsSig) {
|
||||||
RTLIL::SigSpec po = elt.first;
|
RTLIL::SigSpec po = elt.first;
|
||||||
RTLIL::Wire *w = po[0].wire;
|
RTLIL::Wire *w = po[0].wire;
|
||||||
if (w && !w->port_output) {
|
if (w && (!w->port_output) && (!w->get_bool_attribute(ID::keep))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
collectTransitiveFanin(po, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
if (po.is_chunk()) {
|
||||||
|
std::cout << "po ischunck" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "po isnotchunck" << std::endl;
|
||||||
|
}
|
||||||
|
if (w)
|
||||||
|
std::cout << "Name: " << w->name.c_str() << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "No Name: " << std::endl;
|
||||||
|
std::cout << "PO size: " << po.size() << std::endl;
|
||||||
|
collectTransitiveFanin(po, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
for (int i = 0; i < po.size(); i++) {
|
for (int i = 0; i < po.size(); i++) {
|
||||||
SigSpec bit_sig = po.extract(i, 1);
|
SigSpec bit_sig = po.extract(i, 1);
|
||||||
collectTransitiveFanin(bit_sig, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
collectTransitiveFanin(bit_sig, sigmap, sig2CellsInFanin, lhsSig2RhsSig, visitedCells, visitedSigSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pool<RTLIL::SigSig> newConnections;
|
pool<RTLIL::SigSig> newConnections;
|
||||||
for (auto it = module->connections().begin(); it != module->connections().end(); ++it) {
|
for (auto it = module->connections().begin(); it != module->connections().end(); ++it) {
|
||||||
RTLIL::SigSpec lhs = it->first;
|
RTLIL::SigSpec lhs = it->first;
|
||||||
|
RTLIL::SigSpec sigmaplhs = sigmap(lhs);
|
||||||
|
if (!sigmaplhs.is_fully_const()) {
|
||||||
|
lhs = sigmaplhs;
|
||||||
|
}
|
||||||
if (visitedSigSpec.count(lhs)) {
|
if (visitedSigSpec.count(lhs)) {
|
||||||
newConnections.insert(*it);
|
newConnections.insert(*it);
|
||||||
|
std::cout << "New connection\n";
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < lhs.size(); i++) {
|
for (int i = 0; i < lhs.size(); i++) {
|
||||||
SigSpec bit_sig = lhs.extract(i, 1);
|
SigSpec bit_sig = lhs.extract(i, 1);
|
||||||
|
RTLIL::SigSpec sigmapbit_sig = sigmap(bit_sig);
|
||||||
|
//if (!sigmapbit_sig.is_fully_const()) {
|
||||||
|
bit_sig = sigmapbit_sig;
|
||||||
|
//}
|
||||||
if (visitedSigSpec.count(bit_sig)) {
|
if (visitedSigSpec.count(bit_sig)) {
|
||||||
newConnections.insert(*it);
|
newConnections.insert(*it);
|
||||||
|
std::cout << "New connection\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +198,7 @@ void observabilityClean(RTLIL::Module *module, dict<RTLIL::SigSpec, std::set<Cel
|
||||||
pool<RTLIL::Wire *> wiresToRemove;
|
pool<RTLIL::Wire *> wiresToRemove;
|
||||||
for (auto wire : module->wires()) {
|
for (auto wire : module->wires()) {
|
||||||
RTLIL::SigSpec sig = wire;
|
RTLIL::SigSpec sig = wire;
|
||||||
if (visitedSigSpec.count(sig)) {
|
if (visitedSigSpec.count(sigmap(sig))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bool bitVisited = false;
|
bool bitVisited = false;
|
||||||
|
@ -222,7 +263,7 @@ struct ObsClean : public ScriptPass {
|
||||||
dict<RTLIL::SigSpec, std::set<RTLIL::SigSpec>> rhsSig2LhsSig;
|
dict<RTLIL::SigSpec, std::set<RTLIL::SigSpec>> rhsSig2LhsSig;
|
||||||
lhs2rhs_rhs2lhs(module, sigmap, rhsSig2LhsSig, lhsSig2RhsSig);
|
lhs2rhs_rhs2lhs(module, sigmap, rhsSig2LhsSig, lhsSig2RhsSig);
|
||||||
// Actual cleanup
|
// Actual cleanup
|
||||||
observabilityClean(module, sig2CellsInFanin, lhsSig2RhsSig);
|
observabilityClean(module, sigmap, sig2CellsInFanin, lhsSig2RhsSig);
|
||||||
}
|
}
|
||||||
log("End obs_clean pass\n");
|
log("End obs_clean pass\n");
|
||||||
log_flush();
|
log_flush();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue