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/instruction.h" | 5 #include "src/compiler/instruction.h" |
6 | 6 |
7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/generic-node-inl.h" | 8 #include "src/compiler/generic-node-inl.h" |
9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
10 | 10 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 return os << static_cast<const void*>( | 310 return os << static_cast<const void*>( |
311 constant.ToExternalReference().address()); | 311 constant.ToExternalReference().address()); |
312 case Constant::kHeapObject: | 312 case Constant::kHeapObject: |
313 return os << Brief(*constant.ToHeapObject()); | 313 return os << Brief(*constant.ToHeapObject()); |
314 } | 314 } |
315 UNREACHABLE(); | 315 UNREACHABLE(); |
316 return os; | 316 return os; |
317 } | 317 } |
318 | 318 |
319 | 319 |
| 320 static BasicBlock::RpoNumber GetRpo(BasicBlock* block) { |
| 321 if (block == NULL) return BasicBlock::RpoNumber::Invalid(); |
| 322 return block->GetRpoNumber(); |
| 323 } |
| 324 |
| 325 |
| 326 static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) { |
| 327 if (!block->IsLoopHeader()) return BasicBlock::RpoNumber::Invalid(); |
| 328 return BasicBlock::RpoNumber::FromInt(block->loop_end()); |
| 329 } |
| 330 |
| 331 |
| 332 InstructionBlock::InstructionBlock(Zone* zone, const BasicBlock* block) |
| 333 : successors_(block->SuccessorCount(), BasicBlock::RpoNumber::Invalid(), |
| 334 zone), |
| 335 predecessors_(block->PredecessorCount(), BasicBlock::RpoNumber::Invalid(), |
| 336 zone), |
| 337 phis_(zone), |
| 338 rpo_number_(block->GetRpoNumber()), |
| 339 loop_header_(GetRpo(block->loop_header())), |
| 340 loop_end_(GetLoopEndRpo(block)), |
| 341 code_start_(-1), |
| 342 code_end_(-1) { |
| 343 // Map successors and precessors |
| 344 size_t index = 0; |
| 345 for (BasicBlock::Successors::const_iterator it = block->successors_begin(); |
| 346 it != block->successors_end(); ++it, ++index) { |
| 347 successors_[index] = (*it)->GetRpoNumber(); |
| 348 } |
| 349 index = 0; |
| 350 for (BasicBlock::Predecessors::const_iterator |
| 351 it = block->predecessors_begin(); |
| 352 it != block->predecessors_end(); ++it, ++index) { |
| 353 predecessors_[index] = (*it)->GetRpoNumber(); |
| 354 } |
| 355 } |
| 356 |
| 357 |
| 358 size_t InstructionBlock::PredecessorIndexOf( |
| 359 BasicBlock::RpoNumber rpo_number) const { |
| 360 size_t j = 0; |
| 361 for (InstructionBlock::Predecessors::const_iterator i = predecessors_.begin(); |
| 362 i != predecessors_.end(); ++i, ++j) { |
| 363 if (*i == rpo_number) break; |
| 364 } |
| 365 return j; |
| 366 } |
| 367 |
| 368 |
| 369 static void InitializeInstructionBlocks(Zone* zone, const Schedule* schedule, |
| 370 InstructionBlocks* blocks) { |
| 371 DCHECK(blocks->size() == schedule->rpo_order()->size()); |
| 372 size_t rpo_number = 0; |
| 373 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); |
| 374 it != schedule->rpo_order()->end(); ++it, ++rpo_number) { |
| 375 DCHECK_EQ(NULL, (*blocks)[rpo_number]); |
| 376 DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); |
| 377 (*blocks)[rpo_number] = new (zone) InstructionBlock(zone, *it); |
| 378 } |
| 379 } |
| 380 |
| 381 |
320 InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph, | 382 InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph, |
321 Schedule* schedule) | 383 Schedule* schedule) |
322 : zone_(schedule->zone()), | 384 : zone_(schedule->zone()), // TODO(dcarney): new zone. |
323 node_count_(graph->NodeCount()), | 385 node_count_(graph->NodeCount()), |
324 node_map_(zone()->NewArray<int>(node_count_)), | 386 node_map_(zone()->NewArray<int>(node_count_)), |
325 block_data_(static_cast<int>(schedule->BasicBlockCount()), zone()), | 387 instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL, |
| 388 zone()), |
326 linkage_(linkage), | 389 linkage_(linkage), |
327 schedule_(schedule), | 390 schedule_(schedule), |
328 constants_(ConstantMap::key_compare(), | 391 constants_(ConstantMap::key_compare(), |
329 ConstantMap::allocator_type(zone())), | 392 ConstantMap::allocator_type(zone())), |
330 immediates_(zone()), | 393 immediates_(zone()), |
331 instructions_(zone()), | 394 instructions_(zone()), |
332 next_virtual_register_(0), | 395 next_virtual_register_(0), |
333 pointer_maps_(zone()), | 396 pointer_maps_(zone()), |
334 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 397 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
335 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 398 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
336 deoptimization_entries_(zone()) { | 399 deoptimization_entries_(zone()) { |
337 for (int i = 0; i < node_count_; ++i) { | 400 for (int i = 0; i < node_count_; ++i) { |
338 node_map_[i] = -1; | 401 node_map_[i] = -1; |
339 } | 402 } |
| 403 InitializeInstructionBlocks(zone(), schedule, &instruction_blocks_); |
340 } | 404 } |
341 | 405 |
342 | 406 |
343 int InstructionSequence::GetVirtualRegister(const Node* node) { | 407 int InstructionSequence::GetVirtualRegister(const Node* node) { |
344 if (node_map_[node->id()] == -1) { | 408 if (node_map_[node->id()] == -1) { |
345 node_map_[node->id()] = NextVirtualRegister(); | 409 node_map_[node->id()] = NextVirtualRegister(); |
346 } | 410 } |
347 return node_map_[node->id()]; | 411 return node_map_[node->id()]; |
348 } | 412 } |
349 | 413 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 DCHECK_LE(0, instruction_index); | 465 DCHECK_LE(0, instruction_index); |
402 Instruction* instruction = InstructionAt(instruction_index--); | 466 Instruction* instruction = InstructionAt(instruction_index--); |
403 if (instruction->IsBlockStart()) { | 467 if (instruction->IsBlockStart()) { |
404 return schedule()->rpo_order()->at( | 468 return schedule()->rpo_order()->at( |
405 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); | 469 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); |
406 } | 470 } |
407 } | 471 } |
408 } | 472 } |
409 | 473 |
410 | 474 |
| 475 const InstructionBlock* InstructionSequence::GetInstructionBlock( |
| 476 int instruction_index) const { |
| 477 // TODO(turbofan): Optimize this. |
| 478 for (;;) { |
| 479 DCHECK_LE(0, instruction_index); |
| 480 Instruction* instruction = InstructionAt(instruction_index--); |
| 481 if (instruction->IsBlockStart()) { |
| 482 return instruction_blocks_ |
| 483 [BlockStartInstruction::cast(instruction)->rpo_number().ToSize()]; |
| 484 } |
| 485 } |
| 486 } |
| 487 |
| 488 |
411 bool InstructionSequence::IsReference(int virtual_register) const { | 489 bool InstructionSequence::IsReference(int virtual_register) const { |
412 return references_.find(virtual_register) != references_.end(); | 490 return references_.find(virtual_register) != references_.end(); |
413 } | 491 } |
414 | 492 |
415 | 493 |
416 bool InstructionSequence::IsDouble(int virtual_register) const { | 494 bool InstructionSequence::IsDouble(int virtual_register) const { |
417 return doubles_.find(virtual_register) != doubles_.end(); | 495 return doubles_.find(virtual_register) != doubles_.end(); |
418 } | 496 } |
419 | 497 |
420 | 498 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 os << " B" << (*iter)->id(); | 663 os << " B" << (*iter)->id(); |
586 } | 664 } |
587 os << "\n"; | 665 os << "\n"; |
588 } | 666 } |
589 return os; | 667 return os; |
590 } | 668 } |
591 | 669 |
592 } // namespace compiler | 670 } // namespace compiler |
593 } // namespace internal | 671 } // namespace internal |
594 } // namespace v8 | 672 } // namespace v8 |
OLD | NEW |