Add inward edge counters to Nodes; Associate JoinLists with JoinTools.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50738 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h
index bddd8bd..bf46fa5 100644
--- a/tools/llvmc2/CompilationGraph.h
+++ b/tools/llvmc2/CompilationGraph.h
@@ -55,31 +55,41 @@
     typedef container_type::iterator iterator;
     typedef container_type::const_iterator const_iterator;
 
-    Node() {}
-    Node(CompilationGraph* G) : OwningGraph(G) {}
-    Node(CompilationGraph* G, Tool* T) : OwningGraph(G), ToolPtr(T) {}
+    Node() : OwningGraph(0), InEdges(0) {}
+    Node(CompilationGraph* G) : OwningGraph(G), InEdges(0) {}
+    Node(CompilationGraph* G, Tool* T) :
+      OwningGraph(G), ToolPtr(T), InEdges(0) {}
 
     bool HasChildren() const { return !OutEdges.empty(); }
     const std::string Name() const { return ToolPtr->Name(); }
 
+    // Iteration.
     iterator EdgesBegin() { return OutEdges.begin(); }
     const_iterator EdgesBegin() const { return OutEdges.begin(); }
     iterator EdgesEnd() { return OutEdges.end(); }
     const_iterator EdgesEnd() const { return OutEdges.end(); }
 
-    // Choose one of the edges based on command-line options.
+    // Choose one of the outward edges based on command-line options.
     const Edge* ChooseEdge() const;
 
-    // Takes ownership of the object.
+    // Add an outward edge. Takes ownership of the Edge object.
     void AddEdge(Edge* E)
     { OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
 
+    // Inward edge counter. Used by Build() to implement topological
+    // sort.
+    void IncrInEdges() { ++InEdges; }
+    void DecrInEdges() { --InEdges; }
+    bool HasNoInEdges() const { return InEdges == 0; }
+
     // Needed to implement NodeChildIterator/GraphTraits
     CompilationGraph* OwningGraph;
     // The corresponding Tool.
     llvm::IntrusiveRefCntPtr<Tool> ToolPtr;
     // Links to children.
     container_type OutEdges;
+    // Number of parents.
+    unsigned InEdges;
   };
 
   class NodesIterator;
@@ -105,7 +115,7 @@
     void insertNode(Tool* T);
 
     // insertEdge - Insert a new edge into the graph. Takes ownership
-    // of the object.
+    // of the Edge object.
     void insertEdge(const std::string& A, Edge* E);
 
     // Build - Build target(s) from the input file set. Command-line
@@ -143,9 +153,8 @@
     const tools_vector_type& getToolsVector(const std::string& LangName) const;
 
     // Pass the input file through the toolchain.
-    const Tool* PassThroughGraph (llvm::sys::Path& In, llvm::sys::Path Out,
-                                  const llvm::sys::Path& TempDir,
-                                  PathVector& JoinList) const;
+    const JoinTool* PassThroughGraph (llvm::sys::Path& In, llvm::sys::Path Out,
+                                      const llvm::sys::Path& TempDir) const;
 
   };