jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_LITHIUM_ALLOCATOR_INL_H_ |
| 29 | #define V8_LITHIUM_ALLOCATOR_INL_H_ |
| 30 | |
| 31 | #include "lithium-allocator.h" |
| 32 | |
| 33 | #if V8_TARGET_ARCH_IA32 |
| 34 | #include "ia32/lithium-ia32.h" |
| 35 | #elif V8_TARGET_ARCH_X64 |
| 36 | #include "x64/lithium-x64.h" |
| 37 | #elif V8_TARGET_ARCH_ARM |
| 38 | #include "arm/lithium-arm.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 39 | #elif V8_TARGET_ARCH_MIPS |
| 40 | #include "mips/lithium-mips.h" |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 41 | #else |
| 42 | #error "Unknown architecture." |
| 43 | #endif |
| 44 | |
| 45 | namespace v8 { |
| 46 | namespace internal { |
| 47 | |
| 48 | bool LAllocator::IsGapAt(int index) { return chunk_->IsGapAt(index); } |
| 49 | |
| 50 | |
| 51 | LInstruction* LAllocator::InstructionAt(int index) { |
| 52 | return chunk_->instructions()->at(index); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | LGap* LAllocator::GapAt(int index) { |
| 57 | return chunk_->GetGapAt(index); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | TempIterator::TempIterator(LInstruction* instr) |
| 62 | : instr_(instr), |
| 63 | limit_(instr->TempCount()), |
| 64 | current_(0) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 65 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 69 | bool TempIterator::Done() { return current_ >= limit_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 70 | |
| 71 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 72 | LOperand* TempIterator::Current() { |
| 73 | ASSERT(!Done()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 74 | return instr_->TempAt(current_); |
| 75 | } |
| 76 | |
| 77 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 78 | void TempIterator::SkipUninteresting() { |
| 79 | while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | void TempIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 84 | ++current_; |
| 85 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
| 89 | InputIterator::InputIterator(LInstruction* instr) |
| 90 | : instr_(instr), |
| 91 | limit_(instr->InputCount()), |
| 92 | current_(0) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 93 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 97 | bool InputIterator::Done() { return current_ >= limit_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 98 | |
| 99 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 100 | LOperand* InputIterator::Current() { |
| 101 | ASSERT(!Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 102 | ASSERT(instr_->InputAt(current_) != NULL); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 103 | return instr_->InputAt(current_); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void InputIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 108 | ++current_; |
| 109 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 113 | void InputIterator::SkipUninteresting() { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 114 | while (current_ < limit_) { |
| 115 | LOperand* current = instr_->InputAt(current_); |
| 116 | if (current != NULL && !current->IsConstantOperand()) break; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 117 | ++current_; |
| 118 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
| 122 | UseIterator::UseIterator(LInstruction* instr) |
| 123 | : input_iterator_(instr), env_iterator_(instr->environment()) { } |
| 124 | |
| 125 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 126 | bool UseIterator::Done() { |
| 127 | return input_iterator_.Done() && env_iterator_.Done(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 131 | LOperand* UseIterator::Current() { |
| 132 | ASSERT(!Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 133 | LOperand* result = input_iterator_.Done() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 134 | ? env_iterator_.Current() |
| 135 | : input_iterator_.Current(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 136 | ASSERT(result != NULL); |
| 137 | return result; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | void UseIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 142 | input_iterator_.Done() |
| 143 | ? env_iterator_.Advance() |
| 144 | : input_iterator_.Advance(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 145 | } |
| 146 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 147 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 148 | void LAllocator::SetLiveRangeAssignedRegister(LiveRange* range, int reg) { |
| 149 | if (range->Kind() == DOUBLE_REGISTERS) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 150 | assigned_double_registers_->Add(reg); |
| 151 | } else { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 152 | ASSERT(range->Kind() == GENERAL_REGISTERS); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 153 | assigned_registers_->Add(reg); |
| 154 | } |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 155 | range->set_assigned_register(reg, chunk()->zone()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 159 | } } // namespace v8::internal |
| 160 | |
| 161 | #endif // V8_LITHIUM_ALLOCATOR_INL_H_ |