Commit e213b799 authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

SGSubgraph topo order

parent 12c81a62
......@@ -570,5 +570,40 @@ Loco::SectionGraph::PrintSubgraph(std::ostream &os, const SGSubgraphCPtr &subg,
}
}
os << "}" << std::endl;
os << "// topo_order:";
for (unsigned t : subg->mTopoOrder)
{
os << " v" << t;
}
os << std::endl;
return os;
}
void
Loco::SGSubgraph::BuildTopoOrder()
{
std::unordered_set<unsigned> visited;
mTopoOrder.clear();
mTopoOrder.reserve(mSections.size());
for (auto leaf : mTargets)
{
if (visited.find(leaf) == visited.end())
{
TOVisit(leaf, visited);
}
}
}
void
Loco::SGSubgraph::TOVisit(unsigned node, std::unordered_set<unsigned> &visited)
{
visited.insert(node);
for (unsigned pred : mSections.at(node).mPred)
{
if (visited.find(pred) == visited.end())
{
TOVisit(pred, visited);
}
}
mTopoOrder.push_back(node);
}
......@@ -14,6 +14,7 @@
#define __SECTION_GRAPH_H
#include <map>
#include <unordered_set>
#include "logical_graph.h"
#include "places.h"
......@@ -40,10 +41,16 @@ namespace Loco
std::vector<unsigned> mPred;
};
private:
void TOVisit(unsigned node, std::unordered_set<unsigned> &visited);
public:
std::vector<unsigned> mSources;
std::vector<unsigned> mTargets;
std::unordered_map<unsigned, NodeInfo> mSections;
std::vector<unsigned> mTopoOrder;
void BuildTopoOrder();
SGSubgraph(std::vector<unsigned> sources, std::vector<unsigned> targets,
std::unordered_map<unsigned, NodeInfo> sections);
};
......@@ -174,6 +181,7 @@ inline Loco::SGSubgraph::SGSubgraph(
: mSources(std::move(sources)), mTargets(std::move(targets)),
mSections(std::move(sections))
{
BuildTopoOrder();
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment