Index: src/compiler/instruction.cc |
diff --git a/src/compiler/instruction.cc b/src/compiler/instruction.cc |
index 218130c686c585f8de4456a18522916f9c2a660b..f106541ac34c29f00794ee70a24032c07be7a357 100644 |
--- a/src/compiler/instruction.cc |
+++ b/src/compiler/instruction.cc |
@@ -420,6 +420,7 @@ InstructionSequence::InstructionSequence(Zone* instruction_zone, |
InstructionBlocks* instruction_blocks) |
: zone_(instruction_zone), |
instruction_blocks_(instruction_blocks), |
+ block_starts_(static_cast<int>(instruction_blocks_->size()), -1, zone()), |
constants_(ConstantMap::key_compare(), |
ConstantMap::allocator_type(zone())), |
immediates_(zone()), |
@@ -431,26 +432,19 @@ InstructionSequence::InstructionSequence(Zone* instruction_zone, |
deoptimization_entries_(zone()) {} |
-Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { |
- return GetBlockStart(rpo)->label(); |
-} |
- |
- |
BlockStartInstruction* InstructionSequence::GetBlockStart( |
BasicBlock::RpoNumber rpo) { |
InstructionBlock* block = InstructionBlockAt(rpo); |
- BlockStartInstruction* block_start = |
- BlockStartInstruction::cast(InstructionAt(block->code_start())); |
- DCHECK_EQ(rpo.ToInt(), block_start->rpo_number().ToInt()); |
- return block_start; |
+ return BlockStartInstruction::cast(InstructionAt(block->code_start())); |
} |
void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { |
InstructionBlock* block = InstructionBlockAt(rpo); |
- block->set_code_start(static_cast<int>(instructions_.size())); |
- BlockStartInstruction* block_start = |
- BlockStartInstruction::New(zone(), block->id(), rpo); |
+ int code_start = static_cast<int>(instructions_.size()); |
+ block->set_code_start(code_start); |
+ block_starts_[rpo.ToSize()] = code_start; |
+ BlockStartInstruction* block_start = BlockStartInstruction::New(zone()); |
AddInstruction(block_start); |
} |
@@ -483,15 +477,13 @@ int InstructionSequence::AddInstruction(Instruction* instr) { |
const InstructionBlock* InstructionSequence::GetInstructionBlock( |
int instruction_index) const { |
- // TODO(turbofan): Optimize this. |
- for (;;) { |
- DCHECK_LE(0, instruction_index); |
- Instruction* instruction = InstructionAt(instruction_index--); |
- if (instruction->IsBlockStart()) { |
- return instruction_blocks_->at( |
- BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); |
- } |
- } |
+ auto begin = block_starts_.begin(); |
+ auto end = std::lower_bound(begin, block_starts_.end(), instruction_index, |
+ std::less_equal<int>()); |
+ auto block = instruction_blocks_->at(std::distance(begin, end) - 1); |
+ DCHECK(block->code_start() <= instruction_index && |
+ instruction_index < block->code_end()); |
+ return block; |
} |