| OLD | NEW | 
|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "src/compiler/graph-visualizer.h" | 5 #include "src/compiler/graph-visualizer.h" | 
| 6 | 6 | 
| 7 #include "src/compiler/generic-algorithm.h" | 7 #include "src/compiler/generic-algorithm.h" | 
| 8 #include "src/compiler/generic-node.h" | 8 #include "src/compiler/generic-node.h" | 
| 9 #include "src/compiler/generic-node-inl.h" | 9 #include "src/compiler/generic-node-inl.h" | 
| 10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" | 
| 11 #include "src/compiler/graph-inl.h" | 11 #include "src/compiler/graph-inl.h" | 
| 12 #include "src/compiler/node.h" | 12 #include "src/compiler/node.h" | 
| 13 #include "src/compiler/node-properties.h" | 13 #include "src/compiler/node-properties.h" | 
| 14 #include "src/compiler/node-properties-inl.h" | 14 #include "src/compiler/node-properties-inl.h" | 
| 15 #include "src/compiler/opcodes.h" | 15 #include "src/compiler/opcodes.h" | 
| 16 #include "src/compiler/operator.h" | 16 #include "src/compiler/operator.h" | 
| 17 #include "src/ostreams.h" | 17 #include "src/ostreams.h" | 
| 18 | 18 | 
| 19 namespace v8 { | 19 namespace v8 { | 
| 20 namespace internal { | 20 namespace internal { | 
| 21 namespace compiler { | 21 namespace compiler { | 
| 22 | 22 | 
| 23 #define DEAD_COLOR "#999999" | 23 #define DEAD_COLOR "#999999" | 
| 24 | 24 | 
| 25 class GraphVisualizer : public NullNodeVisitor { | 25 class GraphVisualizer : public NullNodeVisitor { | 
| 26  public: | 26  public: | 
| 27   GraphVisualizer(OStream& os, const Graph* graph);  // NOLINT | 27   GraphVisualizer(OStream& os, Zone* zone, const Graph* graph);  // NOLINT | 
| 28 | 28 | 
| 29   void Print(); | 29   void Print(); | 
| 30 | 30 | 
| 31   GenericGraphVisit::Control Pre(Node* node); | 31   GenericGraphVisit::Control Pre(Node* node); | 
| 32   GenericGraphVisit::Control PreEdge(Node* from, int index, Node* to); | 32   GenericGraphVisit::Control PreEdge(Node* from, int index, Node* to); | 
| 33 | 33 | 
| 34  private: | 34  private: | 
| 35   void AnnotateNode(Node* node); | 35   void AnnotateNode(Node* node); | 
| 36   void PrintEdge(Node* from, int index, Node* to); | 36   void PrintEdge(Node* from, int index, Node* to); | 
| 37 | 37 | 
|  | 38   Zone* zone_; | 
| 38   NodeSet all_nodes_; | 39   NodeSet all_nodes_; | 
| 39   NodeSet white_nodes_; | 40   NodeSet white_nodes_; | 
| 40   bool use_to_def_; | 41   bool use_to_def_; | 
| 41   OStream& os_; | 42   OStream& os_; | 
| 42   const Graph* const graph_; | 43   const Graph* const graph_; | 
| 43 | 44 | 
| 44   DISALLOW_COPY_AND_ASSIGN(GraphVisualizer); | 45   DISALLOW_COPY_AND_ASSIGN(GraphVisualizer); | 
| 45 }; | 46 }; | 
| 46 | 47 | 
| 47 | 48 | 
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 218 | 219 | 
| 219   // Make sure all nodes have been output before writing out the edges. | 220   // Make sure all nodes have been output before writing out the edges. | 
| 220   use_to_def_ = true; | 221   use_to_def_ = true; | 
| 221   // TODO(svenpanne) Remove the need for the const_casts. | 222   // TODO(svenpanne) Remove the need for the const_casts. | 
| 222   const_cast<Graph*>(graph_)->VisitNodeInputsFromEnd(this); | 223   const_cast<Graph*>(graph_)->VisitNodeInputsFromEnd(this); | 
| 223   white_nodes_.insert(const_cast<Graph*>(graph_)->start()); | 224   white_nodes_.insert(const_cast<Graph*>(graph_)->start()); | 
| 224 | 225 | 
| 225   // Visit all uses of white nodes. | 226   // Visit all uses of white nodes. | 
| 226   use_to_def_ = false; | 227   use_to_def_ = false; | 
| 227   GenericGraphVisit::Visit<GraphVisualizer, NodeUseIterationTraits<Node> >( | 228   GenericGraphVisit::Visit<GraphVisualizer, NodeUseIterationTraits<Node> >( | 
| 228       const_cast<Graph*>(graph_), white_nodes_.begin(), white_nodes_.end(), | 229       const_cast<Graph*>(graph_), zone_, white_nodes_.begin(), | 
| 229       this); | 230       white_nodes_.end(), this); | 
| 230 | 231 | 
| 231   os_ << "  DEAD_INPUT [\n" | 232   os_ << "  DEAD_INPUT [\n" | 
| 232       << "    style=\"filled\" \n" | 233       << "    style=\"filled\" \n" | 
| 233       << "    fillcolor=\"" DEAD_COLOR "\"\n" | 234       << "    fillcolor=\"" DEAD_COLOR "\"\n" | 
| 234       << "  ]\n" | 235       << "  ]\n" | 
| 235       << "\n"; | 236       << "\n"; | 
| 236 | 237 | 
| 237   // With all the nodes written, add the edges. | 238   // With all the nodes written, add the edges. | 
| 238   for (NodeSetIter i = all_nodes_.begin(); i != all_nodes_.end(); ++i) { | 239   for (NodeSetIter i = all_nodes_.begin(); i != all_nodes_.end(); ++i) { | 
| 239     Node::Inputs inputs = (*i)->inputs(); | 240     Node::Inputs inputs = (*i)->inputs(); | 
| 240     for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); | 241     for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); | 
| 241          ++iter) { | 242          ++iter) { | 
| 242       PrintEdge(iter.edge().from(), iter.edge().index(), iter.edge().to()); | 243       PrintEdge(iter.edge().from(), iter.edge().index(), iter.edge().to()); | 
| 243     } | 244     } | 
| 244   } | 245   } | 
| 245   os_ << "}\n"; | 246   os_ << "}\n"; | 
| 246 } | 247 } | 
| 247 | 248 | 
| 248 | 249 | 
| 249 GraphVisualizer::GraphVisualizer(OStream& os, const Graph* graph)  // NOLINT | 250 GraphVisualizer::GraphVisualizer(OStream& os, Zone* zone, | 
| 250     : all_nodes_(NodeSet::key_compare(), | 251                                  const Graph* graph)  // NOLINT | 
| 251                  NodeSet::allocator_type(graph->zone())), | 252     : zone_(zone), | 
| 252       white_nodes_(NodeSet::key_compare(), | 253       all_nodes_(NodeSet::key_compare(), NodeSet::allocator_type(zone)), | 
| 253                    NodeSet::allocator_type(graph->zone())), | 254       white_nodes_(NodeSet::key_compare(), NodeSet::allocator_type(zone)), | 
| 254       use_to_def_(true), | 255       use_to_def_(true), | 
| 255       os_(os), | 256       os_(os), | 
| 256       graph_(graph) {} | 257       graph_(graph) {} | 
| 257 | 258 | 
| 258 | 259 | 
| 259 OStream& operator<<(OStream& os, const AsDOT& ad) { | 260 OStream& operator<<(OStream& os, const AsDOT& ad) { | 
| 260   GraphVisualizer(os, &ad.graph).Print(); | 261   Zone tmp_zone(ad.graph.zone()->isolate()); | 
|  | 262   GraphVisualizer(os, &tmp_zone, &ad.graph).Print(); | 
| 261   return os; | 263   return os; | 
| 262 } | 264 } | 
| 263 } | 265 } | 
| 264 } | 266 } | 
| 265 }  // namespace v8::internal::compiler | 267 }  // namespace v8::internal::compiler | 
| OLD | NEW | 
|---|