OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 result = new(zone_) LiveRange(FixedLiveRangeID(index), zone_); | 644 result = new(zone_) LiveRange(FixedLiveRangeID(index), zone_); |
645 ASSERT(result->IsFixed()); | 645 ASSERT(result->IsFixed()); |
646 result->set_assigned_register(index, GENERAL_REGISTERS, zone_); | 646 result->set_assigned_register(index, GENERAL_REGISTERS, zone_); |
647 fixed_live_ranges_[index] = result; | 647 fixed_live_ranges_[index] = result; |
648 } | 648 } |
649 return result; | 649 return result; |
650 } | 650 } |
651 | 651 |
652 | 652 |
653 LiveRange* LAllocator::FixedDoubleLiveRangeFor(int index) { | 653 LiveRange* LAllocator::FixedDoubleLiveRangeFor(int index) { |
654 ASSERT(index < DoubleRegister::kNumAllocatableRegisters); | 654 ASSERT(index < DoubleRegister::NumAllocatableRegisters()); |
655 LiveRange* result = fixed_double_live_ranges_[index]; | 655 LiveRange* result = fixed_double_live_ranges_[index]; |
656 if (result == NULL) { | 656 if (result == NULL) { |
657 result = new(zone_) LiveRange(FixedDoubleLiveRangeID(index), zone_); | 657 result = new(zone_) LiveRange(FixedDoubleLiveRangeID(index), zone_); |
658 ASSERT(result->IsFixed()); | 658 ASSERT(result->IsFixed()); |
659 result->set_assigned_register(index, DOUBLE_REGISTERS, zone_); | 659 result->set_assigned_register(index, DOUBLE_REGISTERS, zone_); |
660 fixed_double_live_ranges_[index] = result; | 660 fixed_double_live_ranges_[index] = result; |
661 } | 661 } |
662 return result; | 662 return result; |
663 } | 663 } |
664 | 664 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 output->index() != i) { | 952 output->index() != i) { |
953 LiveRange* range = FixedLiveRangeFor(i); | 953 LiveRange* range = FixedLiveRangeFor(i); |
954 range->AddUseInterval(curr_position, | 954 range->AddUseInterval(curr_position, |
955 curr_position.InstructionEnd(), | 955 curr_position.InstructionEnd(), |
956 zone_); | 956 zone_); |
957 } | 957 } |
958 } | 958 } |
959 } | 959 } |
960 | 960 |
961 if (instr->IsMarkedAsCall()) { | 961 if (instr->IsMarkedAsCall()) { |
962 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) { | 962 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); ++i) { |
963 if (output == NULL || !output->IsDoubleRegister() || | 963 if (output == NULL || !output->IsDoubleRegister() || |
964 output->index() != i) { | 964 output->index() != i) { |
965 LiveRange* range = FixedDoubleLiveRangeFor(i); | 965 LiveRange* range = FixedDoubleLiveRangeFor(i); |
966 range->AddUseInterval(curr_position, | 966 range->AddUseInterval(curr_position, |
967 curr_position.InstructionEnd(), | 967 curr_position.InstructionEnd(), |
968 zone_); | 968 zone_); |
969 } | 969 } |
970 } | 970 } |
971 } | 971 } |
972 | 972 |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1471 | 1471 |
1472 void LAllocator::AllocateGeneralRegisters() { | 1472 void LAllocator::AllocateGeneralRegisters() { |
1473 HPhase phase("L_Allocate general registers", this); | 1473 HPhase phase("L_Allocate general registers", this); |
1474 num_registers_ = Register::kNumAllocatableRegisters; | 1474 num_registers_ = Register::kNumAllocatableRegisters; |
1475 AllocateRegisters(); | 1475 AllocateRegisters(); |
1476 } | 1476 } |
1477 | 1477 |
1478 | 1478 |
1479 void LAllocator::AllocateDoubleRegisters() { | 1479 void LAllocator::AllocateDoubleRegisters() { |
1480 HPhase phase("L_Allocate double registers", this); | 1480 HPhase phase("L_Allocate double registers", this); |
1481 num_registers_ = DoubleRegister::kNumAllocatableRegisters; | 1481 num_registers_ = DoubleRegister::NumAllocatableRegisters(); |
1482 mode_ = DOUBLE_REGISTERS; | 1482 mode_ = DOUBLE_REGISTERS; |
1483 AllocateRegisters(); | 1483 AllocateRegisters(); |
1484 } | 1484 } |
1485 | 1485 |
1486 | 1486 |
1487 void LAllocator::AllocateRegisters() { | 1487 void LAllocator::AllocateRegisters() { |
1488 ASSERT(unhandled_live_ranges_.is_empty()); | 1488 ASSERT(unhandled_live_ranges_.is_empty()); |
1489 | 1489 |
1490 for (int i = 0; i < live_ranges_.length(); ++i) { | 1490 for (int i = 0; i < live_ranges_.length(); ++i) { |
1491 if (live_ranges_[i] != NULL) { | 1491 if (live_ranges_[i] != NULL) { |
1492 if (RequiredRegisterKind(live_ranges_[i]->id()) == mode_) { | 1492 if (RequiredRegisterKind(live_ranges_[i]->id()) == mode_) { |
1493 AddToUnhandledUnsorted(live_ranges_[i]); | 1493 AddToUnhandledUnsorted(live_ranges_[i]); |
1494 } | 1494 } |
1495 } | 1495 } |
1496 } | 1496 } |
1497 SortUnhandled(); | 1497 SortUnhandled(); |
1498 ASSERT(UnhandledIsSorted()); | 1498 ASSERT(UnhandledIsSorted()); |
1499 | 1499 |
1500 ASSERT(reusable_slots_.is_empty()); | 1500 ASSERT(reusable_slots_.is_empty()); |
1501 ASSERT(active_live_ranges_.is_empty()); | 1501 ASSERT(active_live_ranges_.is_empty()); |
1502 ASSERT(inactive_live_ranges_.is_empty()); | 1502 ASSERT(inactive_live_ranges_.is_empty()); |
1503 | 1503 |
1504 if (mode_ == DOUBLE_REGISTERS) { | 1504 if (mode_ == DOUBLE_REGISTERS) { |
1505 for (int i = 0; i < fixed_double_live_ranges_.length(); ++i) { | 1505 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); ++i) { |
1506 LiveRange* current = fixed_double_live_ranges_.at(i); | 1506 LiveRange* current = fixed_double_live_ranges_.at(i); |
1507 if (current != NULL) { | 1507 if (current != NULL) { |
1508 AddToInactive(current); | 1508 AddToInactive(current); |
1509 } | 1509 } |
1510 } | 1510 } |
1511 } else { | 1511 } else { |
1512 for (int i = 0; i < fixed_live_ranges_.length(); ++i) { | 1512 for (int i = 0; i < fixed_live_ranges_.length(); ++i) { |
1513 LiveRange* current = fixed_live_ranges_.at(i); | 1513 LiveRange* current = fixed_live_ranges_.at(i); |
1514 if (current != NULL) { | 1514 if (current != NULL) { |
1515 AddToInactive(current); | 1515 AddToInactive(current); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1748 |
1749 | 1749 |
1750 void LAllocator::InactiveToActive(LiveRange* range) { | 1750 void LAllocator::InactiveToActive(LiveRange* range) { |
1751 ASSERT(inactive_live_ranges_.Contains(range)); | 1751 ASSERT(inactive_live_ranges_.Contains(range)); |
1752 inactive_live_ranges_.RemoveElement(range); | 1752 inactive_live_ranges_.RemoveElement(range); |
1753 active_live_ranges_.Add(range, zone()); | 1753 active_live_ranges_.Add(range, zone()); |
1754 TraceAlloc("Moving live range %d from inactive to active\n", range->id()); | 1754 TraceAlloc("Moving live range %d from inactive to active\n", range->id()); |
1755 } | 1755 } |
1756 | 1756 |
1757 | 1757 |
1758 // TryAllocateFreeReg and AllocateBlockedReg assume this | 1758 bool LAllocator::TryAllocateFreeReg(LiveRange* current) { |
1759 // when allocating local arrays. | 1759 ASSERT(DoubleRegister::NumAllocatableRegisters() >= |
1760 STATIC_ASSERT(DoubleRegister::kNumAllocatableRegisters >= | 1760 Register::kNumAllocatableRegisters); |
1761 Register::kNumAllocatableRegisters); | 1761 LifetimePosition free_until_pos[DoubleRegister::kNumRegisters]; |
1762 | 1762 |
1763 | 1763 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
1764 bool LAllocator::TryAllocateFreeReg(LiveRange* current) { | |
1765 LifetimePosition free_until_pos[DoubleRegister::kNumAllocatableRegisters]; | |
1766 | |
1767 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; i++) { | |
1768 free_until_pos[i] = LifetimePosition::MaxPosition(); | 1764 free_until_pos[i] = LifetimePosition::MaxPosition(); |
1769 } | 1765 } |
1770 | 1766 |
1771 for (int i = 0; i < active_live_ranges_.length(); ++i) { | 1767 for (int i = 0; i < active_live_ranges_.length(); ++i) { |
1772 LiveRange* cur_active = active_live_ranges_.at(i); | 1768 LiveRange* cur_active = active_live_ranges_.at(i); |
1773 free_until_pos[cur_active->assigned_register()] = | 1769 free_until_pos[cur_active->assigned_register()] = |
1774 LifetimePosition::FromInstructionIndex(0); | 1770 LifetimePosition::FromInstructionIndex(0); |
1775 } | 1771 } |
1776 | 1772 |
1777 for (int i = 0; i < inactive_live_ranges_.length(); ++i) { | 1773 for (int i = 0; i < inactive_live_ranges_.length(); ++i) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 TraceAlloc("Assigning free reg %s to live range %d\n", | 1833 TraceAlloc("Assigning free reg %s to live range %d\n", |
1838 RegisterName(reg), | 1834 RegisterName(reg), |
1839 current->id()); | 1835 current->id()); |
1840 current->set_assigned_register(reg, mode_, zone_); | 1836 current->set_assigned_register(reg, mode_, zone_); |
1841 | 1837 |
1842 return true; | 1838 return true; |
1843 } | 1839 } |
1844 | 1840 |
1845 | 1841 |
1846 void LAllocator::AllocateBlockedReg(LiveRange* current) { | 1842 void LAllocator::AllocateBlockedReg(LiveRange* current) { |
| 1843 ASSERT(DoubleRegister::NumAllocatableRegisters() >= |
| 1844 Register::kNumAllocatableRegisters); |
1847 UsePosition* register_use = current->NextRegisterPosition(current->Start()); | 1845 UsePosition* register_use = current->NextRegisterPosition(current->Start()); |
1848 if (register_use == NULL) { | 1846 if (register_use == NULL) { |
1849 // There is no use in the current live range that requires a register. | 1847 // There is no use in the current live range that requires a register. |
1850 // We can just spill it. | 1848 // We can just spill it. |
1851 Spill(current); | 1849 Spill(current); |
1852 return; | 1850 return; |
1853 } | 1851 } |
1854 | 1852 |
1855 | 1853 |
1856 LifetimePosition use_pos[DoubleRegister::kNumAllocatableRegisters]; | 1854 LifetimePosition use_pos[DoubleRegister::kNumRegisters]; |
1857 LifetimePosition block_pos[DoubleRegister::kNumAllocatableRegisters]; | 1855 LifetimePosition block_pos[DoubleRegister::kNumRegisters]; |
1858 | 1856 |
1859 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; i++) { | 1857 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
1860 use_pos[i] = block_pos[i] = LifetimePosition::MaxPosition(); | 1858 use_pos[i] = block_pos[i] = LifetimePosition::MaxPosition(); |
1861 } | 1859 } |
1862 | 1860 |
1863 for (int i = 0; i < active_live_ranges_.length(); ++i) { | 1861 for (int i = 0; i < active_live_ranges_.length(); ++i) { |
1864 LiveRange* range = active_live_ranges_[i]; | 1862 LiveRange* range = active_live_ranges_[i]; |
1865 int cur_reg = range->assigned_register(); | 1863 int cur_reg = range->assigned_register(); |
1866 if (range->IsFixed() || !range->CanBeSpilled(current->Start())) { | 1864 if (range->IsFixed() || !range->CanBeSpilled(current->Start())) { |
1867 block_pos[cur_reg] = use_pos[cur_reg] = | 1865 block_pos[cur_reg] = use_pos[cur_reg] = |
1868 LifetimePosition::FromInstructionIndex(0); | 1866 LifetimePosition::FromInstructionIndex(0); |
1869 } else { | 1867 } else { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 LiveRange* current = live_ranges()->at(i); | 2108 LiveRange* current = live_ranges()->at(i); |
2111 if (current != NULL) current->Verify(); | 2109 if (current != NULL) current->Verify(); |
2112 } | 2110 } |
2113 } | 2111 } |
2114 | 2112 |
2115 | 2113 |
2116 #endif | 2114 #endif |
2117 | 2115 |
2118 | 2116 |
2119 } } // namespace v8::internal | 2117 } } // namespace v8::internal |
OLD | NEW |