Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: src/compiler/graph-visualizer.cc

Issue 765983002: Clean up node iteration (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix comment Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 class GraphVisualizer { 223 class GraphVisualizer {
224 public: 224 public:
225 GraphVisualizer(std::ostream& os, Zone* zone, const Graph* graph) 225 GraphVisualizer(std::ostream& os, Zone* zone, const Graph* graph)
226 : all_(zone, graph), os_(os) {} 226 : all_(zone, graph), os_(os) {}
227 227
228 void Print(); 228 void Print();
229 229
230 void PrintNode(Node* node, bool gray); 230 void PrintNode(Node* node, bool gray);
231 231
232 private: 232 private:
233 void PrintEdge(Node::Edge edge); 233 void PrintEdge(Edge edge);
234 234
235 AllNodes all_; 235 AllNodes all_;
236 std::ostream& os_; 236 std::ostream& os_;
237 237
238 DISALLOW_COPY_AND_ASSIGN(GraphVisualizer); 238 DISALLOW_COPY_AND_ASSIGN(GraphVisualizer);
239 }; 239 };
240 240
241 241
242 static Node* GetControlCluster(Node* node) { 242 static Node* GetControlCluster(Node* node) {
243 if (OperatorProperties::IsBasicBlockBegin(node->op())) { 243 if (OperatorProperties::IsBasicBlockBegin(node->op())) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 if (gray) { 281 if (gray) {
282 os_ << " style=\"filled\"\n" 282 os_ << " style=\"filled\"\n"
283 << " fillcolor=\"" DEAD_COLOR "\"\n"; 283 << " fillcolor=\"" DEAD_COLOR "\"\n";
284 } 284 }
285 285
286 std::ostringstream label; 286 std::ostringstream label;
287 label << *node->op(); 287 label << *node->op();
288 os_ << " label=\"{{#" << SafeId(node) << ":" << Escaped(label); 288 os_ << " label=\"{{#" << SafeId(node) << ":" << Escaped(label);
289 289
290 InputIter i = node->inputs().begin(); 290 auto i = node->input_edges().begin();
291 for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) { 291 for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) {
292 os_ << "|<I" << i.index() << ">#" << SafeId(*i); 292 os_ << "|<I" << (*i).index() << ">#" << SafeId((*i).to());
293 } 293 }
294 for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0; 294 for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0;
295 ++i, j--) { 295 ++i, j--) {
296 os_ << "|<I" << i.index() << ">X #" << SafeId(*i); 296 os_ << "|<I" << (*i).index() << ">X #" << SafeId((*i).to());
297 } 297 }
298 for (int j = OperatorProperties::GetFrameStateInputCount(node->op()); j > 0; 298 for (int j = OperatorProperties::GetFrameStateInputCount(node->op()); j > 0;
299 ++i, j--) { 299 ++i, j--) {
300 os_ << "|<I" << i.index() << ">F #" << SafeId(*i); 300 os_ << "|<I" << (*i).index() << ">F #" << SafeId((*i).to());
301 } 301 }
302 for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) { 302 for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) {
303 os_ << "|<I" << i.index() << ">E #" << SafeId(*i); 303 os_ << "|<I" << (*i).index() << ">E #" << SafeId((*i).to());
304 } 304 }
305 305
306 if (OperatorProperties::IsBasicBlockBegin(node->op()) || 306 if (OperatorProperties::IsBasicBlockBegin(node->op()) ||
307 GetControlCluster(node) == NULL) { 307 GetControlCluster(node) == NULL) {
308 for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) { 308 for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) {
309 os_ << "|<I" << i.index() << ">C #" << SafeId(*i); 309 os_ << "|<I" << (*i).index() << ">C #" << SafeId((*i).to());
310 } 310 }
311 } 311 }
312 os_ << "}"; 312 os_ << "}";
313 313
314 if (FLAG_trace_turbo_types && NodeProperties::IsTyped(node)) { 314 if (FLAG_trace_turbo_types && NodeProperties::IsTyped(node)) {
315 Bounds bounds = NodeProperties::GetBounds(node); 315 Bounds bounds = NodeProperties::GetBounds(node);
316 std::ostringstream upper; 316 std::ostringstream upper;
317 bounds.upper->PrintTo(upper); 317 bounds.upper->PrintTo(upper);
318 std::ostringstream lower; 318 std::ostringstream lower;
319 bounds.lower->PrintTo(lower); 319 bounds.lower->PrintTo(lower);
(...skipping 13 matching lines...) Expand all
333 return control != NULL && control->opcode() != IrOpcode::kMerge && 333 return control != NULL && control->opcode() != IrOpcode::kMerge &&
334 control != to && index != 0; 334 control != to && index != 0;
335 } else if (from->opcode() == IrOpcode::kLoop) { 335 } else if (from->opcode() == IrOpcode::kLoop) {
336 return index != 0; 336 return index != 0;
337 } else { 337 } else {
338 return false; 338 return false;
339 } 339 }
340 } 340 }
341 341
342 342
343 void GraphVisualizer::PrintEdge(Node::Edge edge) { 343 void GraphVisualizer::PrintEdge(Edge edge) {
344 Node* from = edge.from(); 344 Node* from = edge.from();
345 int index = edge.index(); 345 int index = edge.index();
346 Node* to = edge.to(); 346 Node* to = edge.to();
347 347
348 if (!all_.IsLive(to)) return; // skip inputs that point to dead or NULL. 348 if (!all_.IsLive(to)) return; // skip inputs that point to dead or NULL.
349 349
350 bool unconstrained = IsLikelyBackEdge(from, index, to); 350 bool unconstrained = IsLikelyBackEdge(from, index, to);
351 os_ << " ID" << SafeId(from); 351 os_ << " ID" << SafeId(from);
352 352
353 if (OperatorProperties::IsBasicBlockBegin(from->op()) || 353 if (OperatorProperties::IsBasicBlockBegin(from->op()) ||
(...skipping 23 matching lines...) Expand all
377 << " splines=\"true\"\n" 377 << " splines=\"true\"\n"
378 << " concentrate=\"true\"\n" 378 << " concentrate=\"true\"\n"
379 << " \n"; 379 << " \n";
380 380
381 // Make sure all nodes have been output before writing out the edges. 381 // Make sure all nodes have been output before writing out the edges.
382 for (Node* const node : all_.live) PrintNode(node, false); 382 for (Node* const node : all_.live) PrintNode(node, false);
383 for (Node* const node : all_.gray) PrintNode(node, true); 383 for (Node* const node : all_.gray) PrintNode(node, true);
384 384
385 // With all the nodes written, add the edges. 385 // With all the nodes written, add the edges.
386 for (Node* const node : all_.live) { 386 for (Node* const node : all_.live) {
387 for (UseIter i = node->uses().begin(); i != node->uses().end(); ++i) { 387 for (auto edge : node->use_edges()) {
388 PrintEdge(i.edge()); 388 PrintEdge(edge);
389 } 389 }
390 } 390 }
391 os_ << "}\n"; 391 os_ << "}\n";
392 } 392 }
393 393
394 394
395 std::ostream& operator<<(std::ostream& os, const AsDOT& ad) { 395 std::ostream& operator<<(std::ostream& os, const AsDOT& ad) {
396 Zone tmp_zone(ad.graph.zone()->isolate()); 396 Zone tmp_zone(ad.graph.zone()->isolate());
397 GraphVisualizer(os, &tmp_zone, &ad.graph).Print(); 397 GraphVisualizer(os, &tmp_zone, &ad.graph).Print();
398 return os; 398 return os;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 while (count > 0) { 526 while (count > 0) {
527 os_ << " "; 527 os_ << " ";
528 PrintNodeId(**i); 528 PrintNodeId(**i);
529 ++(*i); 529 ++(*i);
530 count--; 530 count--;
531 } 531 }
532 } 532 }
533 533
534 534
535 void GraphC1Visualizer::PrintInputs(Node* node) { 535 void GraphC1Visualizer::PrintInputs(Node* node) {
536 InputIter i = node->inputs().begin(); 536 auto i = node->inputs().begin();
537 PrintInputs(&i, node->op()->ValueInputCount(), " "); 537 PrintInputs(&i, node->op()->ValueInputCount(), " ");
538 PrintInputs(&i, OperatorProperties::GetContextInputCount(node->op()), 538 PrintInputs(&i, OperatorProperties::GetContextInputCount(node->op()),
539 " Ctx:"); 539 " Ctx:");
540 PrintInputs(&i, OperatorProperties::GetFrameStateInputCount(node->op()), 540 PrintInputs(&i, OperatorProperties::GetFrameStateInputCount(node->op()),
541 " FS:"); 541 " FS:");
542 PrintInputs(&i, node->op()->EffectInputCount(), " Eff:"); 542 PrintInputs(&i, node->op()->EffectInputCount(), " Eff:");
543 PrintInputs(&i, node->op()->ControlInputCount(), " Ctrl:"); 543 PrintInputs(&i, node->op()->ControlInputCount(), " Ctrl:");
544 } 544 }
545 545
546 546
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 os << "#" << SafeId(i) << ":" << SafeMnemonic(i); 826 os << "#" << SafeId(i) << ":" << SafeMnemonic(i);
827 } 827 }
828 os << ")" << std::endl; 828 os << ")" << std::endl;
829 } 829 }
830 } 830 }
831 return os; 831 return os;
832 } 832 }
833 } 833 }
834 } 834 }
835 } // namespace v8::internal::compiler 835 } // namespace v8::internal::compiler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698