3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 09:05:32 +00:00

Improved TopoSort determinism

This commit is contained in:
Clifford Wolf 2014-11-07 15:21:03 +01:00
parent 461594bb83
commit 546e8b5fe7
5 changed files with 16 additions and 14 deletions

View file

@ -216,7 +216,7 @@ namespace RTLIL
// set has an influence on the algorithm.
template<typename T> struct compare_ptr_by_name {
bool operator()(const T *a, const T *b) {
bool operator()(const T *a, const T *b) const {
return (a == nullptr || b == nullptr) ? (a < b) : (a->name < b->name);
}
};

View file

@ -128,12 +128,12 @@ public:
// A simple class for topological sorting
// ------------------------------------------------
template<typename T>
template<typename T, typename C = std::less<T>>
struct TopoSort
{
bool analyze_loops, found_loops;
std::map<T, std::set<T>> database;
std::set<std::set<T>> loops;
std::map<T, std::set<T, C>, C> database;
std::set<std::set<T, C>> loops;
std::vector<T> sorted;
TopoSort()
@ -145,7 +145,7 @@ struct TopoSort
void node(T n)
{
if (database.count(n) == 0)
database[n] = std::set<T>();
database[n] = std::set<T, C>();
}
void edge(T left, T right)
@ -154,12 +154,12 @@ struct TopoSort
database[right].insert(left);
}
void sort_worker(const T &n, std::set<T> &marked_cells, std::set<T> &active_cells, std::vector<T> &active_stack)
void sort_worker(const T &n, std::set<T, C> &marked_cells, std::set<T, C> &active_cells, std::vector<T> &active_stack)
{
if (active_cells.count(n)) {
found_loops = true;
if (analyze_loops) {
std::set<T> loop;
std::set<T, C> loop;
for (int i = GetSize(active_stack)-1; i >= 0; i--) {
loop.insert(active_stack[i]);
if (active_stack[i] == n)
@ -197,8 +197,8 @@ struct TopoSort
sorted.clear();
found_loops = false;
std::set<T> marked_cells;
std::set<T> active_cells;
std::set<T, C> marked_cells;
std::set<T, C> active_cells;
std::vector<T> active_stack;
for (auto &it : database)