Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proc_dff: process sync rules in reverse input order #4568

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions passes/proc/proc_dff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,32 @@ RTLIL::SigSpec find_any_lvalue(const RTLIL::Process *proc)
return lvalue;
}

/**
* Container storing key,std::set(value) pairs in reverse insertion order
* and provides a linear search.
*/
template<typename Key, typename Value>
class InsertOrderedSetMap {
using entry = std::pair<Key, std::set<Value>>;
std::vector<entry> backing;
public:
std::set<Value>& operator[] (Key key) {
auto entry_has_key = [key](entry e) { return e.first == key; };
if (auto it = std::find_if(backing.begin(), backing.end(), entry_has_key); it != std::end(backing)) {
return (*it).second;
} else {
backing.push_back(entry(key, std::set<Value>{}));
return backing.back().second;
}
}
typename std::vector<entry>::reverse_iterator begin() { return backing.rbegin(); }
typename std::vector<entry>::reverse_iterator end() { return backing.rend(); }
typename std::vector<entry>::size_type size() { return backing.size(); }
void clear() { return backing.clear(); }
};

void gen_dffsr_complex(RTLIL::Module *mod, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, RTLIL::SigSpec clk, bool clk_polarity,
std::map<RTLIL::SigSpec, std::set<RTLIL::SyncRule*>> &async_rules, RTLIL::Process *proc)
InsertOrderedSetMap<RTLIL::SigSpec, RTLIL::SyncRule*> &async_rules, RTLIL::Process *proc)
{
RTLIL::SigSpec sig_sr_set = RTLIL::SigSpec(0, sig_d.size());
RTLIL::SigSpec sig_sr_clr = RTLIL::SigSpec(0, sig_d.size());
Expand Down Expand Up @@ -219,7 +243,7 @@ void proc_dff(RTLIL::Module *mod, RTLIL::Process *proc, ConstEval &ce)
RTLIL::SyncRule *sync_always = NULL;
bool global_clock = false;

std::map<RTLIL::SigSpec, std::set<RTLIL::SyncRule*>> many_async_rules;
InsertOrderedSetMap<RTLIL::SigSpec, RTLIL::SyncRule*> many_async_rules;

for (auto sync : proc->syncs)
for (auto &action : sync->actions)
Expand Down
Loading