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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); | 374 for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); |
375 it != schedule->rpo_order()->end(); ++it, ++rpo_number) { | 375 it != schedule->rpo_order()->end(); ++it, ++rpo_number) { |
376 DCHECK_EQ(NULL, (*blocks)[rpo_number]); | 376 DCHECK_EQ(NULL, (*blocks)[rpo_number]); |
377 DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); | 377 DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); |
378 (*blocks)[rpo_number] = new (zone) InstructionBlock(zone, *it); | 378 (*blocks)[rpo_number] = new (zone) InstructionBlock(zone, *it); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 InstructionSequence::InstructionSequence(Zone* instruction_zone, | 383 InstructionSequence::InstructionSequence(Zone* instruction_zone, |
384 Linkage* linkage, const Graph* graph, | 384 const Graph* graph, |
385 const Schedule* schedule) | 385 const Schedule* schedule) |
386 : zone_(instruction_zone), | 386 : zone_(instruction_zone), |
387 node_count_(graph->NodeCount()), | 387 node_map_(graph->NodeCount(), kNodeUnmapped, zone()), |
388 node_map_(zone()->NewArray<int>(node_count_)), | |
389 instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL, | 388 instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL, |
390 zone()), | 389 zone()), |
391 linkage_(linkage), | |
392 constants_(ConstantMap::key_compare(), | 390 constants_(ConstantMap::key_compare(), |
393 ConstantMap::allocator_type(zone())), | 391 ConstantMap::allocator_type(zone())), |
394 immediates_(zone()), | 392 immediates_(zone()), |
395 instructions_(zone()), | 393 instructions_(zone()), |
396 next_virtual_register_(0), | 394 next_virtual_register_(0), |
397 pointer_maps_(zone()), | 395 pointer_maps_(zone()), |
398 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 396 doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
399 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), | 397 references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())), |
400 deoptimization_entries_(zone()) { | 398 deoptimization_entries_(zone()) { |
401 for (int i = 0; i < node_count_; ++i) { | |
402 node_map_[i] = -1; | |
403 } | |
404 InitializeInstructionBlocks(zone(), schedule, &instruction_blocks_); | 399 InitializeInstructionBlocks(zone(), schedule, &instruction_blocks_); |
405 } | 400 } |
406 | 401 |
407 | 402 |
408 int InstructionSequence::GetVirtualRegister(const Node* node) { | 403 int InstructionSequence::GetVirtualRegister(const Node* node) { |
409 if (node_map_[node->id()] == -1) { | 404 if (node_map_[node->id()] == kNodeUnmapped) { |
410 node_map_[node->id()] = NextVirtualRegister(); | 405 node_map_[node->id()] = NextVirtualRegister(); |
411 } | 406 } |
412 return node_map_[node->id()]; | 407 return node_map_[node->id()]; |
413 } | 408 } |
414 | 409 |
415 | 410 |
416 Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { | 411 Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { |
417 return GetBlockStart(rpo)->label(); | 412 return GetBlockStart(rpo)->label(); |
418 } | 413 } |
419 | 414 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) { | 592 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) { |
598 for (size_t i = 0; i < code.immediates_.size(); ++i) { | 593 for (size_t i = 0; i < code.immediates_.size(); ++i) { |
599 Constant constant = code.immediates_[i]; | 594 Constant constant = code.immediates_[i]; |
600 os << "IMM#" << i << ": " << constant << "\n"; | 595 os << "IMM#" << i << ": " << constant << "\n"; |
601 } | 596 } |
602 int i = 0; | 597 int i = 0; |
603 for (ConstantMap::const_iterator it = code.constants_.begin(); | 598 for (ConstantMap::const_iterator it = code.constants_.begin(); |
604 it != code.constants_.end(); ++i, ++it) { | 599 it != code.constants_.end(); ++i, ++it) { |
605 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; | 600 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; |
606 } | 601 } |
607 for (int i = 0; i < code.BasicBlockCount(); i++) { | 602 for (int i = 0; i < code.InstructionBlockCount(); i++) { |
608 BasicBlock::RpoNumber rpo = BasicBlock::RpoNumber::FromInt(i); | 603 BasicBlock::RpoNumber rpo = BasicBlock::RpoNumber::FromInt(i); |
609 const InstructionBlock* block = code.InstructionBlockAt(rpo); | 604 const InstructionBlock* block = code.InstructionBlockAt(rpo); |
610 CHECK(block->rpo_number() == rpo); | 605 CHECK(block->rpo_number() == rpo); |
611 | 606 |
612 os << "RPO#" << block->rpo_number() << ": B" << block->id(); | 607 os << "RPO#" << block->rpo_number() << ": B" << block->id(); |
613 if (block->IsLoopHeader()) { | 608 if (block->IsLoopHeader()) { |
614 os << " loop blocks: [" << block->rpo_number() << ", " | 609 os << " loop blocks: [" << block->rpo_number() << ", " |
615 << block->loop_end() << ")"; | 610 << block->loop_end() << ")"; |
616 } | 611 } |
617 os << " instructions: [" << block->code_start() << ", " | 612 os << " instructions: [" << block->code_start() << ", " |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 os << " B" << succ_block->id(); | 646 os << " B" << succ_block->id(); |
652 } | 647 } |
653 os << "\n"; | 648 os << "\n"; |
654 } | 649 } |
655 return os; | 650 return os; |
656 } | 651 } |
657 | 652 |
658 } // namespace compiler | 653 } // namespace compiler |
659 } // namespace internal | 654 } // namespace internal |
660 } // namespace v8 | 655 } // namespace v8 |
OLD | NEW |