Utilize topological sort in CompilationGraph::Build().
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 6 May 2008 18:07:48 +0000 (18:07 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 6 May 2008 18:07:48 +0000 (18:07 +0000)
This makes more interesting graph topologies possible. Currently all tests pass,
but more testing is needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50744 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvmc2/CompilationGraph.cpp
tools/llvmc2/Tool.h
tools/llvmc2/llvmc.cpp

index 8f3918f9e4d89dc67012d954fc90e944b208a30a..a130ee5457436733a793ef882c4a4ef6697e2923 100644 (file)
@@ -234,6 +234,40 @@ int CompilationGraph::Build (const sys::Path& TempDir) {
   // For all join nodes in topological order:
   for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end();
        B != E; ++B) {
+    // TOFIX: more testing, merge some parts with PassThroughGraph.
+    sys::Path Out;
+    const Node* CurNode = *B;
+    JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr());
+    bool IsLast = false;
+
+    if (JT->JoinListEmpty())
+      continue;
+
+    if (!CurNode->HasChildren() || JT->IsLast()) {
+      if (OutputFilename.empty()) {
+        Out.set("a");
+        Out.appendSuffix(JT->OutputSuffix());
+      }
+      else
+        Out.set(OutputFilename);
+      IsLast = true;
+    }
+    else {
+      Out = TempDir;
+      Out.appendComponent("tmp");
+      Out.appendSuffix(JT->OutputSuffix());
+      Out.makeUnique(true, NULL);
+      Out.eraseFromDisk();
+    }
+
+    if (JT->GenerateAction(Out).Execute() != 0)
+      throw std::runtime_error("Tool returned error code!");
+
+    if (!IsLast) {
+      const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges,
+                                                 CurNode->Name())->ToolName());
+      PassThroughGraph(Out, NextNode, TempDir);
+    }
   }
 
   return 0;
@@ -276,7 +310,7 @@ void CompilationGraph::writeGraph() {
   std::ofstream O("CompilationGraph.dot");
 
   if (O.good()) {
-    llvm::WriteGraph(this, "CompilationGraph");
+    llvm::WriteGraph(this, "compilation-graph");
     O.close();
   }
   else {
index 5136468a43e67ec3add827a3b63ad5e1880a7047..b4478f9f2f8ef47ad20d00e25d46fbe7787c69ec 100644 (file)
@@ -55,16 +55,17 @@ namespace llvmcc {
   // Join tools have an input file list associated with them.
   class JoinTool : public Tool {
   public:
-    void AddToJoinList(const llvm::sys::Path& P) { JoinList.push_back(P); }
-    void ClearJoinList() { JoinList.clear(); }
+    void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
+    void ClearJoinList() { JoinList_.clear(); }
+    bool JoinListEmpty() const { return JoinList_.empty(); }
 
     Action GenerateAction(const llvm::sys::Path& outFile) const
-    { return GenerateAction(JoinList, outFile); }
-    // We shouldn't shadow GenerateAction from the base class.
+    { return GenerateAction(JoinList_, outFile); }
+    // We shouldn't shadow base class's version of GenerateAction.
     using Tool::GenerateAction;
 
   private:
-    PathVector JoinList;
+    PathVector JoinList_;
   };
 
 }
index aeb8b331b40ca6d596a333dcd5f8499d0a9248cf..87c0e41cdcab1cf5b648b095c99e0039c3920cb0 100644 (file)
@@ -38,7 +38,7 @@ cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
 cl::opt<bool> VerboseMode("v",
                           cl::desc("Enable verbose mode"));
 cl::opt<bool> WriteGraph("write-graph",
-                         cl::desc("Write CompilationGraph.dot file"),
+                         cl::desc("Write compilation-graph.dot file"),
                          cl::Hidden);
 cl::opt<bool> ViewGraph("view-graph",
                          cl::desc("Show compilation graph in GhostView"),
@@ -72,7 +72,8 @@ int main(int argc, char** argv) {
 
     if (WriteGraph) {
       graph.writeGraph();
-      return 0;
+      if (!ViewGraph)
+        return 0;
     }
 
     if (ViewGraph) {
@@ -80,7 +81,6 @@ int main(int argc, char** argv) {
       return 0;
     }
 
-
     if (InputFilenames.empty()) {
       std::cerr << "No input files.\n";
       return 1;