| OLD | NEW |
| 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/generic-node-inl.h" | 6 #include "src/compiler/generic-node-inl.h" |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/instruction.h" | 8 #include "src/compiler/instruction.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 (*blocks)[rpo_number] = InstructionBlockFor(zone, *it); | 413 (*blocks)[rpo_number] = InstructionBlockFor(zone, *it); |
| 414 } | 414 } |
| 415 return blocks; | 415 return blocks; |
| 416 } | 416 } |
| 417 | 417 |
| 418 | 418 |
| 419 InstructionSequence::InstructionSequence(Zone* instruction_zone, | 419 InstructionSequence::InstructionSequence(Zone* instruction_zone, |
| 420 InstructionBlocks* instruction_blocks) | 420 InstructionBlocks* instruction_blocks) |
| 421 : zone_(instruction_zone), | 421 : zone_(instruction_zone), |
| 422 instruction_blocks_(instruction_blocks), | 422 instruction_blocks_(instruction_blocks), |
| 423 block_starts_(static_cast<int>(instruction_blocks_->size()), -1, zone()), |
| 423 constants_(ConstantMap::key_compare(), | 424 constants_(ConstantMap::key_compare(), |
| 424 ConstantMap::allocator_type(zone())), | 425 ConstantMap::allocator_type(zone())), |
| 425 immediates_(zone()), | 426 immediates_(zone()), |
| 426 instructions_(zone()), | 427 instructions_(zone()), |
| 427 next_virtual_register_(0), | 428 next_virtual_register_(0), |
| 428 pointer_maps_(zone()), | 429 pointer_maps_(zone()), |
| 429 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 430 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
| 430 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 431 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
| 431 deoptimization_entries_(zone()) {} | 432 deoptimization_entries_(zone()) {} |
| 432 | 433 |
| 433 | 434 |
| 434 Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { | |
| 435 return GetBlockStart(rpo)->label(); | |
| 436 } | |
| 437 | |
| 438 | |
| 439 BlockStartInstruction* InstructionSequence::GetBlockStart( | 435 BlockStartInstruction* InstructionSequence::GetBlockStart( |
| 440 BasicBlock::RpoNumber rpo) { | 436 BasicBlock::RpoNumber rpo) { |
| 441 InstructionBlock* block = InstructionBlockAt(rpo); | 437 InstructionBlock* block = InstructionBlockAt(rpo); |
| 442 BlockStartInstruction* block_start = | 438 return BlockStartInstruction::cast(InstructionAt(block->code_start())); |
| 443 BlockStartInstruction::cast(InstructionAt(block->code_start())); | |
| 444 DCHECK_EQ(rpo.ToInt(), block_start->rpo_number().ToInt()); | |
| 445 return block_start; | |
| 446 } | 439 } |
| 447 | 440 |
| 448 | 441 |
| 449 void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { | 442 void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { |
| 450 InstructionBlock* block = InstructionBlockAt(rpo); | 443 InstructionBlock* block = InstructionBlockAt(rpo); |
| 451 block->set_code_start(static_cast<int>(instructions_.size())); | 444 int code_start = static_cast<int>(instructions_.size()); |
| 452 BlockStartInstruction* block_start = | 445 block->set_code_start(code_start); |
| 453 BlockStartInstruction::New(zone(), block->id(), rpo); | 446 block_starts_[rpo.ToSize()] = code_start; |
| 447 BlockStartInstruction* block_start = BlockStartInstruction::New(zone()); |
| 454 AddInstruction(block_start); | 448 AddInstruction(block_start); |
| 455 } | 449 } |
| 456 | 450 |
| 457 | 451 |
| 458 void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { | 452 void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { |
| 459 int end = static_cast<int>(instructions_.size()); | 453 int end = static_cast<int>(instructions_.size()); |
| 460 InstructionBlock* block = InstructionBlockAt(rpo); | 454 InstructionBlock* block = InstructionBlockAt(rpo); |
| 461 DCHECK(block->code_start() >= 0 && block->code_start() < end); | 455 DCHECK(block->code_start() >= 0 && block->code_start() < end); |
| 462 block->set_code_end(end); | 456 block->set_code_end(end); |
| 463 } | 457 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 476 pointer_map->set_instruction_position(index); | 470 pointer_map->set_instruction_position(index); |
| 477 instr->set_pointer_map(pointer_map); | 471 instr->set_pointer_map(pointer_map); |
| 478 pointer_maps_.push_back(pointer_map); | 472 pointer_maps_.push_back(pointer_map); |
| 479 } | 473 } |
| 480 return index; | 474 return index; |
| 481 } | 475 } |
| 482 | 476 |
| 483 | 477 |
| 484 const InstructionBlock* InstructionSequence::GetInstructionBlock( | 478 const InstructionBlock* InstructionSequence::GetInstructionBlock( |
| 485 int instruction_index) const { | 479 int instruction_index) const { |
| 486 // TODO(turbofan): Optimize this. | 480 auto begin = block_starts_.begin(); |
| 487 for (;;) { | 481 auto end = std::lower_bound(begin, block_starts_.end(), instruction_index, |
| 488 DCHECK_LE(0, instruction_index); | 482 std::less_equal<int>()); |
| 489 Instruction* instruction = InstructionAt(instruction_index--); | 483 auto block = instruction_blocks_->at(std::distance(begin, end) - 1); |
| 490 if (instruction->IsBlockStart()) { | 484 DCHECK(block->code_start() <= instruction_index && |
| 491 return instruction_blocks_->at( | 485 instruction_index < block->code_end()); |
| 492 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); | 486 return block; |
| 493 } | |
| 494 } | |
| 495 } | 487 } |
| 496 | 488 |
| 497 | 489 |
| 498 bool InstructionSequence::IsReference(int virtual_register) const { | 490 bool InstructionSequence::IsReference(int virtual_register) const { |
| 499 return references_.find(virtual_register) != references_.end(); | 491 return references_.find(virtual_register) != references_.end(); |
| 500 } | 492 } |
| 501 | 493 |
| 502 | 494 |
| 503 bool InstructionSequence::IsDouble(int virtual_register) const { | 495 bool InstructionSequence::IsDouble(int virtual_register) const { |
| 504 return doubles_.find(virtual_register) != doubles_.end(); | 496 return doubles_.find(virtual_register) != doubles_.end(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 os << " B" << succ_block->id(); | 662 os << " B" << succ_block->id(); |
| 671 } | 663 } |
| 672 os << "\n"; | 664 os << "\n"; |
| 673 } | 665 } |
| 674 return os; | 666 return os; |
| 675 } | 667 } |
| 676 | 668 |
| 677 } // namespace compiler | 669 } // namespace compiler |
| 678 } // namespace internal | 670 } // namespace internal |
| 679 } // namespace v8 | 671 } // namespace v8 |
| OLD | NEW |