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" |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame^] | 37 | #elif V8_TARGET_ARCH_A64 |
| 38 | #include "a64/lithium-a64.h" |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 39 | #elif V8_TARGET_ARCH_ARM |
| 40 | #include "arm/lithium-arm.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 41 | #elif V8_TARGET_ARCH_MIPS |
| 42 | #include "mips/lithium-mips.h" |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 43 | #else |
| 44 | #error "Unknown architecture." |
| 45 | #endif |
| 46 | |
| 47 | namespace v8 { |
| 48 | namespace internal { |
| 49 | |
| 50 | bool LAllocator::IsGapAt(int index) { return chunk_->IsGapAt(index); } |
| 51 | |
| 52 | |
| 53 | LInstruction* LAllocator::InstructionAt(int index) { |
| 54 | return chunk_->instructions()->at(index); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | LGap* LAllocator::GapAt(int index) { |
| 59 | return chunk_->GetGapAt(index); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | TempIterator::TempIterator(LInstruction* instr) |
| 64 | : instr_(instr), |
| 65 | limit_(instr->TempCount()), |
| 66 | current_(0) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 67 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 71 | bool TempIterator::Done() { return current_ >= limit_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 72 | |
| 73 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 74 | LOperand* TempIterator::Current() { |
| 75 | ASSERT(!Done()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 76 | return instr_->TempAt(current_); |
| 77 | } |
| 78 | |
| 79 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 80 | void TempIterator::SkipUninteresting() { |
| 81 | while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | void TempIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 86 | ++current_; |
| 87 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
| 91 | InputIterator::InputIterator(LInstruction* instr) |
| 92 | : instr_(instr), |
| 93 | limit_(instr->InputCount()), |
| 94 | current_(0) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 95 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 99 | bool InputIterator::Done() { return current_ >= limit_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 100 | |
| 101 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 102 | LOperand* InputIterator::Current() { |
| 103 | ASSERT(!Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 104 | ASSERT(instr_->InputAt(current_) != NULL); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 105 | return instr_->InputAt(current_); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void InputIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 110 | ++current_; |
| 111 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 115 | void InputIterator::SkipUninteresting() { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 116 | while (current_ < limit_) { |
| 117 | LOperand* current = instr_->InputAt(current_); |
| 118 | if (current != NULL && !current->IsConstantOperand()) break; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 119 | ++current_; |
| 120 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | UseIterator::UseIterator(LInstruction* instr) |
| 125 | : input_iterator_(instr), env_iterator_(instr->environment()) { } |
| 126 | |
| 127 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 128 | bool UseIterator::Done() { |
| 129 | return input_iterator_.Done() && env_iterator_.Done(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 133 | LOperand* UseIterator::Current() { |
| 134 | ASSERT(!Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 135 | LOperand* result = input_iterator_.Done() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 136 | ? env_iterator_.Current() |
| 137 | : input_iterator_.Current(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 138 | ASSERT(result != NULL); |
| 139 | return result; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | void UseIterator::Advance() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 144 | input_iterator_.Done() |
| 145 | ? env_iterator_.Advance() |
| 146 | : input_iterator_.Advance(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 147 | } |
| 148 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 149 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 150 | void LAllocator::SetLiveRangeAssignedRegister(LiveRange* range, int reg) { |
| 151 | if (range->Kind() == DOUBLE_REGISTERS) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 152 | assigned_double_registers_->Add(reg); |
| 153 | } else { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 154 | ASSERT(range->Kind() == GENERAL_REGISTERS); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 155 | assigned_registers_->Add(reg); |
| 156 | } |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 157 | range->set_assigned_register(reg, chunk()->zone()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 161 | } } // namespace v8::internal |
| 162 | |
| 163 | #endif // V8_LITHIUM_ALLOCATOR_INL_H_ |