llvm.org GIT mirror llvm / 3d68822
Utilize topological sort in CompilationGraph::Build(). 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 Mikhail Glushenkov 12 years ago
3 changed file(s) with 44 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
233233 // For all join nodes in topological order:
234234 for (std::vector::iterator B = JTV.begin(), E = JTV.end();
235235 B != E; ++B) {
236 // TOFIX: more testing, merge some parts with PassThroughGraph.
237 sys::Path Out;
238 const Node* CurNode = *B;
239 JoinTool* JT = &dynamic_cast(*CurNode->ToolPtr.getPtr());
240 bool IsLast = false;
241
242 if (JT->JoinListEmpty())
243 continue;
244
245 if (!CurNode->HasChildren() || JT->IsLast()) {
246 if (OutputFilename.empty()) {
247 Out.set("a");
248 Out.appendSuffix(JT->OutputSuffix());
249 }
250 else
251 Out.set(OutputFilename);
252 IsLast = true;
253 }
254 else {
255 Out = TempDir;
256 Out.appendComponent("tmp");
257 Out.appendSuffix(JT->OutputSuffix());
258 Out.makeUnique(true, NULL);
259 Out.eraseFromDisk();
260 }
261
262 if (JT->GenerateAction(Out).Execute() != 0)
263 throw std::runtime_error("Tool returned error code!");
264
265 if (!IsLast) {
266 const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges,
267 CurNode->Name())->ToolName());
268 PassThroughGraph(Out, NextNode, TempDir);
269 }
236270 }
237271
238272 return 0;
275309 std::ofstream O("CompilationGraph.dot");
276310
277311 if (O.good()) {
278 llvm::WriteGraph(this, "CompilationGraph");
312 llvm::WriteGraph(this, "compilation-graph");
279313 O.close();
280314 }
281315 else {
5454 // Join tools have an input file list associated with them.
5555 class JoinTool : public Tool {
5656 public:
57 void AddToJoinList(const llvm::sys::Path& P) { JoinList.push_back(P); }
58 void ClearJoinList() { JoinList.clear(); }
57 void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
58 void ClearJoinList() { JoinList_.clear(); }
59 bool JoinListEmpty() const { return JoinList_.empty(); }
5960
6061 Action GenerateAction(const llvm::sys::Path& outFile) const
61 { return GenerateAction(JoinList, outFile); }
62 // We shouldn't shadow GenerateAction from the base class.
62 { return GenerateAction(JoinList_, outFile); }
63 // We shouldn't shadow base class's version of GenerateAction.
6364 using Tool::GenerateAction;
6465
6566 private:
66 PathVector JoinList;
67 PathVector JoinList_;
6768 };
6869
6970 }
3737 cl::opt VerboseMode("v",
3838 cl::desc("Enable verbose mode"));
3939 cl::opt WriteGraph("write-graph",
40 cl::desc("Write CompilationGraph.dot file"),
40 cl::desc("Write compilation-graph.dot file"),
4141 cl::Hidden);
4242 cl::opt ViewGraph("view-graph",
4343 cl::desc("Show compilation graph in GhostView"),
7171
7272 if (WriteGraph) {
7373 graph.writeGraph();
74 return 0;
74 if (!ViewGraph)
75 return 0;
7576 }
7677
7778 if (ViewGraph) {
7879 graph.viewGraph();
7980 return 0;
8081 }
81
8282
8383 if (InputFilenames.empty()) {
8484 std::cerr << "No input files.\n";