aiger2: Add strashing option

This commit is contained in:
Martin Povišer 2024-09-11 11:02:40 +02:00
parent fa39227416
commit 5671c10173
1 changed files with 32 additions and 9 deletions

View File

@ -99,9 +99,15 @@ struct Index {
ModuleInfo *top_minfo; ModuleInfo *top_minfo;
std::vector<Lit> lits; std::vector<Lit> lits;
Index(RTLIL::Module *top) Index()
: design(top->design), top(top)
{ {
}
void setup(RTLIL::Module *top)
{
design = top->design;
this->top = top;
modules.reserve(top->design->modules().size()); modules.reserve(top->design->modules().size());
int nlits = index_module(top); int nlits = index_module(top);
log_debug("allocating for %d literals\n", nlits); log_debug("allocating for %d literals\n", nlits);
@ -109,7 +115,9 @@ struct Index {
top_minfo = &modules.at(top); top_minfo = &modules.at(top);
} }
bool const_folding = false; bool const_folding = true;
bool strashing = false;
dict<std::pair<int, int>, int> cache;
Lit AND(Lit a, Lit b) Lit AND(Lit a, Lit b)
{ {
@ -122,7 +130,20 @@ struct Index {
return a; return a;
} }
return (static_cast<Writer*>(this))->emit_gate(a, b); if (!strashing) {
return (static_cast<Writer*>(this))->emit_gate(a, b);
} else {
if (a < b) std::swap(a, b);
auto pair = std::make_pair(a, b);
if (!cache.count(pair)) {
Lit nl = (static_cast<Writer*>(this))->emit_gate(a, b);
cache[pair] = nl;
return nl;
} else {
return cache.at(pair);
}
}
} }
Lit NOT(Lit lit) Lit NOT(Lit lit)
@ -552,9 +573,6 @@ struct AigerWriter : Index<AigerWriter, unsigned int> {
i++; i++;
} }
} }
AigerWriter(RTLIL::Module *top)
: Index(top) {}
}; };
struct Aiger2Backend : Backend { struct Aiger2Backend : Backend {
@ -568,8 +586,13 @@ struct Aiger2Backend : Backend {
log_header(design, "Executing AIGER2 backend.\n"); log_header(design, "Executing AIGER2 backend.\n");
size_t argidx; size_t argidx;
AigerWriter writer;
writer.const_folding = true;
for (argidx = 1; argidx < args.size(); argidx++) { for (argidx = 1; argidx < args.size(); argidx++) {
break; if (args[argidx] == "-strash")
writer.strashing = true;
else
break;
} }
extra_args(f, filename, args, argidx); extra_args(f, filename, args, argidx);
@ -579,7 +602,7 @@ struct Aiger2Backend : Backend {
log_cmd_error("No top module selected\n"); log_cmd_error("No top module selected\n");
design->bufNormalize(true); design->bufNormalize(true);
AigerWriter writer(top); writer.setup(top);
writer.write(f); writer.write(f);
// we are leaving the sacred land, un-bufnormalize // we are leaving the sacred land, un-bufnormalize