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 <memory> | 7 #include <memory> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 const std::string str_; | 108 const std::string str_; |
109 const char* const escaped_chars_; | 109 const char* const escaped_chars_; |
110 }; | 110 }; |
111 | 111 |
112 class JSONGraphNodeWriter { | 112 class JSONGraphNodeWriter { |
113 public: | 113 public: |
114 JSONGraphNodeWriter(std::ostream& os, Zone* zone, const Graph* graph, | 114 JSONGraphNodeWriter(std::ostream& os, Zone* zone, const Graph* graph, |
115 const SourcePositionTable* positions) | 115 const SourcePositionTable* positions) |
116 : os_(os), all_(zone, graph), positions_(positions), first_node_(true) {} | 116 : os_(os), |
| 117 all_(zone, graph, false), |
| 118 live_(zone, graph, true), |
| 119 positions_(positions), |
| 120 first_node_(true) {} |
117 | 121 |
118 void Print() { | 122 void Print() { |
119 for (Node* const node : all_.live) PrintNode(node); | 123 for (Node* const node : all_.reachable) PrintNode(node); |
120 os_ << "\n"; | 124 os_ << "\n"; |
121 } | 125 } |
122 | 126 |
123 void PrintNode(Node* node) { | 127 void PrintNode(Node* node) { |
124 if (first_node_) { | 128 if (first_node_) { |
125 first_node_ = false; | 129 first_node_ = false; |
126 } else { | 130 } else { |
127 os_ << ",\n"; | 131 os_ << ",\n"; |
128 } | 132 } |
129 std::ostringstream label, title, properties; | 133 std::ostringstream label, title, properties; |
130 node->op()->PrintTo(label, Operator::PrintVerbosity::kSilent); | 134 node->op()->PrintTo(label, Operator::PrintVerbosity::kSilent); |
131 node->op()->PrintTo(title, Operator::PrintVerbosity::kVerbose); | 135 node->op()->PrintTo(title, Operator::PrintVerbosity::kVerbose); |
132 node->op()->PrintPropsTo(properties); | 136 node->op()->PrintPropsTo(properties); |
133 os_ << "{\"id\":" << SafeId(node) << ",\"label\":\"" << Escaped(label, "\"") | 137 os_ << "{\"id\":" << SafeId(node) << ",\"label\":\"" << Escaped(label, "\"") |
134 << "\"" | 138 << "\"" |
135 << ",\"title\":\"" << Escaped(title, "\"") << "\"" | 139 << ",\"title\":\"" << Escaped(title, "\"") << "\"" |
| 140 << ",\"live\": " << (live_.IsLive(node) ? "true" : "false") |
136 << ",\"properties\":\"" << Escaped(properties, "\"") << "\""; | 141 << ",\"properties\":\"" << Escaped(properties, "\"") << "\""; |
137 IrOpcode::Value opcode = node->opcode(); | 142 IrOpcode::Value opcode = node->opcode(); |
138 if (IrOpcode::IsPhiOpcode(opcode)) { | 143 if (IrOpcode::IsPhiOpcode(opcode)) { |
139 os_ << ",\"rankInputs\":[0," << NodeProperties::FirstControlIndex(node) | 144 os_ << ",\"rankInputs\":[0," << NodeProperties::FirstControlIndex(node) |
140 << "]"; | 145 << "]"; |
141 os_ << ",\"rankWithInput\":[" << NodeProperties::FirstControlIndex(node) | 146 os_ << ",\"rankWithInput\":[" << NodeProperties::FirstControlIndex(node) |
142 << "]"; | 147 << "]"; |
143 } else if (opcode == IrOpcode::kIfTrue || opcode == IrOpcode::kIfFalse || | 148 } else if (opcode == IrOpcode::kIfTrue || opcode == IrOpcode::kIfFalse || |
144 opcode == IrOpcode::kLoop) { | 149 opcode == IrOpcode::kLoop) { |
145 os_ << ",\"rankInputs\":[" << NodeProperties::FirstControlIndex(node) | 150 os_ << ",\"rankInputs\":[" << NodeProperties::FirstControlIndex(node) |
(...skipping 20 matching lines...) Expand all Loading... |
166 std::ostringstream type_out; | 171 std::ostringstream type_out; |
167 type->PrintTo(type_out); | 172 type->PrintTo(type_out); |
168 os_ << ",\"type\":\"" << Escaped(type_out, "\"") << "\""; | 173 os_ << ",\"type\":\"" << Escaped(type_out, "\"") << "\""; |
169 } | 174 } |
170 os_ << "}"; | 175 os_ << "}"; |
171 } | 176 } |
172 | 177 |
173 private: | 178 private: |
174 std::ostream& os_; | 179 std::ostream& os_; |
175 AllNodes all_; | 180 AllNodes all_; |
| 181 AllNodes live_; |
176 const SourcePositionTable* positions_; | 182 const SourcePositionTable* positions_; |
177 bool first_node_; | 183 bool first_node_; |
178 | 184 |
179 DISALLOW_COPY_AND_ASSIGN(JSONGraphNodeWriter); | 185 DISALLOW_COPY_AND_ASSIGN(JSONGraphNodeWriter); |
180 }; | 186 }; |
181 | 187 |
182 | 188 |
183 class JSONGraphEdgeWriter { | 189 class JSONGraphEdgeWriter { |
184 public: | 190 public: |
185 JSONGraphEdgeWriter(std::ostream& os, Zone* zone, const Graph* graph) | 191 JSONGraphEdgeWriter(std::ostream& os, Zone* zone, const Graph* graph) |
186 : os_(os), all_(zone, graph), first_edge_(true) {} | 192 : os_(os), all_(zone, graph, false), first_edge_(true) {} |
187 | 193 |
188 void Print() { | 194 void Print() { |
189 for (Node* const node : all_.live) PrintEdges(node); | 195 for (Node* const node : all_.reachable) PrintEdges(node); |
190 os_ << "\n"; | 196 os_ << "\n"; |
191 } | 197 } |
192 | 198 |
193 void PrintEdges(Node* node) { | 199 void PrintEdges(Node* node) { |
194 for (int i = 0; i < node->InputCount(); i++) { | 200 for (int i = 0; i < node->InputCount(); i++) { |
195 Node* input = node->InputAt(i); | 201 Node* input = node->InputAt(i); |
196 if (input == nullptr) continue; | 202 if (input == nullptr) continue; |
197 PrintEdge(node, i, input); | 203 PrintEdge(node, i, input); |
198 } | 204 } |
199 } | 205 } |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 os << "]"; | 707 os << "]"; |
702 } | 708 } |
703 os << std::endl; | 709 os << std::endl; |
704 } | 710 } |
705 } | 711 } |
706 return os; | 712 return os; |
707 } | 713 } |
708 } // namespace compiler | 714 } // namespace compiler |
709 } // namespace internal | 715 } // namespace internal |
710 } // namespace v8 | 716 } // namespace v8 |
OLD | NEW |