Skip to content

Commit

Permalink
Adde CTreeComparator when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
orlarey committed Jan 17, 2025
1 parent 7c9015b commit d163596
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 38 deletions.
19 changes: 9 additions & 10 deletions compiler/DirectedGraph/DirectedGraphAlgorythm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ inline std::vector<std::vector<N>> parallelize(const digraph<N, Comparator>& g)
}
};

std::map<N, int> levelcache;
std::map<N, int, Comparator> levelcache;
// compute the level of each node in the graph
int l = -1;
for (const N& n : g.nodes()) {
Expand Down Expand Up @@ -582,8 +582,8 @@ inline std::vector<N> leaves(const digraph<N, Comparator>& G)
* @param G
* @return std::vector<N>
*/
template <typename N>
inline std::vector<N> criticalpath(const digraph<N>& G, const N& n)
template <typename N, typename Comparator = std::less<N>>
inline std::vector<N> criticalpath(const digraph<N, Comparator>& G, const N& n)
{
std::vector<N> P;
for (const auto& c : G.destinations(n)) {
Expand Down Expand Up @@ -643,8 +643,8 @@ static std::list<N> interleave(std::list<N>& list1, std::list<N>& list2)
* @param n a node of G
* @return std::list<N> scheduling with duplicates
*/
template <typename N>
inline std::list<N> recschedulenode(const digraph<N>& G, const N& n)
template <typename N, typename Comparator = std::less<N>>
inline std::list<N> recschedulenode(const digraph<N, Comparator>& G, const N& n)
{
std::list<N> P;
for (const auto& c : G.destinations(n)) {
Expand All @@ -662,8 +662,8 @@ inline std::list<N> recschedulenode(const digraph<N>& G, const N& n)
* @param G a DAG
* @return std::list<N> scheduling with duplicates
*/
template <typename N>
inline std::list<N> recschedule(const digraph<N>& G)
template <typename N, typename Comparator = std::less<N>>
inline std::list<N> recschedule(const digraph<N, Comparator>& G)
{
std::list<N> P;
for (const N& n : roots(G)) {
Expand All @@ -673,7 +673,6 @@ inline std::list<N> recschedule(const digraph<N>& G)
return P;
}


/*******************************************************************************
********************************************************************************
Expand Down Expand Up @@ -848,8 +847,8 @@ inline std::ostream& operator<<(std::ostream& file, const digraph<N, Comparator>
* @param g graph we want to analyze
* @return std::vector<int> [n, a, c, l0, l1, ...]
*/
template <typename N>
inline std::vector<int> topology(const digraph<N>& g)
template <typename N, typename Comparator = std::less<N>>
inline std::vector<int> topology(const digraph<N, Comparator>& g)
{
std::vector<int> v;
int n = 0;
Expand Down
16 changes: 8 additions & 8 deletions compiler/DirectedGraph/Schedule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class schedule {
// A schedule in reverse order
schedule reverse() const
{
schedule<N> S;
schedule<N, Comparator> S;
for (auto it = fElements.rbegin(); it != fElements.rend(); ++it) {
S.append(*it);
}
Expand Down Expand Up @@ -166,11 +166,11 @@ inline schedule<N, Comparator> bfschedule(const digraph<N, Comparator>& G)
* @param G
* @return schedule<N>
*/
template <typename N>
inline schedule<N> spschedule(const digraph<N>& G)
template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> spschedule(const digraph<N, Comparator>& G)
{
std::set<N> V; // already scheduled nodes
schedule<N> S; // the final schedule
std::set<N> V; // already scheduled nodes
schedule<N, Comparator> S; // the final schedule

std::list<N> L = recschedule(G); // schedule list with duplicated
for (auto it = L.rbegin(); it != L.rend(); ++it) {
Expand Down Expand Up @@ -253,11 +253,11 @@ inline schedule<N, Comparator> bfcyclesschedule(const digraph<N, Comparator>& G)
* @param G
* @return schedule<N>
*/
template <typename N>
inline schedule<N> rbschedule(const digraph<N>& G)
template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> rbschedule(const digraph<N, Comparator>& G)
{
std::vector<std::vector<N>> P = parallelize(reverse(G));
schedule<N> S;
schedule<N, Comparator> S;

for (uint64_t i = 0; i < P.size(); i++) {
for (const N& n : P[i]) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/generator/compile_scal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ void ScalarCompiler::compileMultiSignal(Tree L)
std::cerr << "Print siglist inst graph topology : " << topology(G) << '\n';
}
// Force a specific scheduling (i.e. compilation order)
schedule<Tree> S;
schedule<Tree, CTreeComparator> S;
switch (gGlobal->gSchedulingStrategy) {
case 0:
S = dfschedule(G);
Expand Down
20 changes: 2 additions & 18 deletions compiler/transform/sigDependenciesGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SigDependenciesGraph : public SignalVisitor {
protected:
digraph<Tree, CTreeComparator> fGraph;
bool fFullGraph;
bool fLimitOndemand = false; // don't go beyond tempvar signals
bool fLimitOndemand = false; // don't go beyond tempvar signals

public:
SigDependenciesGraph(bool full, bool limit)
Expand Down Expand Up @@ -299,22 +299,6 @@ digraph<Tree, CTreeComparator> immediateGraph(Tree L)
return g.getGraph();
}

/**
* @brief Compute the immediate Graph (containing only immediate dependencies)
* of a list of signals and not going beyond tempvar signals
*
* @param L list of signals
* @return digraph<Tree>
*/
digraph<Tree> ondemandGraph(const tvec& signals)
{
SigDependenciesGraph g(false, true);
for (Tree s : signals) {
g.self(s);
}
return g.getGraph();
}

/**
* @brief Compute the immediate Graph (containing only immediate dependencies)
* of a list of signals and not going beyond tempvar signals
Expand Down Expand Up @@ -364,6 +348,6 @@ std::vector<Tree> compilationOrder(Tree L)
*/
std::vector<Tree> ondemandCompilationOrder(const tvec& signals)
{
digraph<Tree> G = ondemandGraph(signals);
digraph<Tree, CTreeComparator> G = ondemandGraph(signals);
return serialize(G);
}
2 changes: 1 addition & 1 deletion compiler/transform/sigDependenciesGraph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ digraph<Tree, CTreeComparator> immediateGraph(Tree L);
* @param L list of signals
* @return digraph<Tree>
*/
digraph<Tree> ondemandGraph(const tvec& V);
digraph<Tree, CTreeComparator> ondemandGraph(const tvec& V);

/**
* @brief Compute the full Graph of a list of signals including immediate and time dependencies
Expand Down

0 comments on commit d163596

Please sign in to comment.