| 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 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 AddToInactive(current); | 1539 AddToInactive(current); |
| 1540 } | 1540 } |
| 1541 } | 1541 } |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 while (!unhandled_live_ranges_.is_empty()) { | 1544 while (!unhandled_live_ranges_.is_empty()) { |
| 1545 ASSERT(UnhandledIsSorted()); | 1545 ASSERT(UnhandledIsSorted()); |
| 1546 LiveRange* current = unhandled_live_ranges_.RemoveLast(); | 1546 LiveRange* current = unhandled_live_ranges_.RemoveLast(); |
| 1547 ASSERT(UnhandledIsSorted()); | 1547 ASSERT(UnhandledIsSorted()); |
| 1548 LifetimePosition position = current->Start(); | 1548 LifetimePosition position = current->Start(); |
| 1549 #ifdef DEBUG |
| 1550 allocation_finger_ = position; |
| 1551 #endif |
| 1549 TraceAlloc("Processing interval %d start=%d\n", | 1552 TraceAlloc("Processing interval %d start=%d\n", |
| 1550 current->id(), | 1553 current->id(), |
| 1551 position.Value()); | 1554 position.Value()); |
| 1552 | 1555 |
| 1553 if (current->HasAllocatedSpillOperand()) { | 1556 if (current->HasAllocatedSpillOperand()) { |
| 1554 TraceAlloc("Live range %d already has a spill operand\n", current->id()); | 1557 TraceAlloc("Live range %d already has a spill operand\n", current->id()); |
| 1555 LifetimePosition next_pos = position; | 1558 LifetimePosition next_pos = position; |
| 1556 if (IsGapAt(next_pos.InstructionIndex())) { | 1559 if (IsGapAt(next_pos.InstructionIndex())) { |
| 1557 next_pos = next_pos.NextInstruction(); | 1560 next_pos = next_pos.NextInstruction(); |
| 1558 } | 1561 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 | 1666 |
| 1664 void LAllocator::AddToInactive(LiveRange* range) { | 1667 void LAllocator::AddToInactive(LiveRange* range) { |
| 1665 TraceAlloc("Add live range %d to inactive\n", range->id()); | 1668 TraceAlloc("Add live range %d to inactive\n", range->id()); |
| 1666 inactive_live_ranges_.Add(range, zone()); | 1669 inactive_live_ranges_.Add(range, zone()); |
| 1667 } | 1670 } |
| 1668 | 1671 |
| 1669 | 1672 |
| 1670 void LAllocator::AddToUnhandledSorted(LiveRange* range) { | 1673 void LAllocator::AddToUnhandledSorted(LiveRange* range) { |
| 1671 if (range == NULL || range->IsEmpty()) return; | 1674 if (range == NULL || range->IsEmpty()) return; |
| 1672 ASSERT(!range->HasRegisterAssigned() && !range->IsSpilled()); | 1675 ASSERT(!range->HasRegisterAssigned() && !range->IsSpilled()); |
| 1676 ASSERT(allocation_finger_.Value() <= range->Start().Value()); |
| 1673 for (int i = unhandled_live_ranges_.length() - 1; i >= 0; --i) { | 1677 for (int i = unhandled_live_ranges_.length() - 1; i >= 0; --i) { |
| 1674 LiveRange* cur_range = unhandled_live_ranges_.at(i); | 1678 LiveRange* cur_range = unhandled_live_ranges_.at(i); |
| 1675 if (range->ShouldBeAllocatedBefore(cur_range)) { | 1679 if (range->ShouldBeAllocatedBefore(cur_range)) { |
| 1676 TraceAlloc("Add live range %d to unhandled at %d\n", range->id(), i + 1); | 1680 TraceAlloc("Add live range %d to unhandled at %d\n", range->id(), i + 1); |
| 1677 unhandled_live_ranges_.InsertAt(i + 1, range, zone()); | 1681 unhandled_live_ranges_.InsertAt(i + 1, range, zone()); |
| 1678 ASSERT(UnhandledIsSorted()); | 1682 ASSERT(UnhandledIsSorted()); |
| 1679 return; | 1683 return; |
| 1680 } | 1684 } |
| 1681 } | 1685 } |
| 1682 TraceAlloc("Add live range %d to unhandled at start\n", range->id()); | 1686 TraceAlloc("Add live range %d to unhandled at start\n", range->id()); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 int reg = current->assigned_register(); | 1997 int reg = current->assigned_register(); |
| 1994 LifetimePosition split_pos = current->Start(); | 1998 LifetimePosition split_pos = current->Start(); |
| 1995 for (int i = 0; i < active_live_ranges_.length(); ++i) { | 1999 for (int i = 0; i < active_live_ranges_.length(); ++i) { |
| 1996 LiveRange* range = active_live_ranges_[i]; | 2000 LiveRange* range = active_live_ranges_[i]; |
| 1997 if (range->assigned_register() == reg) { | 2001 if (range->assigned_register() == reg) { |
| 1998 UsePosition* next_pos = range->NextRegisterPosition(current->Start()); | 2002 UsePosition* next_pos = range->NextRegisterPosition(current->Start()); |
| 1999 LifetimePosition spill_pos = FindOptimalSpillingPos(range, split_pos); | 2003 LifetimePosition spill_pos = FindOptimalSpillingPos(range, split_pos); |
| 2000 if (next_pos == NULL) { | 2004 if (next_pos == NULL) { |
| 2001 SpillAfter(range, spill_pos); | 2005 SpillAfter(range, spill_pos); |
| 2002 } else { | 2006 } else { |
| 2003 SpillBetween(range, spill_pos, next_pos->pos()); | 2007 // When spilling between spill_pos and next_pos ensure that the range |
| 2008 // remains spilled at least until the start of the current live range. |
| 2009 // This guarantees that we will not introduce new unhandled ranges that |
| 2010 // start before the current range as this violates allocation invariant |
| 2011 // and will lead to an inconsistent state of active and inactive |
| 2012 // live-ranges: ranges are allocated in order of their start positions, |
| 2013 // ranges are retired from active/inactive when the start of the |
| 2014 // current live-range is larger than their end. |
| 2015 SpillBetweenUntil(range, spill_pos, current->Start(), next_pos->pos()); |
| 2004 } | 2016 } |
| 2005 if (!AllocationOk()) return; | 2017 if (!AllocationOk()) return; |
| 2006 ActiveToHandled(range); | 2018 ActiveToHandled(range); |
| 2007 --i; | 2019 --i; |
| 2008 } | 2020 } |
| 2009 } | 2021 } |
| 2010 | 2022 |
| 2011 for (int i = 0; i < inactive_live_ranges_.length(); ++i) { | 2023 for (int i = 0; i < inactive_live_ranges_.length(); ++i) { |
| 2012 LiveRange* range = inactive_live_ranges_[i]; | 2024 LiveRange* range = inactive_live_ranges_[i]; |
| 2013 ASSERT(range->End().Value() > current->Start().Value()); | 2025 ASSERT(range->End().Value() > current->Start().Value()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 void LAllocator::SpillAfter(LiveRange* range, LifetimePosition pos) { | 2119 void LAllocator::SpillAfter(LiveRange* range, LifetimePosition pos) { |
| 2108 LiveRange* second_part = SplitRangeAt(range, pos); | 2120 LiveRange* second_part = SplitRangeAt(range, pos); |
| 2109 if (!AllocationOk()) return; | 2121 if (!AllocationOk()) return; |
| 2110 Spill(second_part); | 2122 Spill(second_part); |
| 2111 } | 2123 } |
| 2112 | 2124 |
| 2113 | 2125 |
| 2114 void LAllocator::SpillBetween(LiveRange* range, | 2126 void LAllocator::SpillBetween(LiveRange* range, |
| 2115 LifetimePosition start, | 2127 LifetimePosition start, |
| 2116 LifetimePosition end) { | 2128 LifetimePosition end) { |
| 2129 SpillBetweenUntil(range, start, start, end); |
| 2130 } |
| 2131 |
| 2132 |
| 2133 void LAllocator::SpillBetweenUntil(LiveRange* range, |
| 2134 LifetimePosition start, |
| 2135 LifetimePosition until, |
| 2136 LifetimePosition end) { |
| 2117 CHECK(start.Value() < end.Value()); | 2137 CHECK(start.Value() < end.Value()); |
| 2118 LiveRange* second_part = SplitRangeAt(range, start); | 2138 LiveRange* second_part = SplitRangeAt(range, start); |
| 2119 if (!AllocationOk()) return; | 2139 if (!AllocationOk()) return; |
| 2120 | 2140 |
| 2121 if (second_part->Start().Value() < end.Value()) { | 2141 if (second_part->Start().Value() < end.Value()) { |
| 2122 // The split result intersects with [start, end[. | 2142 // The split result intersects with [start, end[. |
| 2123 // Split it at position between ]start+1, end[, spill the middle part | 2143 // Split it at position between ]start+1, end[, spill the middle part |
| 2124 // and put the rest to unhandled. | 2144 // and put the rest to unhandled. |
| 2125 LiveRange* third_part = SplitBetween( | 2145 LiveRange* third_part = SplitBetween( |
| 2126 second_part, | 2146 second_part, |
| 2127 second_part->Start().InstructionEnd(), | 2147 Max(second_part->Start().InstructionEnd(), until), |
| 2128 end.PrevInstruction().InstructionEnd()); | 2148 end.PrevInstruction().InstructionEnd()); |
| 2129 if (!AllocationOk()) return; | 2149 if (!AllocationOk()) return; |
| 2130 | 2150 |
| 2131 ASSERT(third_part != second_part); | 2151 ASSERT(third_part != second_part); |
| 2132 | 2152 |
| 2133 Spill(second_part); | 2153 Spill(second_part); |
| 2134 AddToUnhandledSorted(third_part); | 2154 AddToUnhandledSorted(third_part); |
| 2135 } else { | 2155 } else { |
| 2136 // The split result does not intersect with [start, end[. | 2156 // The split result does not intersect with [start, end[. |
| 2137 // Nothing to spill. Just put it to unhandled as whole. | 2157 // Nothing to spill. Just put it to unhandled as whole. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2167 LiveRange* current = live_ranges()->at(i); | 2187 LiveRange* current = live_ranges()->at(i); |
| 2168 if (current != NULL) current->Verify(); | 2188 if (current != NULL) current->Verify(); |
| 2169 } | 2189 } |
| 2170 } | 2190 } |
| 2171 | 2191 |
| 2172 | 2192 |
| 2173 #endif | 2193 #endif |
| 2174 | 2194 |
| 2175 | 2195 |
| 2176 } } // namespace v8::internal | 2196 } } // namespace v8::internal |
| OLD | NEW |