| 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 void InstructionBlock::AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } |
| 370 |
| 371 |
| 372 static void InitializeInstructionBlocks(Zone* zone, const Schedule* schedule, |
| 373 InstructionBlocks* blocks) { |
| 374 DCHECK(blocks->size() == schedule->rpo_order()->size()); |
| 375 size_t rpo_number = 0; |
| 376 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); |
| 377 it != schedule->rpo_order()->end(); ++it, ++rpo_number) { |
| 378 DCHECK_EQ(NULL, (*blocks)[rpo_number]); |
| 379 DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); |
| 380 (*blocks)[rpo_number] = new (zone) InstructionBlock(zone, *it); |
| 381 } |
| 382 } |
| 383 |
| 384 |
| 320 InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph, | 385 InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph, |
| 321 Schedule* schedule) | 386 Schedule* schedule) |
| 322 : zone_(schedule->zone()), | 387 : zone_(schedule->zone()), // TODO(dcarney): new zone. |
| 323 node_count_(graph->NodeCount()), | 388 node_count_(graph->NodeCount()), |
| 324 node_map_(zone()->NewArray<int>(node_count_)), | 389 node_map_(zone()->NewArray<int>(node_count_)), |
| 325 block_data_(static_cast<int>(schedule->BasicBlockCount()), zone()), | 390 instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL, |
| 391 zone()), |
| 326 linkage_(linkage), | 392 linkage_(linkage), |
| 327 schedule_(schedule), | 393 schedule_(schedule), |
| 328 constants_(ConstantMap::key_compare(), | 394 constants_(ConstantMap::key_compare(), |
| 329 ConstantMap::allocator_type(zone())), | 395 ConstantMap::allocator_type(zone())), |
| 330 immediates_(zone()), | 396 immediates_(zone()), |
| 331 instructions_(zone()), | 397 instructions_(zone()), |
| 332 next_virtual_register_(0), | 398 next_virtual_register_(0), |
| 333 pointer_maps_(zone()), | 399 pointer_maps_(zone()), |
| 334 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 400 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
| 335 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 401 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
| 336 deoptimization_entries_(zone()) { | 402 deoptimization_entries_(zone()) { |
| 337 for (int i = 0; i < node_count_; ++i) { | 403 for (int i = 0; i < node_count_; ++i) { |
| 338 node_map_[i] = -1; | 404 node_map_[i] = -1; |
| 339 } | 405 } |
| 406 InitializeInstructionBlocks(zone(), schedule, &instruction_blocks_); |
| 340 } | 407 } |
| 341 | 408 |
| 342 | 409 |
| 343 int InstructionSequence::GetVirtualRegister(const Node* node) { | 410 int InstructionSequence::GetVirtualRegister(const Node* node) { |
| 344 if (node_map_[node->id()] == -1) { | 411 if (node_map_[node->id()] == -1) { |
| 345 node_map_[node->id()] = NextVirtualRegister(); | 412 node_map_[node->id()] = NextVirtualRegister(); |
| 346 } | 413 } |
| 347 return node_map_[node->id()]; | 414 return node_map_[node->id()]; |
| 348 } | 415 } |
| 349 | 416 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 DCHECK_LE(0, instruction_index); | 468 DCHECK_LE(0, instruction_index); |
| 402 Instruction* instruction = InstructionAt(instruction_index--); | 469 Instruction* instruction = InstructionAt(instruction_index--); |
| 403 if (instruction->IsBlockStart()) { | 470 if (instruction->IsBlockStart()) { |
| 404 return schedule()->rpo_order()->at( | 471 return schedule()->rpo_order()->at( |
| 405 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); | 472 BlockStartInstruction::cast(instruction)->rpo_number().ToSize()); |
| 406 } | 473 } |
| 407 } | 474 } |
| 408 } | 475 } |
| 409 | 476 |
| 410 | 477 |
| 478 const InstructionBlock* InstructionSequence::GetInstructionBlock( |
| 479 int instruction_index) const { |
| 480 // TODO(turbofan): Optimize this. |
| 481 for (;;) { |
| 482 DCHECK_LE(0, instruction_index); |
| 483 Instruction* instruction = InstructionAt(instruction_index--); |
| 484 if (instruction->IsBlockStart()) { |
| 485 return instruction_blocks_ |
| 486 [BlockStartInstruction::cast(instruction)->rpo_number().ToSize()]; |
| 487 } |
| 488 } |
| 489 } |
| 490 |
| 491 |
| 411 bool InstructionSequence::IsReference(int virtual_register) const { | 492 bool InstructionSequence::IsReference(int virtual_register) const { |
| 412 return references_.find(virtual_register) != references_.end(); | 493 return references_.find(virtual_register) != references_.end(); |
| 413 } | 494 } |
| 414 | 495 |
| 415 | 496 |
| 416 bool InstructionSequence::IsDouble(int virtual_register) const { | 497 bool InstructionSequence::IsDouble(int virtual_register) const { |
| 417 return doubles_.find(virtual_register) != doubles_.end(); | 498 return doubles_.find(virtual_register) != doubles_.end(); |
| 418 } | 499 } |
| 419 | 500 |
| 420 | 501 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 os << " B" << (*iter)->id(); | 666 os << " B" << (*iter)->id(); |
| 586 } | 667 } |
| 587 os << "\n"; | 668 os << "\n"; |
| 588 } | 669 } |
| 589 return os; | 670 return os; |
| 590 } | 671 } |
| 591 | 672 |
| 592 } // namespace compiler | 673 } // namespace compiler |
| 593 } // namespace internal | 674 } // namespace internal |
| 594 } // namespace v8 | 675 } // namespace v8 |
| OLD | NEW |