From 1565d1af69f552b790aa43fd6be194ee59ab76f3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 21 Apr 2016 19:47:25 +0200 Subject: [PATCH] Fixed performance bug in "share" pass --- passes/opt/share.cc | 53 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/passes/opt/share.cc b/passes/opt/share.cc index 1d9b1006e..7927c5397 100644 --- a/passes/opt/share.cc +++ b/passes/opt/share.cc @@ -793,10 +793,59 @@ struct ShareWorker return true; } - void optimize_activation_patterns(pool & /* patterns */) + void optimize_activation_patterns(pool &patterns) { // TODO: Remove patterns that are contained in other patterns - // TODO: Consolidate pairs of patterns that only differ in the value for one signal bit + + dict> db; + bool did_something = false; + + for (auto const &p : patterns) + { + auto &sig = p.first; + auto &val = p.second; + int len = GetSize(sig); + + for (int i = 0; i < len; i++) + { + auto otherval = val; + + if (otherval.bits[i] == State::S0) + otherval.bits[i] = State::S1; + else if (otherval.bits[i] == State::S1) + otherval.bits[i] = State::S0; + else + continue; + + if (db[sig].count(otherval)) + { + auto newsig = sig; + newsig.remove(i); + + auto newval = val; + newval.bits.erase(newval.bits.begin() + i); + + db[newsig].insert(newval); + db[sig].erase(otherval); + + did_something = true; + goto next_pattern; + } + } + + db[sig].insert(val); + next_pattern:; + } + + if (!did_something) + return; + + patterns.clear(); + for (auto &it : db) + for (auto &val : it.second) + patterns.insert(make_pair(it.first, val)); + + optimize_activation_patterns(patterns); } const pool &find_cell_activation_patterns(RTLIL::Cell *cell, const char *indent) -- 2.30.2