diff --git a/compiler/DirectedGraph/DirectedGraph.hh b/compiler/DirectedGraph/DirectedGraph.hh index 4aa09108d4..0a6724d575 100644 --- a/compiler/DirectedGraph/DirectedGraph.hh +++ b/compiler/DirectedGraph/DirectedGraph.hh @@ -25,10 +25,10 @@ // to represent the time dependency between computations. //=========================================================== -template > +template class digraph { using TWeights = std::set; - using TDestinations = std::map; + using TDestinations = std::map; static inline const TWeights gEmptyWeights; @@ -38,8 +38,8 @@ class digraph { // have integer values attached. class internalgraph { private: - std::set fNodes; // {n1,n2,...} - std::map fConnections; // {(ni -{d1,d2,...}-> nj),...} + std::set fNodes; // {n1,n2,...} + std::map fConnections; // {(ni -{d1,d2,...}-> nj),...} public: #if 0 @@ -70,13 +70,10 @@ class digraph { //---------------------------------------------------------------------- // returns the set of nodes of the graph - [[nodiscard]] const std::set& nodes() const { return fNodes; } + [[nodiscard]] const std::set& nodes() const { return fNodes; } // returns the set of nodes of the graph - [[nodiscard]] const std::map& connections() const - { - return fConnections; - } + [[nodiscard]] const std::map& connections() const { return fConnections; } // Returns the destinations of node n in the graph [[nodiscard]] const TDestinations& destinations(const N& n) const @@ -208,10 +205,10 @@ class digraph { //-------------------------------------------------------------------------- // returns the set of nodes of the graph - [[nodiscard]] const std::set& nodes() const { return fContent->nodes(); } + [[nodiscard]] const std::set& nodes() const { return fContent->nodes(); } // returns the set of nodes of the graph - [[nodiscard]] const std::map& connections() const + [[nodiscard]] const std::map& connections() const { return fContent->connections(); } diff --git a/compiler/DirectedGraph/DirectedGraphAlgorythm.hh b/compiler/DirectedGraph/DirectedGraphAlgorythm.hh index 96f198fc50..7afc8f2716 100644 --- a/compiler/DirectedGraph/DirectedGraphAlgorythm.hh +++ b/compiler/DirectedGraph/DirectedGraphAlgorythm.hh @@ -27,7 +27,7 @@ //=========================================================== //=========================================================== -template > +template class Tarjan { // Additional information associated to each node // during the visit @@ -38,12 +38,12 @@ class Tarjan { int fNum2 = 0; }; - const digraph fGraph; - int fGroup; - std::stack fStack; - std::map fAux; - std::set> fPartition; - int fCycleCount; + const digraph fGraph; + int fGroup; + std::stack fStack; + std::map fAux; + std::set> fPartition; + int fCycleCount; // visit a specific node n of the graph void visit(const N& v) @@ -77,8 +77,8 @@ class Tarjan { if (x.fNum1 == x.fNum2) { // std::cout << "the node " << v << " is the root of a cycle" << std::endl; - std::set cycle; - bool finished = false; + std::set cycle; + bool finished = false; do { const N& w = fStack.top(); fStack.pop(); @@ -95,7 +95,7 @@ class Tarjan { } public: - explicit Tarjan(const digraph& g) : fGraph(g), fGroup(0), fCycleCount(0) + explicit Tarjan(const digraph& g) : fGraph(g), fGroup(0), fCycleCount(0) { for (const auto& n : fGraph.nodes()) { if (fAux.find(n) == fAux.end()) { @@ -104,7 +104,7 @@ class Tarjan { } } - [[nodiscard]] const std::set>& partition() const { return fPartition; } + [[nodiscard]] const std::set>& partition() const { return fPartition; } [[nodiscard]] int cycles() const { return fCycleCount; } }; @@ -116,10 +116,10 @@ class Tarjan { //=========================================================== //=========================================================== -template > -inline int cycles(const digraph& g) +template +inline int cycles(const digraph& g) { - Tarjan T(g); + Tarjan T(g); return T.cycles(); } @@ -132,12 +132,12 @@ inline int cycles(const digraph& g) //=========================================================== //=========================================================== -template > -inline digraph> graph2dag(const digraph& g) +template +inline digraph> graph2dag(const digraph& g) { - Tarjan T(g); // the partition of g - std::map, Comparator> M; // std::mapping between nodes and supernodes - digraph> sg; // the resulting supergraph + Tarjan T(g); // the partition of g + std::map> M; // std::mapping between nodes and supernodes + digraph> sg; // the resulting supergraph // build the graph of supernodes @@ -145,7 +145,7 @@ inline digraph> graph2dag(const digraph& g // create also a std::mapping in order to retrieve the supernode a node /// belongs to. for (const auto& s : T.partition()) { - digraph sn; // the supernode graph + digraph sn; // the supernode graph for (const N& n : s) { // for each node of a cycle M.insert(std::make_pair(n, sn)); // remember its supernode sn.add(n); // and add it to the super node @@ -155,11 +155,11 @@ inline digraph> graph2dag(const digraph& g // compute the destinations between the supernodes for (const auto& n1 : g.nodes()) { - digraph sn1(M[n1]); + digraph sn1(M[n1]); for (const auto& c : g.destinations(n1)) { - const N& n2 = c.first; - const auto& W12 = c.second; - digraph sn2(M[n2]); + const N& n2 = c.first; + const auto& W12 = c.second; + digraph sn2(M[n2]); if (sn1 == sn2) { // the connection is inside the same supernode sn1.add(n1, n2, W12); @@ -182,13 +182,13 @@ inline digraph> graph2dag(const digraph& g //=========================================================== //=========================================================== -template > -inline digraph> graph2dag2(const digraph& g) +template +inline digraph> graph2dag2(const digraph& g) { - Tarjan T(g); // the partition of g - std::map, Comparator> M; // std::mapping between nodes and supernodes - digraph> sg; // the resulting supergraph - std::map, digraph>, int, Comparator> + Tarjan T(g); // the partition of g + std::map> M; // std::mapping between nodes and supernodes + digraph> sg; // the resulting supergraph + std::map, digraph>, int> CC; // count of destinations between supernodes // build the graph of supernodes @@ -197,7 +197,7 @@ inline digraph> graph2dag2(const digraph& // create also a std::mapping in order to retrieve the supernode a node /// belongs to. for (const auto& s : T.partition()) { - digraph sn; // the supernode graph + digraph sn; // the supernode graph for (const N& n : s) { // for each node of a cycle M.insert(std::make_pair(n, sn)); // remember its supernode sn.add(n); // and add it to the super node @@ -207,9 +207,9 @@ inline digraph> graph2dag2(const digraph& // compute the number of destinations between the supernodes for (const auto& n1 : g.nodes()) { // for each node n1 - digraph sn1(M[n1]); // retrieve the supernode + digraph sn1(M[n1]); // retrieve the supernode for (const auto& c : g.destinations(n1)) { // for each destination of n - digraph sn2(M[c.first]); + digraph sn2(M[c.first]); if (sn1 == sn2) { // the connection is inside the same supernode sn1.add(n1, c.first, c.second); @@ -237,17 +237,17 @@ inline digraph> graph2dag2(const digraph& //=========================================================== //=========================================================== -template > -inline std::vector> parallelize(const digraph& g) +template +inline std::vector> parallelize(const digraph& g) { //----------------------------------------------------------- // Find the level of a node n -> {m1,m2,...} such that // level(n -> {}) = 0 // level(n -> {m1,m2,...}) = 1 + std::max(level(mi)) //----------------------------------------------------------- - using Levelfun = std::function&)>; + using Levelfun = std::function&)>; - Levelfun level = [&g, &level](const N& n1, std::map& levelcache) -> int { + Levelfun level = [&g, &level](const N& n1, std::map& levelcache) -> int { auto p = levelcache.find(n1); if (p != levelcache.end()) { return p->second; @@ -277,8 +277,8 @@ inline std::vector> parallelize(const digraph& g) return v; } -template > -inline std::vector> rparallelize(const digraph& G) +template +inline std::vector> rparallelize(const digraph& G) { std::vector> P = parallelize(G); int i = 0; @@ -300,8 +300,8 @@ inline std::vector> rparallelize(const digraph& G) //=========================================================== //=========================================================== -template > -inline std::vector serialize(const digraph& G) +template +inline std::vector serialize(const digraph& G) { //------------------------------------------------------------------------ // visit : a local std::function (simulated using a lambda) to visit a graph @@ -310,10 +310,9 @@ inline std::vector serialize(const digraph& G) // V : std::set of already visited nodes // S : serialized std::vector of nodes //------------------------------------------------------------------------ - using Visitfun = std::function&, const N&, - std::set&, std::vector&)>; - Visitfun visit = [&visit](const digraph& g, const N& n, - std::set& V, std::vector& S) { + using Visitfun = + std::function&, const N&, std::set&, std::vector&)>; + Visitfun visit = [&visit](const digraph& g, const N& n, std::set& V, std::vector& S) { if (V.find(n) == V.end()) { V.insert(n); for (const auto& p : g.destinations(n)) { @@ -323,8 +322,8 @@ inline std::vector serialize(const digraph& G) } }; - std::vector S; - std::set V; + std::vector S; + std::set V; for (const N& n : G.nodes()) { visit(G, n, V, S); } @@ -338,13 +337,11 @@ inline std::vector serialize(const digraph& G) //=========================================================== //=========================================================== -template , - typename Comparator2 = std::less> -inline digraph mapnodes(const digraph& g, - std::function foo) +template +inline digraph mapnodes(const digraph& g, std::function foo) { - digraph r; - std::map cache; + digraph r; + std::map cache; // create a new graph with the transformed nodes for (const auto& n1 : g.nodes()) { M n2 = foo(n1); @@ -369,10 +366,10 @@ inline digraph mapnodes(const digraph& g, //=========================================================== //=========================================================== -template > -inline digraph reverse(const digraph& g) +template +inline digraph reverse(const digraph& g) { - digraph r; + digraph r; // copy the destinations for (const auto& n : g.nodes()) { r.add(n); @@ -393,11 +390,11 @@ inline digraph reverse(const digraph& g) //=========================================================== //=========================================================== -template > -inline digraph mapconnections(const digraph& G, +template +inline digraph mapconnections(const digraph& G, std::function&)> keep) { - digraph R; + digraph R; for (const N& n : G.nodes()) { R.add(n); for (const auto& c : G.destinations(n)) { @@ -425,9 +422,9 @@ inline digraph mapconnections(const digraph& * @param L resulting graph of left nodes * @param R resulting graph of right nodes */ -template > -void splitgraph(const digraph& G, std::function left, - digraph& L, digraph& R) +template +void splitgraph(const digraph& G, std::function left, digraph& L, + digraph& R) { for (auto n : G.nodes()) { if (left(n)) { @@ -462,14 +459,14 @@ void splitgraph(const digraph& G, std::function l * @param S the set of nodes to keep with their dependencies * @return the resulting subgraph */ -template > -digraph subgraph(const digraph& G, const std::set& S) +template +digraph subgraph(const digraph& G, const std::set& S) { - digraph R; // the (R)esulting graph - std::set W{S}; // nodes (W)aiting to be processed - std::set P; // nodes already (P)rocessed + digraph R; // the (R)esulting graph + std::set W{S}; // nodes (W)aiting to be processed + std::set P; // nodes already (P)rocessed while (!W.empty()) { - std::set M; // (M)ore nodes to process at next iteration + std::set M; // (M)ore nodes to process at next iteration for (auto n : W) { R.add(n); // add n to the resulting graph P.insert(n); // mark n as processed @@ -492,10 +489,10 @@ digraph subgraph(const digraph& G, const std::set< //=========================================================== //=========================================================== -template > -inline digraph cut(const digraph& G, int dm) +template +inline digraph cut(const digraph& G, int dm) { - digraph R; + digraph R; for (const auto& n1 : G.nodes()) { R.add(n1); for (const auto& c : G.destinations(n1)) { @@ -526,11 +523,11 @@ inline digraph cut(const digraph& G, int dm) //=========================================================== //=========================================================== -template > -inline digraph chain(const digraph& g, bool strict) +template +inline digraph chain(const digraph& g, bool strict) { - const digraph h = reverse(g); - digraph r; + const digraph h = reverse(g); + digraph r; for (const auto& n : g.nodes()) { if (!strict) { r.add(n); @@ -546,10 +543,10 @@ inline digraph chain(const digraph& g, bool strict return r; } -template > -inline std::vector roots(const digraph& G) +template +inline std::vector roots(const digraph& G) { - std::map R; + std::map R; for (const N& n : G.nodes()) { for (const auto& c : G.destinations(n)) { R[c.first]++; @@ -564,8 +561,8 @@ inline std::vector roots(const digraph& G) return V; } -template > -inline std::vector leaves(const digraph& G) +template +inline std::vector leaves(const digraph& G) { std::vector L; for (const N& n : G.nodes()) { @@ -590,7 +587,7 @@ inline std::vector leaves(const digraph& G) //=========================================================== //=========================================================== -template > +template inline std::ostream& operator<<(std::ostream& file, const std::list& L) { std::string sep = ""; @@ -609,7 +606,7 @@ inline std::ostream& operator<<(std::ostream& file, const std::list& L) //=========================================================== //=========================================================== -template > +template inline std::ostream& operator<<(std::ostream& file, const std::vector& V) { std::string sep = ""; @@ -628,7 +625,7 @@ inline std::ostream& operator<<(std::ostream& file, const std::vector& V) //=========================================================== //=========================================================== -template > +template inline std::ostream& operator<<(std::ostream& file, const std::set& S) { std::string sep = ""; @@ -647,8 +644,7 @@ inline std::ostream& operator<<(std::ostream& file, const std::set& S) //=========================================================== //=========================================================== -template , - typename Comparator2 = std::less> +template inline std::ostream& operator<<(std::ostream& file, const std::pair& V) { return file << "std::pair{" << V.first << ", " << V.second << "}"; @@ -660,9 +656,8 @@ inline std::ostream& operator<<(std::ostream& file, const std::pair& V) //=========================================================== //=========================================================== -template > -inline std::ostream& dotfile(std::ostream& file, const digraph& g, - bool clusters = false) +template +inline std::ostream& dotfile(std::ostream& file, const digraph& g, bool clusters = false) { file << "digraph mygraph {" << std::endl; for (const N& n : g.nodes()) { @@ -682,8 +677,8 @@ inline std::ostream& dotfile(std::ostream& file, const digraph& g } if (clusters) { - Tarjan T(g); - int ccount = 0; // cluster count + Tarjan T(g); + int ccount = 0; // cluster count for (const auto& s : T.partition()) { file << "\t" << "subgraph cluster" << ccount++ << " { " << std::endl; @@ -704,8 +699,8 @@ inline std::ostream& dotfile(std::ostream& file, const digraph& g //=========================================================== //=========================================================== -template > -inline std::ostream& operator<<(std::ostream& file, const digraph& g) +template +inline std::ostream& operator<<(std::ostream& file, const digraph& g) { std::string sep = ""; diff --git a/compiler/DirectedGraph/Schedule.hh b/compiler/DirectedGraph/Schedule.hh index 93551e3e72..b34836711a 100644 --- a/compiler/DirectedGraph/Schedule.hh +++ b/compiler/DirectedGraph/Schedule.hh @@ -30,12 +30,11 @@ * * @tparam N */ -template > +template class schedule { private: - std::vector fElements; // ordered set of elements - std::map - fOrder; // order of each element (starting at 1, 0 indicates not in schedule) + std::vector fElements; // ordered set of elements + std::map fOrder; // order of each element (starting at 1, 0 indicates not in schedule) public: // number of elements in the schedule @@ -64,7 +63,7 @@ class schedule { } // append all the elements of a schedule - schedule& append(const schedule& S) + schedule& append(const schedule& S) { for (const N& n : S.elements()) { append(n); @@ -81,8 +80,8 @@ class schedule { * @param S the schedule * @return std::ostream& the output stream */ -template > -inline std::ostream& operator<<(std::ostream& file, const schedule& S) +template +inline std::ostream& operator<<(std::ostream& file, const schedule& S) { std::string sep = ""; @@ -101,11 +100,11 @@ inline std::ostream& operator<<(std::ostream& file, const schedule the deep first schedule of G */ -template > -inline schedule dfschedule(const digraph& G) +template +inline schedule dfschedule(const digraph& G) { - schedule S; - std::set V; // set of visited nodes + schedule S; + std::set V; // set of visited nodes // recursive deep first visit (pseudo local function using a lambda) std::function dfvisit = [&](const N& n) { @@ -133,11 +132,11 @@ inline schedule dfschedule(const digraph& G) * @return schedule the breadth first schedule of G */ -template > -inline schedule bfschedule(const digraph& G) +template +inline schedule bfschedule(const digraph& G) { std::vector> P = parallelize(G); - schedule S; + schedule S; for (uint64_t i = 0; i < P.size(); i++) { for (const N& n : P[i]) { @@ -158,8 +157,8 @@ inline schedule bfschedule(const digraph& G) * @param S * @return int */ -template > -inline int schedulingcost(const digraph& G, const schedule& S) +template +inline int schedulingcost(const digraph& G, const schedule& S) { int cost = 0; for (const N& n : G.nodes()) { @@ -180,13 +179,13 @@ inline int schedulingcost(const digraph& G, const schedule the deep first schedule of G */ -template > -inline schedule dfcyclesschedule(const digraph& G) +template +inline schedule dfcyclesschedule(const digraph& G) { - digraph> H = graph2dag(G); - schedule> SH = dfschedule(H); - schedule S; - for (const digraph& n : SH.elements()) { + digraph> H = graph2dag(G); + schedule> SH = dfschedule(H); + schedule S; + for (const digraph& n : SH.elements()) { S.append(dfschedule(cut(n, 1))); } return S; @@ -199,13 +198,13 @@ inline schedule dfcyclesschedule(const digraph& G) * @param G the graph we want to schedule * @return schedule the deep first schedule of G */ -template > -inline schedule bfcyclesschedule(const digraph& G) +template +inline schedule bfcyclesschedule(const digraph& G) { - digraph> H = graph2dag(G); - schedule> SH = bfschedule(H); - schedule S; - for (const digraph& n : SH.elements()) { + digraph> H = graph2dag(G); + schedule> SH = bfschedule(H); + schedule S; + for (const digraph& n : SH.elements()) { S.append(dfschedule(cut(n, 1))); } return S; diff --git a/compiler/documentator/doc.cpp b/compiler/documentator/doc.cpp index fd317a74aa..8f45e885c1 100644 --- a/compiler/documentator/doc.cpp +++ b/compiler/documentator/doc.cpp @@ -319,8 +319,8 @@ static void printLatexHeader(istream& latexheader, const string& faustversion, o static void printDocMetadata(const Tree expr, ostream& docout) { if (gGlobal->gMetaDataSet.count(expr)) { - string sep = ""; - set mset = gGlobal->gMetaDataSet[expr]; + string sep = ""; + set mset = gGlobal->gMetaDataSet[expr]; for (set::iterator j = mset.begin(); j != mset.end(); j++) { docout << sep << unquote(tree2str(*j)); sep = ", "; diff --git a/compiler/draw/sigToGraph.cpp b/compiler/draw/sigToGraph.cpp index 447d0d30bd..9c5253e7e8 100644 --- a/compiler/draw/sigToGraph.cpp +++ b/compiler/draw/sigToGraph.cpp @@ -38,7 +38,7 @@ using namespace std; -static void recdraw(Tree sig, set& drawn, ostream& fout); +static void recdraw(Tree sig, set& drawn, ostream& fout); static string nodeattr(Type t); static string edgeattr(Type t); static string sigLabel(Tree sig); @@ -48,7 +48,7 @@ static string sigLabel(Tree sig); */ void sigToGraph(Tree L, ostream& fout) { - set alreadyDrawn; + set alreadyDrawn; fout << "strict digraph loopgraph {\n" << " rankdir=LR; node [fontsize=10];" << endl; @@ -70,7 +70,7 @@ void sigToGraph(Tree L, ostream& fout) /** * Draw recursively a signal */ -static void recdraw(Tree sig, set& drawn, ostream& fout) +static void recdraw(Tree sig, set& drawn, ostream& fout) { // cerr << ++gGlobal->TABBER << "ENTER REC DRAW OF " << sig << "$" << *sig << endl; tvec subsig; diff --git a/compiler/generator/code_container.cpp b/compiler/generator/code_container.cpp index c8e5de1c0a..230d2e59c2 100644 --- a/compiler/generator/code_container.cpp +++ b/compiler/generator/code_container.cpp @@ -132,8 +132,7 @@ bool CodeContainer::getLoopProperty(Tree sig, CodeLoop*& l) return fLoopProperty.get(sig, l); } -void CodeContainer::listAllLoopProperties(Tree sig, set& L, - set& visited) +void CodeContainer::listAllLoopProperties(Tree sig, set& L, set& visited) { if (visited.count(sig) == 0) { visited.insert(sig); @@ -179,8 +178,8 @@ void CodeContainer::closeLoop(Tree sig) faustassert(fCurLoop); // fix the missing dependencies - set L; - set V; + set L; + set V; listAllLoopProperties(sig, L, V); for (CodeLoop* l : L) { fCurLoop->fBackwardLoopDependencies.insert(l); diff --git a/compiler/generator/code_container.hh b/compiler/generator/code_container.hh index 612be408c5..e27a12409c 100644 --- a/compiler/generator/code_container.hh +++ b/compiler/generator/code_container.hh @@ -176,7 +176,7 @@ class CodeContainer : public virtual Garbageable { void printHeader(std::ostream& dst) { // defines the metadata we want to print as comments at the begin of in the file - std::set selectedKeys; + std::set selectedKeys; selectedKeys.insert(tree("name")); selectedKeys.insert(tree("author")); selectedKeys.insert(tree("copyright")); @@ -280,9 +280,9 @@ class CodeContainer : public virtual Garbageable { void setLoopProperty(Tree sig, CodeLoop* l); ///< Store the loop used to compute a signal bool getLoopProperty(Tree sig, CodeLoop*& l); ///< Returns the loop used to compute a signal - void listAllLoopProperties(Tree sig, std::set&, - std::set& - visited); ///< Returns all the loop used to compute a signal + void listAllLoopProperties( + Tree sig, std::set&, + std::set& visited); ///< Returns all the loop used to compute a signal void printGraphDotFormat(std::ostream& fout); diff --git a/compiler/generator/compile.cpp b/compiler/generator/compile.cpp index 1008807aa9..09c7e7dc70 100644 --- a/compiler/generator/compile.cpp +++ b/compiler/generator/compile.cpp @@ -128,7 +128,7 @@ static string wdel(const string& s) void Compiler::generateMetaData() { // Add global metadata - for (map>::iterator i = gGlobal->gMetaDataSet.begin(); + for (map>::iterator i = gGlobal->gMetaDataSet.begin(); i != gGlobal->gMetaDataSet.end(); i++) { if (i->first != tree("author")) { stringstream str1, str2; @@ -138,8 +138,7 @@ void Compiler::generateMetaData() string res2 = unquote(str2.str()); fJSON.declare(res1.c_str(), res2.c_str()); } else { - for (set::iterator j = i->second.begin(); j != i->second.end(); - j++) { + for (set::iterator j = i->second.begin(); j != i->second.end(); j++) { if (j == i->second.begin()) { stringstream str1, str2; str1 << *(i->first); diff --git a/compiler/generator/compile_scal.cpp b/compiler/generator/compile_scal.cpp index 0e70bcfd3c..65548f903a 100644 --- a/compiler/generator/compile_scal.cpp +++ b/compiler/generator/compile_scal.cpp @@ -273,7 +273,7 @@ void ScalarCompiler::conditionStatistics(Tree l) void ScalarCompiler::conditionStatistics(Tree l) { - map + map fConditionStatistics; // used with the new X,Y:enable --> sigEnable(X*Y,Y>0) primitive for (const auto& p : fConditionProperty) { for (Tree lc = p.second; !isNil(lc); lc = tl(lc)) { diff --git a/compiler/generator/compile_scal.hh b/compiler/generator/compile_scal.hh index a161eb8c17..aa0b9d160e 100644 --- a/compiler/generator/compile_scal.hh +++ b/compiler/generator/compile_scal.hh @@ -49,15 +49,15 @@ class ScalarCompiler : public Compiler { property > fInstanceInitProperty; // property added to solve 20101208 kjetil bug - std::map + std::map fConditionProperty; // used with the new X,Y:enable --> sigControl(X*Y,Y>0) primitive - static std::map fIDCounters; - Tree fSharingKey; - OccMarkup* fOccMarkup; - int fMaxIota; - std::map fIotaCache; - std::map fScheduleOrder; + static std::map fIDCounters; + Tree fSharingKey; + OccMarkup* fOccMarkup; + int fMaxIota; + std::map fIotaCache; + std::map fScheduleOrder; public: ScalarCompiler(const std::string& name, const std::string& super, int numInputs, int numOutputs) diff --git a/compiler/generator/instructions_compiler.cpp b/compiler/generator/instructions_compiler.cpp index 3fd1845003..fa378fa2c7 100644 --- a/compiler/generator/instructions_compiler.cpp +++ b/compiler/generator/instructions_compiler.cpp @@ -264,7 +264,7 @@ void InstructionsCompiler::conditionStatistics(Tree l) void InstructionsCompiler::conditionStatistics(Tree l) { - map + map fConditionStatistics; // used with the new X,Y:enable --> sigEnable(X*Y,Y != 0) primitive for (const auto& p : fConditionProperty) { for (Tree lc = p.second; !isNil(lc); lc = tl(lc)) { diff --git a/compiler/generator/instructions_compiler.hh b/compiler/generator/instructions_compiler.hh index 3ee05bf68d..d3b2cd9945 100644 --- a/compiler/generator/instructions_compiler.hh +++ b/compiler/generator/instructions_compiler.hh @@ -49,7 +49,7 @@ class InstructionsCompiler : public virtual Garbageable { property> fInstanceInitProperty; property fTableProperty; - std::map + std::map fConditionProperty; // used with the new X,Y:enable --> sigControl(X*Y,Y>0) primitive Tree fSharingKey; diff --git a/compiler/generator/klass.cpp b/compiler/generator/klass.cpp index 5795ee7a88..a16cb7e434 100644 --- a/compiler/generator/klass.cpp +++ b/compiler/generator/klass.cpp @@ -88,7 +88,7 @@ void Klass::openLoop(Tree recsymbol, const string& size) // cerr << "\nOPEN REC LOOP(" << *recsymbol << ", " << size << ") ----> " << fTopLoop << endl; } -void Klass::listAllLoopProperties(Tree sig, set& L, set& visited) +void Klass::listAllLoopProperties(Tree sig, set& L, set& visited) { if (visited.count(sig) == 0) { visited.insert(sig); @@ -115,8 +115,8 @@ void Klass::closeLoop(Tree sig) faustassert(fTopLoop); // fix the missing dependencies - set L; - set V; + set L; + set V; listAllLoopProperties(sig, L, V); for (Loop* l : L) { fTopLoop->fBackwardLoopDependencies.insert(l); diff --git a/compiler/generator/klass.hh b/compiler/generator/klass.hh index 699fbf3db3..b03267ee3a 100644 --- a/compiler/generator/klass.hh +++ b/compiler/generator/klass.hh @@ -136,9 +136,9 @@ class Klass { void setLoopProperty(Tree sig, Loop* l); ///< Store the loop used to compute a signal bool getLoopProperty(Tree sig, Loop*& l); ///< Returns the loop used to compute a signal - void listAllLoopProperties(Tree sig, std::set&, - std::set& - visited); ///< Returns all the loop used to compute a signal + void listAllLoopProperties( + Tree sig, std::set&, + std::set& visited); ///< Returns all the loop used to compute a signal const std::string& getClassName() const { diff --git a/compiler/generator/occurrences.hh b/compiler/generator/occurrences.hh index f0477bcd54..833d73c13b 100644 --- a/compiler/generator/occurrences.hh +++ b/compiler/generator/occurrences.hh @@ -56,9 +56,9 @@ class Occurrences : public virtual Garbageable { * second om.mark(root) then om.retrieve(subtree) */ class OccMarkup : public virtual Garbageable { - Tree fRootTree; ///< occurrences computed within this tree - Tree fPropKey; ///< key used to store occurrences property - std::map fConditions; ///< condition associated to each tree + Tree fRootTree; ///< occurrences computed within this tree + Tree fPropKey; ///< key used to store occurrences property + std::map fConditions; ///< condition associated to each tree void incOcc(Tree env, int v, int r, int d, Tree xc, Tree t); ///< inc the occurrence of t in context v,r @@ -67,7 +67,7 @@ class OccMarkup : public virtual Garbageable { public: OccMarkup() : fRootTree(nullptr), fPropKey(nullptr) {} - OccMarkup(std::map conditions) + OccMarkup(std::map conditions) : fRootTree(nullptr), fPropKey(nullptr), fConditions(conditions) { } diff --git a/compiler/global.hh b/compiler/global.hh index f8c8a20bec..8ddf4db0c0 100644 --- a/compiler/global.hh +++ b/compiler/global.hh @@ -82,9 +82,8 @@ struct comp_str { bool operator()(Tree s1, Tree s2) const { return (strcmp(tree2str(s1), tree2str(s2)) < 0); } }; -typedef std::map, comp_str> MetaDataSet; -typedef std::map, CTreeComparator> - FunMDSet; // foo -> {(file/foo/key,value)...} +typedef std::map, comp_str> MetaDataSet; +typedef std::map> FunMDSet; // foo -> {(file/foo/key,value)...} // Global outside of the global context extern std::vector gWarningMessages; @@ -256,7 +255,7 @@ struct global { bool gLstMdocTagsSwitch; // mdoc listing management bool gLstDistributedSwitch; // mdoc listing management - std::unordered_map> gDependencies; + std::unordered_map> gDependencies; bool gAutoDifferentiate; @@ -292,8 +291,8 @@ struct global { // Tree is used to identify the same nodes during Box tree traversal, // but gBoxCounter is then used to generate unique IDs - std::map, CTreeComparator> gBoxTable; - int gBoxCounter; + std::map> gBoxTable; + int gBoxCounter; // To keep the box tree traversing trace std::vector gBoxTrace; @@ -302,8 +301,8 @@ struct global { // ------------ // Tree is used to identify the same nodes during Signal tree traversal, // but gSignalCounter is then used to generate unique IDs - std::map, CTreeComparator> gSignalTable; - int gSignalCounter; + std::map> gSignalTable; + int gSignalCounter; // To keep the signal tree traversing trace std::vector gSignalTrace; @@ -544,15 +543,14 @@ struct global { std::map gIDCounters; // Internal state during drawing - Occur* gOccurrences; - bool gFoldingFlag; // true with complex block-diagrams - std::stack gPendingExp; // Expressions that need to be drawn - std::set gDrawnExp; // Expressions drawn or scheduled so far - const char* gDevSuffix; // .svg or .ps used to choose output device - std::string gSchemaFileName; // name of schema file beeing generated - Tree gInverter[6]; - std::map - gBackLink; // link to enclosing file for sub schema + Occur* gOccurrences; + bool gFoldingFlag; // true with complex block-diagrams + std::stack gPendingExp; // Expressions that need to be drawn + std::set gDrawnExp; // Expressions drawn or scheduled so far + const char* gDevSuffix; // .svg or .ps used to choose output device + std::string gSchemaFileName; // name of schema file beeing generated + Tree gInverter[6]; + std::map gBackLink; // link to enclosing file for sub schema // FIR std::map diff --git a/compiler/libcode.cpp b/compiler/libcode.cpp index 9853febf25..56fd8316bb 100644 --- a/compiler/libcode.cpp +++ b/compiler/libcode.cpp @@ -985,7 +985,7 @@ static void generateCodeAux1(unique_ptr& helpers, unique_ptr& static void printHeader(ostream& dst) { // defines the metadata we want to print as comments at the begin of in the C++ file - set selectedKeys; + set selectedKeys; selectedKeys.insert(tree("name")); selectedKeys.insert(tree("author")); selectedKeys.insert(tree("copyright")); diff --git a/compiler/normalize/aterm.hh b/compiler/normalize/aterm.hh index e894cb109c..738963561c 100644 --- a/compiler/normalize/aterm.hh +++ b/compiler/normalize/aterm.hh @@ -42,8 +42,7 @@ */ class aterm : public virtual Garbageable { - std::map - fSig2MTerms; ///< mapping between signatures and corresponding mterms + std::map fSig2MTerms; ///< mapping between signatures and corresponding mterms public: aterm(); ///< create an empty aterm (equivalent to 0) diff --git a/compiler/normalize/mterm.hh b/compiler/normalize/mterm.hh index ecb85e9662..e98dc47c80 100644 --- a/compiler/normalize/mterm.hh +++ b/compiler/normalize/mterm.hh @@ -41,8 +41,8 @@ */ class mterm : public virtual Garbageable { - Tree fCoef; ///< constant part of the term (usually 1 or -1) - std::map fFactors; ///< non constant terms and their power + Tree fCoef; ///< constant part of the term (usually 1 or -1) + std::map fFactors; ///< non constant terms and their power public: mterm(); ///< create a 0 mterm diff --git a/compiler/parser/sourcereader.cpp b/compiler/parser/sourcereader.cpp index 2fc58eca9c..891091a470 100644 --- a/compiler/parser/sourcereader.cpp +++ b/compiler/parser/sourcereader.cpp @@ -75,7 +75,7 @@ extern const char* FAUSTfilename; static bool standardArgList(Tree args) { - map L; + map L; while (isList(args)) { if (!isBoxIdent(hd(args))) return false; if (++L[hd(args)] > 1) return false; @@ -434,8 +434,8 @@ Tree SourceReader::expandRec(Tree ldef, set& visited, Tree lresult) Tree formatDefinitions(Tree rldef) { - map, CTreeComparator> dic; - map , CTreeComparator>::iterator p; + map> dic; + map >::iterator p; Tree ldef2 = gGlobal->nil; Tree file; diff --git a/compiler/signals/recursivness.cpp b/compiler/signals/recursivness.cpp index b452304e10..8dc8852bc5 100644 --- a/compiler/signals/recursivness.cpp +++ b/compiler/signals/recursivness.cpp @@ -141,7 +141,7 @@ static int position(Tree env, Tree t, int p) * @param sig the signal to analyze * @return the set of symbols */ -static Tree symlistVisit(Tree sig, set& visited) +static Tree symlistVisit(Tree sig, set& visited) { Tree S; @@ -180,7 +180,7 @@ Tree symlist(Tree sig) Tree S; if (!gGlobal->gSymListProp->get(sig, S)) { - set visited; + set visited; S = symlistVisit(sig, visited); gGlobal->gSymListProp->set(sig, S); } diff --git a/compiler/tlib/tree.hh b/compiler/tlib/tree.hh index f92b0ea55e..eabcee300f 100644 --- a/compiler/tlib/tree.hh +++ b/compiler/tlib/tree.hh @@ -84,6 +84,17 @@ typedef CTree* Tree; typedef std::vector tvec; +namespace std { + +// The std::less comparison function is redefined to provide an unique and stable ordering +// for all CTree instances and so maintain determinism. +template <> +struct less { + bool operator()(const CTree* lhs, const CTree* rhs) const; +}; + +} + /** * A CTree = (Node x [CTree]) is the association of a content Node and a list of subtrees * called branches. In order to maximize the sharing of trees, hashconsing techniques are used. @@ -107,17 +118,10 @@ class LIBFAUST_API CTree : public virtual Garbageable { public: static bool gDetails; ///< CTree::print() print with more details when true - static unsigned int - gVisitTime; ///< Should be incremented for each new visit to keep track of visited tree - - struct TreeComparator { - bool operator()(const Tree& lhs, const Tree& rhs) const - { - return lhs->serial() < rhs->serial(); - } - }; + ///< Should be incremented for each new visit to keep track of visited tree + static unsigned int gVisitTime; - typedef std::map plist; + typedef std::map plist; protected: // fields @@ -134,11 +138,12 @@ class LIBFAUST_API CTree : public virtual Garbageable { CTree() : fNext(nullptr), fType(nullptr), fHashKey(0), fSerial(0), fAperture(0), fVisitTime(0) { } - CTree(size_t hk, const Node& n, - const tvec& br); ///< construction is private, uses tree::make instead + ///< construction is private, uses tree::make instead + CTree(size_t hk, const Node& n, const tvec& br); + + ///< used to check if an equivalent tree already exists + bool equiv(const Node& n, const tvec& br) const; - bool equiv(const Node& n, - const tvec& br) const; ///< used to check if an equivalent tree already exists static size_t calcTreeHash( const Node& n, const tvec& br); ///< compute the hash key of a tree according to its node and branches @@ -198,7 +203,14 @@ class LIBFAUST_API CTree : public virtual Garbageable { } }; -using CTreeComparator = CTree::TreeComparator; +// The comparison function relies on lhs->serial() which provides an unique and stable ordering +// for all CTree instances and so maintain determinism. +namespace std { +inline bool less::operator()(const CTree* lhs, const CTree* rhs) const +{ + return lhs->serial() < rhs->serial(); +} +}; //---------------------------------API--------------------------------------- // To build trees diff --git a/compiler/transform/sigDependenciesGraph.cpp b/compiler/transform/sigDependenciesGraph.cpp index 6b5a6fa22f..d99a32bf4a 100644 --- a/compiler/transform/sigDependenciesGraph.cpp +++ b/compiler/transform/sigDependenciesGraph.cpp @@ -11,8 +11,8 @@ */ class SigDependenciesGraph : public SignalVisitor { protected: - digraph fGraph; - bool fFullGraph; + digraph fGraph; + bool fFullGraph; public: SigDependenciesGraph(bool full) : SignalVisitor(), fFullGraph(full) @@ -21,7 +21,7 @@ class SigDependenciesGraph : public SignalVisitor { fMessage = "SigDependenciesGraph"; } - digraph getGraph() { return fGraph; } + digraph getGraph() { return fGraph; } protected: void visit(Tree t) override; @@ -124,9 +124,9 @@ void SigDependenciesGraph::visit(Tree t) * of a list of signals * * @param L list of signals - * @return digraph + * @return digraph */ -digraph immediateGraph(Tree L) +digraph immediateGraph(Tree L) { SigDependenciesGraph g(false); g.mapself(L); @@ -137,9 +137,9 @@ digraph immediateGraph(Tree L) * @brief Compute the full Graph (all dependencies) of a list of signals * * @param L list of signals - * @return digraph + * @return digraph */ -digraph fullGraph(Tree L) +digraph fullGraph(Tree L) { SigDependenciesGraph g(true); g.mapself(L); @@ -154,6 +154,6 @@ digraph fullGraph(Tree L) */ std::vector compilationOrder(Tree L) { - digraph G = immediateGraph(L); + digraph G = immediateGraph(L); return serialize(G); } diff --git a/compiler/transform/sigDependenciesGraph.hh b/compiler/transform/sigDependenciesGraph.hh index 617e7eea5a..cf464c3892 100644 --- a/compiler/transform/sigDependenciesGraph.hh +++ b/compiler/transform/sigDependenciesGraph.hh @@ -9,7 +9,7 @@ * @param L list of signals * @return digraph */ -digraph immediateGraph(Tree L); +digraph immediateGraph(Tree L); /** * @brief Compute the full Graph of a list of signals @@ -17,7 +17,7 @@ digraph immediateGraph(Tree L); * @param L list of signals * @return digraph */ -digraph fullGraph(Tree L); +digraph fullGraph(Tree L); /** * @brief Compute in which order the list of signals L should be compiled diff --git a/compiler/transform/sigNewConstantPropagation.cpp b/compiler/transform/sigNewConstantPropagation.cpp index bc81f3ba79..2ce6cc8385 100644 --- a/compiler/transform/sigNewConstantPropagation.cpp +++ b/compiler/transform/sigNewConstantPropagation.cpp @@ -40,9 +40,9 @@ class SigNewConstantPropagation final : public SignalIdentity { }; static void explainInterval(Tree sig) { - digraph G = fullGraph(list1(sig)); - schedule S = dfcyclesschedule(G); - int i = 0; + digraph G = fullGraph(list1(sig)); + schedule S = dfcyclesschedule(G); + int i = 0; std::cerr << "\n\n EXPLAIN INTERVAL: " << getCertifiedSigType(sig)->getInterval() << " FOR SIGNAL " << sig << " = " << ppsig(sig, 10) << std::endl; for (Tree s : S.elements()) { diff --git a/compiler/transform/sigRecursiveDependencies.cpp b/compiler/transform/sigRecursiveDependencies.cpp index dc239f8fec..23d82fd2fc 100644 --- a/compiler/transform/sigRecursiveDependencies.cpp +++ b/compiler/transform/sigRecursiveDependencies.cpp @@ -59,9 +59,9 @@ * * @param underVisit, stack of projections under visit (prevent infinite loops) * @param sig - * @return std::set set of dependencies of sig + * @return std::set set of dependencies of sig */ -static std::set sigDependencies(std::vector& underVisit, Tree sig) +static std::set sigDependencies(std::vector& underVisit, Tree sig) { int i; Tree rec, id, le; @@ -70,7 +70,7 @@ static std::set sigDependencies(std::vector& underV return gGlobal->gDependencies[sig]; } else if (isProj(sig, &i, rec)) { // 2) sig is a projection, its dependencies are itself and the dependecies of its definition - std::set deps; + std::set deps; if (std::find(underVisit.begin(), underVisit.end(), sig) == underVisit.end()) { // we mark the projection under visit and compute the dependencies of its definition underVisit.push_back(sig); @@ -85,9 +85,9 @@ static std::set sigDependencies(std::vector& underV } else { // 3) sig is not a projection but is any other expression, // its dependencies are the dependencies of its branches - std::set deps; + std::set deps; for (Tree b : sig->branches()) { - std::set depsb = sigDependencies(underVisit, b); + std::set depsb = sigDependencies(underVisit, b); deps.insert(depsb.begin(), depsb.end()); } gGlobal->gDependencies[sig] = deps; @@ -99,9 +99,9 @@ static std::set sigDependencies(std::vector& underV * @brief compute the set of recursive dependencies of a signal * * @param sig - * @return std::set + * @return std::set */ -std::set signalDependencies(Tree sig) +std::set signalDependencies(Tree sig) { std::vector underVisit; return sigDependencies(underVisit, sig); @@ -117,8 +117,8 @@ std::set signalDependencies(Tree sig) */ bool isSignalRecursive(Tree proj) { - std::set deps = signalDependencies(getProjDefinition(proj)); - bool answer = deps.find(proj) != deps.end(); + std::set deps = signalDependencies(getProjDefinition(proj)); + bool answer = deps.find(proj) != deps.end(); #if 0 if (answer) { std::cerr << "\nSignal " << *proj << " is recursive. Its dependencies are: ("; @@ -147,8 +147,8 @@ bool isSignalRecursive(Tree proj) */ bool isDependingOn(Tree sig, Tree proj) { - std::set deps = signalDependencies(sig); - bool answer = deps.find(proj) != deps.end(); + std::set deps = signalDependencies(sig); + bool answer = deps.find(proj) != deps.end(); return answer; } @@ -192,7 +192,7 @@ Tree getProjFinalDefinition(Tree proj) */ void printDependencies(const std::string& msg, Tree sig) { - std::set deps = signalDependencies(sig); + std::set deps = signalDependencies(sig); std::cerr << msg << " dependencies of " << ppsig(sig, 20) << " are: ("; for (Tree d : deps) { std::cerr << *d << " "; diff --git a/compiler/transform/sigRecursiveDependencies.hh b/compiler/transform/sigRecursiveDependencies.hh index 19d56b1209..c5f8d6d89e 100644 --- a/compiler/transform/sigRecursiveDependencies.hh +++ b/compiler/transform/sigRecursiveDependencies.hh @@ -42,7 +42,7 @@ * @param sig * @return std::set */ -std::set signalDependencies(Tree sig); +std::set signalDependencies(Tree sig); /** * @brief true if signal is a recursive projection that depends on itself, false otherwise diff --git a/compiler/transform/signalRenderer.hh b/compiler/transform/signalRenderer.hh index b82eb2e1ac..4faf27a3d3 100644 --- a/compiler/transform/signalRenderer.hh +++ b/compiler/transform/signalRenderer.hh @@ -120,11 +120,11 @@ struct SignalRenderer : public SignalVisitor { * @tparam REAL */ struct SignalBuilder : public SignalVisitor { - std::map, CTreeComparator>& fIntDelays; - std::map, CTreeComparator>& fRealDelays; - std::map& fInputControls; - std::map& fOutputControls; - int& fNumInputs; + std::map>& fIntDelays; + std::map>& fRealDelays; + std::map& fInputControls; + std::map& fOutputControls; + int& fNumInputs; void allocateDelayLine(Tree x, Tree y) { @@ -150,10 +150,10 @@ struct SignalRenderer : public SignalVisitor { } } - SignalBuilder(std::map, CTreeComparator>& int_delays, - std::map, CTreeComparator>& real_delays, - std::map& inputs_control, - std::map& outputs_control, int& inputs) + SignalBuilder(std::map>& int_delays, + std::map>& real_delays, + std::map& inputs_control, + std::map& outputs_control, int& inputs) : fIntDelays(int_delays), fRealDelays(real_delays), fInputControls(inputs_control), @@ -245,18 +245,18 @@ struct SignalRenderer : public SignalVisitor { } } - bool fVisitGen{false}; // wether to visit gen signal for tables - std::stack fValueStack; - std::map, CTreeComparator> fIntDelays; - std::map, CTreeComparator> fRealDelays; - std::map fInputControls; - std::map fOutputControls; - int fNumInputs = 0; - int fSampleRate = -1; - int fSample = 0; - int fIOTA = 0; - FAUSTFLOAT** fInputs = nullptr; - Tree fOutputSig; + bool fVisitGen{false}; // wether to visit gen signal for tables + std::stack fValueStack; + std::map> fIntDelays; + std::map> fRealDelays; + std::map fInputControls; + std::map fOutputControls; + int fNumInputs = 0; + int fSampleRate = -1; + int fSample = 0; + int fIOTA = 0; + FAUSTFLOAT** fInputs = nullptr; + Tree fOutputSig; void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs); diff --git a/compiler/transform/treeTraversal.hh b/compiler/transform/treeTraversal.hh index f16dc50403..6bdf754759 100644 --- a/compiler/transform/treeTraversal.hh +++ b/compiler/transform/treeTraversal.hh @@ -50,7 +50,7 @@ class TreeTraversal : public Garbageable { explicit TreeTraversal(const std::string& msg = "TreeTraversal") : fMessage(msg) {} virtual ~TreeTraversal() = default; - std::map fVisited; // visiting counter + std::map fVisited; // visiting counter virtual void self(Tree t) {