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

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

Issue 637313002: [turbofan] Output file for C1 visualizer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix Created 6 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/graph-visualizer.h ('k') | src/compiler/instruction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler/generic-algorithm.h" 10 #include "src/compiler/generic-algorithm.h"
11 #include "src/compiler/generic-node.h" 11 #include "src/compiler/generic-node.h"
12 #include "src/compiler/generic-node-inl.h" 12 #include "src/compiler/generic-node-inl.h"
13 #include "src/compiler/graph.h" 13 #include "src/compiler/graph.h"
14 #include "src/compiler/graph-inl.h" 14 #include "src/compiler/graph-inl.h"
15 #include "src/compiler/node.h" 15 #include "src/compiler/node.h"
16 #include "src/compiler/node-properties.h" 16 #include "src/compiler/node-properties.h"
17 #include "src/compiler/node-properties-inl.h" 17 #include "src/compiler/node-properties-inl.h"
18 #include "src/compiler/opcodes.h" 18 #include "src/compiler/opcodes.h"
19 #include "src/compiler/operator.h" 19 #include "src/compiler/operator.h"
20 #include "src/compiler/register-allocator.h"
21 #include "src/compiler/schedule.h"
22 #include "src/compiler/scheduler.h"
20 #include "src/ostreams.h" 23 #include "src/ostreams.h"
21 24
22 namespace v8 { 25 namespace v8 {
23 namespace internal { 26 namespace internal {
24 namespace compiler { 27 namespace compiler {
25 28
26 #define DEAD_COLOR "#999999" 29 #define DEAD_COLOR "#999999"
27 30
28 class Escaped { 31 class Escaped {
29 public: 32 public:
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 use_to_def_(true), 385 use_to_def_(true),
383 os_(os), 386 os_(os),
384 graph_(graph) {} 387 graph_(graph) {}
385 388
386 389
387 std::ostream& operator<<(std::ostream& os, const AsDOT& ad) { 390 std::ostream& operator<<(std::ostream& os, const AsDOT& ad) {
388 Zone tmp_zone(ad.graph.zone()->isolate()); 391 Zone tmp_zone(ad.graph.zone()->isolate());
389 GraphVisualizer(os, &tmp_zone, &ad.graph).Print(); 392 GraphVisualizer(os, &tmp_zone, &ad.graph).Print();
390 return os; 393 return os;
391 } 394 }
395
396
397 class GraphC1Visualizer {
398 public:
399 GraphC1Visualizer(std::ostream& os, Zone* zone); // NOLINT
400
401 void PrintCompilation(const CompilationInfo* info);
402 void PrintSchedule(const char* phase, const Schedule* schedule,
403 const SourcePositionTable* positions,
404 const InstructionSequence* instructions);
405 void PrintAllocator(const char* phase, const RegisterAllocator* allocator);
406 Zone* zone() const { return zone_; }
407
408 private:
409 void PrintIndent();
410 void PrintStringProperty(const char* name, const char* value);
411 void PrintLongProperty(const char* name, int64_t value);
412 void PrintIntProperty(const char* name, int value);
413 void PrintBlockProperty(const char* name, BasicBlock::Id block_id);
414 void PrintNodeId(Node* n);
415 void PrintNode(Node* n);
416 void PrintInputs(Node* n);
417 void PrintInputs(InputIter* i, int count, const char* prefix);
418 void PrintType(Node* node);
419
420 void PrintLiveRange(LiveRange* range, const char* type);
421 class Tag FINAL BASE_EMBEDDED {
422 public:
423 Tag(GraphC1Visualizer* visualizer, const char* name) {
424 name_ = name;
425 visualizer_ = visualizer;
426 visualizer->PrintIndent();
427 visualizer_->os_ << "begin_" << name << "\n";
428 visualizer->indent_++;
429 }
430
431 ~Tag() {
432 visualizer_->indent_--;
433 visualizer_->PrintIndent();
434 visualizer_->os_ << "end_" << name_ << "\n";
435 DCHECK(visualizer_->indent_ >= 0);
436 }
437
438 private:
439 GraphC1Visualizer* visualizer_;
440 const char* name_;
441 };
442
443 std::ostream& os_;
444 int indent_;
445 Zone* zone_;
446
447 DISALLOW_COPY_AND_ASSIGN(GraphC1Visualizer);
448 };
449
450
451 void GraphC1Visualizer::PrintIndent() {
452 for (int i = 0; i < indent_; i++) {
453 os_ << " ";
454 }
455 }
456
457
458 GraphC1Visualizer::GraphC1Visualizer(std::ostream& os, Zone* zone)
459 : os_(os), indent_(0), zone_(zone) {}
460
461
462 void GraphC1Visualizer::PrintStringProperty(const char* name,
463 const char* value) {
464 PrintIndent();
465 os_ << name << " \"" << value << "\"\n";
466 }
467
468
469 void GraphC1Visualizer::PrintLongProperty(const char* name, int64_t value) {
470 PrintIndent();
471 os_ << name << " " << static_cast<int>(value / 1000) << "\n";
472 }
473
474
475 void GraphC1Visualizer::PrintBlockProperty(const char* name,
476 BasicBlock::Id block_id) {
477 PrintIndent();
478 os_ << name << " \"B" << block_id << "\"\n";
479 }
480
481
482 void GraphC1Visualizer::PrintIntProperty(const char* name, int value) {
483 PrintIndent();
484 os_ << name << " " << value << "\n";
485 }
486
487
488 void GraphC1Visualizer::PrintCompilation(const CompilationInfo* info) {
489 Tag tag(this, "compilation");
490 if (info->IsOptimizing()) {
491 Handle<String> name = info->function()->debug_name();
492 PrintStringProperty("name", name->ToCString().get());
493 PrintIndent();
494 os_ << "method \"" << name->ToCString().get() << ":"
495 << info->optimization_id() << "\"\n";
496 } else {
497 CodeStub::Major major_key = info->code_stub()->MajorKey();
498 PrintStringProperty("name", CodeStub::MajorName(major_key, false));
499 PrintStringProperty("method", "stub");
500 }
501 PrintLongProperty("date",
502 static_cast<int64_t>(base::OS::TimeCurrentMillis()));
503 }
504
505
506 void GraphC1Visualizer::PrintNodeId(Node* n) { os_ << "n" << n->id(); }
507
508
509 void GraphC1Visualizer::PrintNode(Node* n) {
510 PrintNodeId(n);
511 os_ << " " << *n->op() << " ";
512 PrintInputs(n);
513 }
514
515
516 void GraphC1Visualizer::PrintInputs(InputIter* i, int count,
517 const char* prefix) {
518 if (count > 0) {
519 os_ << prefix;
520 }
521 while (count > 0) {
522 os_ << " ";
523 PrintNodeId(**i);
524 ++(*i);
525 count--;
526 }
527 }
528
529
530 void GraphC1Visualizer::PrintInputs(Node* node) {
531 InputIter i = node->inputs().begin();
532 PrintInputs(&i, OperatorProperties::GetValueInputCount(node->op()), " ");
533 PrintInputs(&i, OperatorProperties::GetContextInputCount(node->op()),
534 " Ctx:");
535 PrintInputs(&i, OperatorProperties::GetFrameStateInputCount(node->op()),
536 " FS:");
537 PrintInputs(&i, OperatorProperties::GetEffectInputCount(node->op()), " Eff:");
538 PrintInputs(&i, OperatorProperties::GetControlInputCount(node->op()),
539 " Ctrl:");
540 }
541
542
543 void GraphC1Visualizer::PrintType(Node* node) {
544 Bounds bounds = NodeProperties::GetBounds(node);
545 os_ << " type:";
546 bounds.upper->PrintTo(os_);
547 os_ << "..";
548 bounds.lower->PrintTo(os_);
549 }
550
551
552 void GraphC1Visualizer::PrintSchedule(const char* phase,
553 const Schedule* schedule,
554 const SourcePositionTable* positions,
555 const InstructionSequence* instructions) {
556 Tag tag(this, "cfg");
557 PrintStringProperty("name", phase);
558 const BasicBlockVector* rpo = schedule->rpo_order();
559 for (size_t i = 0; i < rpo->size(); i++) {
560 BasicBlock* current = (*rpo)[i];
561 Tag block_tag(this, "block");
562 PrintBlockProperty("name", current->id());
563 PrintIntProperty("from_bci", -1);
564 PrintIntProperty("to_bci", -1);
565
566 PrintIndent();
567 os_ << "predecessors";
568 for (BasicBlock::Predecessors::iterator j = current->predecessors_begin();
569 j != current->predecessors_end(); ++j) {
570 os_ << " \"B" << (*j)->id() << "\"";
571 }
572 os_ << "\n";
573
574 PrintIndent();
575 os_ << "successors";
576 for (BasicBlock::Successors::iterator j = current->successors_begin();
577 j != current->successors_end(); ++j) {
578 os_ << " \"B" << (*j)->id() << "\"";
579 }
580 os_ << "\n";
581
582 PrintIndent();
583 os_ << "xhandlers\n";
584
585 PrintIndent();
586 os_ << "flags\n";
587
588 if (current->dominator() != NULL) {
589 PrintBlockProperty("dominator", current->dominator()->id());
590 }
591
592 PrintIntProperty("loop_depth", current->loop_depth());
593
594 if (current->code_start() >= 0) {
595 int first_index = current->first_instruction_index();
596 int last_index = current->last_instruction_index();
597 PrintIntProperty("first_lir_id", LifetimePosition::FromInstructionIndex(
598 first_index).Value());
599 PrintIntProperty("last_lir_id", LifetimePosition::FromInstructionIndex(
600 last_index).Value());
601 }
602
603 {
604 Tag states_tag(this, "states");
605 Tag locals_tag(this, "locals");
606 int total = 0;
607 for (BasicBlock::const_iterator i = current->begin(); i != current->end();
608 ++i) {
609 if ((*i)->opcode() == IrOpcode::kPhi) total++;
610 }
611 PrintIntProperty("size", total);
612 PrintStringProperty("method", "None");
613 int index = 0;
614 for (BasicBlock::const_iterator i = current->begin(); i != current->end();
615 ++i) {
616 if ((*i)->opcode() != IrOpcode::kPhi) continue;
617 PrintIndent();
618 os_ << index << " ";
619 PrintNodeId(*i);
620 os_ << " [";
621 PrintInputs(*i);
622 os_ << "]\n";
623 index++;
624 }
625 }
626
627 {
628 Tag HIR_tag(this, "HIR");
629 for (BasicBlock::const_iterator i = current->begin(); i != current->end();
630 ++i) {
631 Node* node = *i;
632 if (node->opcode() == IrOpcode::kPhi) continue;
633 int uses = node->UseCount();
634 PrintIndent();
635 os_ << "0 " << uses << " ";
636 PrintNode(node);
637 if (FLAG_trace_turbo_types) {
638 os_ << " ";
639 PrintType(node);
640 }
641 if (positions != NULL) {
642 SourcePosition position = positions->GetSourcePosition(node);
643 if (!position.IsUnknown()) {
644 DCHECK(!position.IsInvalid());
645 os_ << " pos:" << position.raw();
646 }
647 }
648 os_ << " <|@\n";
649 }
650
651 BasicBlock::Control control = current->control();
652 if (control != BasicBlock::kNone) {
653 PrintIndent();
654 os_ << "0 0 ";
655 if (current->control_input() != NULL) {
656 PrintNode(current->control_input());
657 } else {
658 os_ << -1 - current->id().ToInt() << " Goto";
659 }
660 os_ << " ->";
661 for (BasicBlock::Successors::iterator j = current->successors_begin();
662 j != current->successors_end(); ++j) {
663 os_ << " B" << (*j)->id();
664 }
665 if (FLAG_trace_turbo_types && current->control_input() != NULL) {
666 os_ << " ";
667 PrintType(current->control_input());
668 }
669 os_ << " <|@\n";
670 }
671 }
672
673 if (instructions != NULL) {
674 Tag LIR_tag(this, "LIR");
675 for (int j = current->first_instruction_index();
676 j <= current->last_instruction_index(); j++) {
677 PrintIndent();
678 os_ << j << " " << *instructions->InstructionAt(j) << " <|@\n";
679 }
680 }
681 }
682 }
683
684
685 void GraphC1Visualizer::PrintAllocator(const char* phase,
686 const RegisterAllocator* allocator) {
687 Tag tag(this, "intervals");
688 PrintStringProperty("name", phase);
689
690 const Vector<LiveRange*>* fixed_d = allocator->fixed_double_live_ranges();
691 for (int i = 0; i < fixed_d->length(); ++i) {
692 PrintLiveRange(fixed_d->at(i), "fixed");
693 }
694
695 const Vector<LiveRange*>* fixed = allocator->fixed_live_ranges();
696 for (int i = 0; i < fixed->length(); ++i) {
697 PrintLiveRange(fixed->at(i), "fixed");
698 }
699
700 const ZoneList<LiveRange*>* live_ranges = allocator->live_ranges();
701 for (int i = 0; i < live_ranges->length(); ++i) {
702 PrintLiveRange(live_ranges->at(i), "object");
703 }
704 }
705
706
707 void GraphC1Visualizer::PrintLiveRange(LiveRange* range, const char* type) {
708 if (range != NULL && !range->IsEmpty()) {
709 PrintIndent();
710 os_ << range->id() << " " << type;
711 if (range->HasRegisterAssigned()) {
712 InstructionOperand* op = range->CreateAssignedOperand(zone());
713 int assigned_reg = op->index();
714 if (op->IsDoubleRegister()) {
715 os_ << " \"" << DoubleRegister::AllocationIndexToString(assigned_reg)
716 << "\"";
717 } else {
718 DCHECK(op->IsRegister());
719 os_ << " \"" << Register::AllocationIndexToString(assigned_reg) << "\"";
720 }
721 } else if (range->IsSpilled()) {
722 InstructionOperand* op = range->TopLevel()->GetSpillOperand();
723 if (op->IsDoubleStackSlot()) {
724 os_ << " \"double_stack:" << op->index() << "\"";
725 } else if (op->IsStackSlot()) {
726 os_ << " \"stack:" << op->index() << "\"";
727 } else {
728 DCHECK(op->IsConstant());
729 os_ << " \"const(nostack):" << op->index() << "\"";
730 }
731 }
732 int parent_index = -1;
733 if (range->IsChild()) {
734 parent_index = range->parent()->id();
735 } else {
736 parent_index = range->id();
737 }
738 InstructionOperand* op = range->FirstHint();
739 int hint_index = -1;
740 if (op != NULL && op->IsUnallocated()) {
741 hint_index = UnallocatedOperand::cast(op)->virtual_register();
742 }
743 os_ << " " << parent_index << " " << hint_index;
744 UseInterval* cur_interval = range->first_interval();
745 while (cur_interval != NULL && range->Covers(cur_interval->start())) {
746 os_ << " [" << cur_interval->start().Value() << ", "
747 << cur_interval->end().Value() << "[";
748 cur_interval = cur_interval->next();
749 }
750
751 UsePosition* current_pos = range->first_pos();
752 while (current_pos != NULL) {
753 if (current_pos->RegisterIsBeneficial() || FLAG_trace_all_uses) {
754 os_ << " " << current_pos->pos().Value() << " M";
755 }
756 current_pos = current_pos->next();
757 }
758
759 os_ << " \"\"\n";
760 }
761 }
762
763
764 std::ostream& operator<<(std::ostream& os, const AsC1VCompilation& ac) {
765 Zone tmp_zone(ac.info_->isolate());
766 GraphC1Visualizer(os, &tmp_zone).PrintCompilation(ac.info_);
767 return os;
768 }
769
770
771 std::ostream& operator<<(std::ostream& os, const AsC1V& ac) {
772 Zone tmp_zone(ac.schedule_->zone()->isolate());
773 GraphC1Visualizer(os, &tmp_zone)
774 .PrintSchedule(ac.phase_, ac.schedule_, ac.positions_, ac.instructions_);
775 return os;
776 }
777
778
779 std::ostream& operator<<(std::ostream& os, const AsC1VAllocator& ac) {
780 Zone tmp_zone(ac.allocator_->code()->zone()->isolate());
781 GraphC1Visualizer(os, &tmp_zone).PrintAllocator(ac.phase_, ac.allocator_);
782 return os;
783 }
392 } 784 }
393 } 785 }
394 } // namespace v8::internal::compiler 786 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/graph-visualizer.h ('k') | src/compiler/instruction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698