Refactor bit2aig for less lookups

This commit is contained in:
Eddie Hung 2019-06-20 22:09:13 -07:00
parent eb13663698
commit a9ce9193a1
1 changed files with 28 additions and 25 deletions

View File

@ -86,33 +86,36 @@ struct XAigerWriter
int bit2aig(SigBit bit) int bit2aig(SigBit bit)
{ {
if (aig_map.count(bit) == 0) // NB: Cannot use iterator returned from aig_map.insert()
{ // since this function is called recursively
aig_map[bit] = -1; auto it = aig_map.find(bit);
if (it != aig_map.end()) {
log_assert(it->second >= 0);
return it->second;
}
int a = -1;
if (not_map.count(bit)) { if (not_map.count(bit)) {
int a = bit2aig(not_map.at(bit)) ^ 1; a = bit2aig(not_map.at(bit)) ^ 1;
aig_map[bit] = a;
} else } else
if (and_map.count(bit)) { if (and_map.count(bit)) {
auto args = and_map.at(bit); auto args = and_map.at(bit);
int a0 = bit2aig(args.first); int a0 = bit2aig(args.first);
int a1 = bit2aig(args.second); int a1 = bit2aig(args.second);
aig_map[bit] = mkgate(a0, a1); a = mkgate(a0, a1);
} else } else
if (alias_map.count(bit)) { if (alias_map.count(bit)) {
int a = bit2aig(alias_map.at(bit)); a = bit2aig(alias_map.at(bit));
aig_map[bit] = a;
} }
if (bit == State::Sx || bit == State::Sz) { if (bit == State::Sx || bit == State::Sz) {
log_debug("Bit '%s' contains 'x' or 'z' bits. Treating as 1'b0.\n", log_signal(bit)); log_debug("Bit '%s' contains 'x' or 'z' bits. Treating as 1'b0.\n", log_signal(bit));
aig_map[bit] = aig_map.at(State::S0); a = aig_map.at(State::S0);
}
} }
log_assert(aig_map.at(bit) >= 0); log_assert(a >= 0);
return aig_map.at(bit); aig_map[bit] = a;
return a;
} }
XAigerWriter(Module *module, bool holes_mode=false) : module(module), sigmap(module) XAigerWriter(Module *module, bool holes_mode=false) : module(module), sigmap(module)