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_(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 block_starts_.reserve(instruction_blocks_->size()); |
433 | |
434 Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { | |
435 return GetBlockStart(rpo)->label(); | |
436 } | 434 } |
437 | 435 |
438 | 436 |
439 BlockStartInstruction* InstructionSequence::GetBlockStart( | 437 BlockStartInstruction* InstructionSequence::GetBlockStart( |
440 BasicBlock::RpoNumber rpo) { | 438 BasicBlock::RpoNumber rpo) { |
441 InstructionBlock* block = InstructionBlockAt(rpo); | 439 InstructionBlock* block = InstructionBlockAt(rpo); |
442 BlockStartInstruction* block_start = | 440 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 } | 441 } |
447 | 442 |
448 | 443 |
449 void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { | 444 void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { |
| 445 DCHECK(block_starts_.size() == rpo.ToSize()); |
450 InstructionBlock* block = InstructionBlockAt(rpo); | 446 InstructionBlock* block = InstructionBlockAt(rpo); |
451 block->set_code_start(static_cast<int>(instructions_.size())); | 447 int code_start = static_cast<int>(instructions_.size()); |
452 BlockStartInstruction* block_start = | 448 block->set_code_start(code_start); |
453 BlockStartInstruction::New(zone(), block->id(), rpo); | 449 block_starts_.push_back(code_start); |
| 450 BlockStartInstruction* block_start = BlockStartInstruction::New(zone()); |
454 AddInstruction(block_start); | 451 AddInstruction(block_start); |
455 } | 452 } |
456 | 453 |
457 | 454 |
458 void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { | 455 void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { |
459 int end = static_cast<int>(instructions_.size()); | 456 int end = static_cast<int>(instructions_.size()); |
460 InstructionBlock* block = InstructionBlockAt(rpo); | 457 InstructionBlock* block = InstructionBlockAt(rpo); |
461 DCHECK(block->code_start() >= 0 && block->code_start() < end); | 458 DCHECK(block->code_start() >= 0 && block->code_start() < end); |
462 block->set_code_end(end); | 459 block->set_code_end(end); |
463 } | 460 } |
(...skipping 12 matching lines...) Expand all Loading... |
476 pointer_map->set_instruction_position(index); | 473 pointer_map->set_instruction_position(index); |
477 instr->set_pointer_map(pointer_map); | 474 instr->set_pointer_map(pointer_map); |
478 pointer_maps_.push_back(pointer_map); | 475 pointer_maps_.push_back(pointer_map); |
479 } | 476 } |
480 return index; | 477 return index; |
481 } | 478 } |
482 | 479 |
483 | 480 |
484 const InstructionBlock* InstructionSequence::GetInstructionBlock( | 481 const InstructionBlock* InstructionSequence::GetInstructionBlock( |
485 int instruction_index) const { | 482 int instruction_index) const { |
486 // TODO(turbofan): Optimize this. | 483 DCHECK(instruction_blocks_->size() == block_starts_.size()); |
487 for (;;) { | 484 auto begin = block_starts_.begin(); |
488 DCHECK_LE(0, instruction_index); | 485 auto end = std::lower_bound(begin, block_starts_.end(), instruction_index, |
489 Instruction* instruction = InstructionAt(instruction_index--); | 486 std::less_equal<int>()); |
490 if (instruction->IsBlockStart()) { | 487 size_t index = std::distance(begin, end) - 1; |
491 return instruction_blocks_->at( | 488 auto block = instruction_blocks_->at(index); |
492 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); | 489 DCHECK(block->code_start() <= instruction_index && |
493 } | 490 instruction_index < block->code_end()); |
494 } | 491 return block; |
495 } | 492 } |
496 | 493 |
497 | 494 |
498 bool InstructionSequence::IsReference(int virtual_register) const { | 495 bool InstructionSequence::IsReference(int virtual_register) const { |
499 return references_.find(virtual_register) != references_.end(); | 496 return references_.find(virtual_register) != references_.end(); |
500 } | 497 } |
501 | 498 |
502 | 499 |
503 bool InstructionSequence::IsDouble(int virtual_register) const { | 500 bool InstructionSequence::IsDouble(int virtual_register) const { |
504 return doubles_.find(virtual_register) != doubles_.end(); | 501 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(); | 667 os << " B" << succ_block->id(); |
671 } | 668 } |
672 os << "\n"; | 669 os << "\n"; |
673 } | 670 } |
674 return os; | 671 return os; |
675 } | 672 } |
676 | 673 |
677 } // namespace compiler | 674 } // namespace compiler |
678 } // namespace internal | 675 } // namespace internal |
679 } // namespace v8 | 676 } // namespace v8 |
OLD | NEW |