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

Side by Side Diff: src/compiler/instruction.cc

Issue 951553005: [turbofan] remove dependence of InstructionBlock on BasicBlock (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « src/compiler/instruction.h ('k') | src/compiler/instruction-selector.h » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/common-operator.h" 5 #include "src/compiler/common-operator.h"
6 #include "src/compiler/graph.h" 6 #include "src/compiler/graph.h"
7 #include "src/compiler/instruction.h" 7 #include "src/compiler/instruction.h"
8 #include "src/compiler/schedule.h"
8 9
9 namespace v8 { 10 namespace v8 {
10 namespace internal { 11 namespace internal {
11 namespace compiler { 12 namespace compiler {
12 13
13 std::ostream& operator<<(std::ostream& os, 14 std::ostream& operator<<(std::ostream& os,
14 const PrintableInstructionOperand& printable) { 15 const PrintableInstructionOperand& printable) {
15 const InstructionOperand& op = *printable.op_; 16 const InstructionOperand& op = *printable.op_;
16 const RegisterConfiguration* conf = printable.register_configuration_; 17 const RegisterConfiguration* conf = printable.register_configuration_;
17 switch (op.kind()) { 18 switch (op.kind()) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 369
369 370
370 void PhiInstruction::SetInput(size_t offset, int virtual_register) { 371 void PhiInstruction::SetInput(size_t offset, int virtual_register) {
371 DCHECK(inputs_[offset].IsInvalid()); 372 DCHECK(inputs_[offset].IsInvalid());
372 auto input = UnallocatedOperand(UnallocatedOperand::ANY, virtual_register); 373 auto input = UnallocatedOperand(UnallocatedOperand::ANY, virtual_register);
373 inputs_[offset] = input; 374 inputs_[offset] = input;
374 operands_[offset] = virtual_register; 375 operands_[offset] = virtual_register;
375 } 376 }
376 377
377 378
378 InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id, 379 InstructionBlock::InstructionBlock(Zone* zone, RpoNumber rpo_number,
379 BasicBlock::RpoNumber rpo_number, 380 RpoNumber loop_header, RpoNumber loop_end,
380 BasicBlock::RpoNumber loop_header,
381 BasicBlock::RpoNumber loop_end,
382 bool deferred) 381 bool deferred)
383 : successors_(zone), 382 : successors_(zone),
384 predecessors_(zone), 383 predecessors_(zone),
385 phis_(zone), 384 phis_(zone),
386 id_(id),
387 ao_number_(rpo_number), 385 ao_number_(rpo_number),
388 rpo_number_(rpo_number), 386 rpo_number_(rpo_number),
389 loop_header_(loop_header), 387 loop_header_(loop_header),
390 loop_end_(loop_end), 388 loop_end_(loop_end),
391 code_start_(-1), 389 code_start_(-1),
392 code_end_(-1), 390 code_end_(-1),
393 deferred_(deferred) {} 391 deferred_(deferred) {}
394 392
395 393
396 size_t InstructionBlock::PredecessorIndexOf( 394 size_t InstructionBlock::PredecessorIndexOf(RpoNumber rpo_number) const {
397 BasicBlock::RpoNumber rpo_number) const {
398 size_t j = 0; 395 size_t j = 0;
399 for (InstructionBlock::Predecessors::const_iterator i = predecessors_.begin(); 396 for (InstructionBlock::Predecessors::const_iterator i = predecessors_.begin();
400 i != predecessors_.end(); ++i, ++j) { 397 i != predecessors_.end(); ++i, ++j) {
401 if (*i == rpo_number) break; 398 if (*i == rpo_number) break;
402 } 399 }
403 return j; 400 return j;
404 } 401 }
405 402
406 403
407 static BasicBlock::RpoNumber GetRpo(BasicBlock* block) { 404 static RpoNumber GetRpo(const BasicBlock* block) {
408 if (block == NULL) return BasicBlock::RpoNumber::Invalid(); 405 if (block == NULL) return RpoNumber::Invalid();
409 return block->GetRpoNumber(); 406 return RpoNumber::FromInt(block->rpo_number());
410 } 407 }
411 408
412 409
413 static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) { 410 static RpoNumber GetLoopEndRpo(const BasicBlock* block) {
414 if (!block->IsLoopHeader()) return BasicBlock::RpoNumber::Invalid(); 411 if (!block->IsLoopHeader()) return RpoNumber::Invalid();
415 return block->loop_end()->GetRpoNumber(); 412 return RpoNumber::FromInt(block->loop_end()->rpo_number());
416 } 413 }
417 414
418 415
419 static InstructionBlock* InstructionBlockFor(Zone* zone, 416 static InstructionBlock* InstructionBlockFor(Zone* zone,
420 const BasicBlock* block) { 417 const BasicBlock* block) {
421 InstructionBlock* instr_block = new (zone) InstructionBlock( 418 InstructionBlock* instr_block = new (zone)
422 zone, block->id(), block->GetRpoNumber(), GetRpo(block->loop_header()), 419 InstructionBlock(zone, GetRpo(block), GetRpo(block->loop_header()),
423 GetLoopEndRpo(block), block->deferred()); 420 GetLoopEndRpo(block), block->deferred());
424 // Map successors and precessors 421 // Map successors and precessors
425 instr_block->successors().reserve(block->SuccessorCount()); 422 instr_block->successors().reserve(block->SuccessorCount());
426 for (BasicBlock* successor : block->successors()) { 423 for (BasicBlock* successor : block->successors()) {
427 instr_block->successors().push_back(successor->GetRpoNumber()); 424 instr_block->successors().push_back(GetRpo(successor));
428 } 425 }
429 instr_block->predecessors().reserve(block->PredecessorCount()); 426 instr_block->predecessors().reserve(block->PredecessorCount());
430 for (BasicBlock* predecessor : block->predecessors()) { 427 for (BasicBlock* predecessor : block->predecessors()) {
431 instr_block->predecessors().push_back(predecessor->GetRpoNumber()); 428 instr_block->predecessors().push_back(GetRpo(predecessor));
432 } 429 }
433 return instr_block; 430 return instr_block;
434 } 431 }
435 432
436 433
437 InstructionBlocks* InstructionSequence::InstructionBlocksFor( 434 InstructionBlocks* InstructionSequence::InstructionBlocksFor(
438 Zone* zone, const Schedule* schedule) { 435 Zone* zone, const Schedule* schedule) {
439 InstructionBlocks* blocks = zone->NewArray<InstructionBlocks>(1); 436 InstructionBlocks* blocks = zone->NewArray<InstructionBlocks>(1);
440 new (blocks) InstructionBlocks( 437 new (blocks) InstructionBlocks(
441 static_cast<int>(schedule->rpo_order()->size()), NULL, zone); 438 static_cast<int>(schedule->rpo_order()->size()), NULL, zone);
442 size_t rpo_number = 0; 439 size_t rpo_number = 0;
443 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); 440 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin();
444 it != schedule->rpo_order()->end(); ++it, ++rpo_number) { 441 it != schedule->rpo_order()->end(); ++it, ++rpo_number) {
445 DCHECK(!(*blocks)[rpo_number]); 442 DCHECK(!(*blocks)[rpo_number]);
446 DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); 443 DCHECK(GetRpo(*it).ToSize() == rpo_number);
447 (*blocks)[rpo_number] = InstructionBlockFor(zone, *it); 444 (*blocks)[rpo_number] = InstructionBlockFor(zone, *it);
448 } 445 }
449 ComputeAssemblyOrder(blocks); 446 ComputeAssemblyOrder(blocks);
450 return blocks; 447 return blocks;
451 } 448 }
452 449
453 450
454 void InstructionSequence::ComputeAssemblyOrder(InstructionBlocks* blocks) { 451 void InstructionSequence::ComputeAssemblyOrder(InstructionBlocks* blocks) {
455 int ao = 0; 452 int ao = 0;
456 for (auto const block : *blocks) { 453 for (auto const block : *blocks) {
457 if (!block->IsDeferred()) { 454 if (!block->IsDeferred()) {
458 block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++)); 455 block->set_ao_number(RpoNumber::FromInt(ao++));
459 } 456 }
460 } 457 }
461 for (auto const block : *blocks) { 458 for (auto const block : *blocks) {
462 if (block->IsDeferred()) { 459 if (block->IsDeferred()) {
463 block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++)); 460 block->set_ao_number(RpoNumber::FromInt(ao++));
464 } 461 }
465 } 462 }
466 } 463 }
467 464
468 465
469 InstructionSequence::InstructionSequence(Isolate* isolate, 466 InstructionSequence::InstructionSequence(Isolate* isolate,
470 Zone* instruction_zone, 467 Zone* instruction_zone,
471 InstructionBlocks* instruction_blocks) 468 InstructionBlocks* instruction_blocks)
472 : isolate_(isolate), 469 : isolate_(isolate),
473 zone_(instruction_zone), 470 zone_(instruction_zone),
(...skipping 12 matching lines...) Expand all
486 } 483 }
487 484
488 485
489 int InstructionSequence::NextVirtualRegister() { 486 int InstructionSequence::NextVirtualRegister() {
490 int virtual_register = next_virtual_register_++; 487 int virtual_register = next_virtual_register_++;
491 CHECK_NE(virtual_register, InstructionOperand::kInvalidVirtualRegister); 488 CHECK_NE(virtual_register, InstructionOperand::kInvalidVirtualRegister);
492 return virtual_register; 489 return virtual_register;
493 } 490 }
494 491
495 492
496 GapInstruction* InstructionSequence::GetBlockStart( 493 GapInstruction* InstructionSequence::GetBlockStart(RpoNumber rpo) const {
497 BasicBlock::RpoNumber rpo) const {
498 const InstructionBlock* block = InstructionBlockAt(rpo); 494 const InstructionBlock* block = InstructionBlockAt(rpo);
499 return GapInstruction::cast(InstructionAt(block->code_start())); 495 return GapInstruction::cast(InstructionAt(block->code_start()));
500 } 496 }
501 497
502 498
503 void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { 499 void InstructionSequence::StartBlock(RpoNumber rpo) {
504 DCHECK(block_starts_.size() == rpo.ToSize()); 500 DCHECK(block_starts_.size() == rpo.ToSize());
505 InstructionBlock* block = InstructionBlockAt(rpo); 501 InstructionBlock* block = InstructionBlockAt(rpo);
506 int code_start = static_cast<int>(instructions_.size()); 502 int code_start = static_cast<int>(instructions_.size());
507 block->set_code_start(code_start); 503 block->set_code_start(code_start);
508 block_starts_.push_back(code_start); 504 block_starts_.push_back(code_start);
509 } 505 }
510 506
511 507
512 void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { 508 void InstructionSequence::EndBlock(RpoNumber rpo) {
513 int end = static_cast<int>(instructions_.size()); 509 int end = static_cast<int>(instructions_.size());
514 InstructionBlock* block = InstructionBlockAt(rpo); 510 InstructionBlock* block = InstructionBlockAt(rpo);
515 if (block->code_start() == end) { // Empty block. Insert a nop. 511 if (block->code_start() == end) { // Empty block. Insert a nop.
516 AddInstruction(Instruction::New(zone(), kArchNop)); 512 AddInstruction(Instruction::New(zone(), kArchNop));
517 end = static_cast<int>(instructions_.size()); 513 end = static_cast<int>(instructions_.size());
518 } 514 }
519 DCHECK(block->code_start() >= 0 && block->code_start() < end); 515 DCHECK(block->code_start() >= 0 && block->code_start() < end);
520 block->set_code_end(end); 516 block->set_code_end(end);
521 } 517 }
522 518
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 return types_[index]; 657 return types_[index];
662 } 658 }
663 659
664 660
665 void FrameStateDescriptor::SetType(size_t index, MachineType type) { 661 void FrameStateDescriptor::SetType(size_t index, MachineType type) {
666 DCHECK(index < GetSize()); 662 DCHECK(index < GetSize());
667 types_[index] = type; 663 types_[index] = type;
668 } 664 }
669 665
670 666
667 std::ostream& operator<<(std::ostream& os, const RpoNumber& rpo) {
668 return os << rpo.ToSize();
669 }
670
671
671 std::ostream& operator<<(std::ostream& os, 672 std::ostream& operator<<(std::ostream& os,
672 const PrintableInstructionSequence& printable) { 673 const PrintableInstructionSequence& printable) {
673 const InstructionSequence& code = *printable.sequence_; 674 const InstructionSequence& code = *printable.sequence_;
674 for (size_t i = 0; i < code.immediates_.size(); ++i) { 675 for (size_t i = 0; i < code.immediates_.size(); ++i) {
675 Constant constant = code.immediates_[i]; 676 Constant constant = code.immediates_[i];
676 os << "IMM#" << i << ": " << constant << "\n"; 677 os << "IMM#" << i << ": " << constant << "\n";
677 } 678 }
678 int i = 0; 679 int i = 0;
679 for (ConstantMap::const_iterator it = code.constants_.begin(); 680 for (ConstantMap::const_iterator it = code.constants_.begin();
680 it != code.constants_.end(); ++i, ++it) { 681 it != code.constants_.end(); ++i, ++it) {
681 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; 682 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n";
682 } 683 }
683 for (int i = 0; i < code.InstructionBlockCount(); i++) { 684 for (int i = 0; i < code.InstructionBlockCount(); i++) {
684 BasicBlock::RpoNumber rpo = BasicBlock::RpoNumber::FromInt(i); 685 RpoNumber rpo = RpoNumber::FromInt(i);
685 const InstructionBlock* block = code.InstructionBlockAt(rpo); 686 const InstructionBlock* block = code.InstructionBlockAt(rpo);
686 CHECK(block->rpo_number() == rpo); 687 CHECK(block->rpo_number() == rpo);
687 688
688 os << "RPO#" << block->rpo_number(); 689 os << "B" << block->rpo_number();
689 os << ": AO#" << block->ao_number(); 690 os << ": AO#" << block->ao_number();
690 os << ": B" << block->id();
691 if (block->IsDeferred()) os << " (deferred)"; 691 if (block->IsDeferred()) os << " (deferred)";
692 if (block->IsLoopHeader()) { 692 if (block->IsLoopHeader()) {
693 os << " loop blocks: [" << block->rpo_number() << ", " 693 os << " loop blocks: [" << block->rpo_number() << ", "
694 << block->loop_end() << ")"; 694 << block->loop_end() << ")";
695 } 695 }
696 os << " instructions: [" << block->code_start() << ", " 696 os << " instructions: [" << block->code_start() << ", "
697 << block->code_end() << ")\n predecessors:"; 697 << block->code_end() << ")\n predecessors:";
698 698
699 for (auto pred : block->predecessors()) { 699 for (auto pred : block->predecessors()) {
700 const InstructionBlock* pred_block = code.InstructionBlockAt(pred); 700 os << " B" << pred.ToInt();
701 os << " B" << pred_block->id();
702 } 701 }
703 os << "\n"; 702 os << "\n";
704 703
705 for (auto phi : block->phis()) { 704 for (auto phi : block->phis()) {
706 PrintableInstructionOperand printable_op = { 705 PrintableInstructionOperand printable_op = {
707 printable.register_configuration_, &phi->output()}; 706 printable.register_configuration_, &phi->output()};
708 os << " phi: " << printable_op << " ="; 707 os << " phi: " << printable_op << " =";
709 for (auto input : phi->inputs()) { 708 for (auto input : phi->inputs()) {
710 printable_op.op_ = &input; 709 printable_op.op_ = &input;
711 os << " " << printable_op; 710 os << " " << printable_op;
712 } 711 }
713 os << "\n"; 712 os << "\n";
714 } 713 }
715 714
716 ScopedVector<char> buf(32); 715 ScopedVector<char> buf(32);
717 PrintableInstruction printable_instr; 716 PrintableInstruction printable_instr;
718 printable_instr.register_configuration_ = printable.register_configuration_; 717 printable_instr.register_configuration_ = printable.register_configuration_;
719 for (int j = block->first_instruction_index(); 718 for (int j = block->first_instruction_index();
720 j <= block->last_instruction_index(); j++) { 719 j <= block->last_instruction_index(); j++) {
721 // TODO(svenpanne) Add some basic formatting to our streams. 720 // TODO(svenpanne) Add some basic formatting to our streams.
722 SNPrintF(buf, "%5d", j); 721 SNPrintF(buf, "%5d", j);
723 printable_instr.instr_ = code.InstructionAt(j); 722 printable_instr.instr_ = code.InstructionAt(j);
724 os << " " << buf.start() << ": " << printable_instr << "\n"; 723 os << " " << buf.start() << ": " << printable_instr << "\n";
725 } 724 }
726 725
727 for (auto succ : block->successors()) { 726 for (auto succ : block->successors()) {
728 const InstructionBlock* succ_block = code.InstructionBlockAt(succ); 727 os << " B" << succ.ToInt();
729 os << " B" << succ_block->id();
730 } 728 }
731 os << "\n"; 729 os << "\n";
732 } 730 }
733 return os; 731 return os;
734 } 732 }
735 733
736 } // namespace compiler 734 } // namespace compiler
737 } // namespace internal 735 } // namespace internal
738 } // namespace v8 736 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/instruction.h ('k') | src/compiler/instruction-selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698