blob: 1d43b269f9ae099289819b8bb56ec554e3193676 [file] [log] [blame]
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00001// Copyright 2011 the V8 project authors. All rights reserved.
ricow@chromium.org83aa5492011-02-07 12:42:56 +00002// 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.orgf5a24542014-03-04 09:06:17 +000037#elif V8_TARGET_ARCH_A64
38#include "a64/lithium-a64.h"
ricow@chromium.org83aa5492011-02-07 12:42:56 +000039#elif V8_TARGET_ARCH_ARM
40#include "arm/lithium-arm.h"
lrn@chromium.org7516f052011-03-30 08:52:27 +000041#elif V8_TARGET_ARCH_MIPS
42#include "mips/lithium-mips.h"
ricow@chromium.org83aa5492011-02-07 12:42:56 +000043#else
44#error "Unknown architecture."
45#endif
46
47namespace v8 {
48namespace internal {
49
50bool LAllocator::IsGapAt(int index) { return chunk_->IsGapAt(index); }
51
52
53LInstruction* LAllocator::InstructionAt(int index) {
54 return chunk_->instructions()->at(index);
55}
56
57
58LGap* LAllocator::GapAt(int index) {
59 return chunk_->GetGapAt(index);
60}
61
62
63TempIterator::TempIterator(LInstruction* instr)
64 : instr_(instr),
65 limit_(instr->TempCount()),
66 current_(0) {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000067 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000068}
69
70
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000071bool TempIterator::Done() { return current_ >= limit_; }
ricow@chromium.org83aa5492011-02-07 12:42:56 +000072
73
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000074LOperand* TempIterator::Current() {
75 ASSERT(!Done());
ricow@chromium.org83aa5492011-02-07 12:42:56 +000076 return instr_->TempAt(current_);
77}
78
79
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000080void TempIterator::SkipUninteresting() {
81 while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_;
ricow@chromium.org83aa5492011-02-07 12:42:56 +000082}
83
84
85void TempIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000086 ++current_;
87 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000088}
89
90
91InputIterator::InputIterator(LInstruction* instr)
92 : instr_(instr),
93 limit_(instr->InputCount()),
94 current_(0) {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000095 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000096}
97
98
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000099bool InputIterator::Done() { return current_ >= limit_; }
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000100
101
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000102LOperand* InputIterator::Current() {
103 ASSERT(!Done());
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000104 ASSERT(instr_->InputAt(current_) != NULL);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000105 return instr_->InputAt(current_);
106}
107
108
109void InputIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000110 ++current_;
111 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000112}
113
114
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000115void InputIterator::SkipUninteresting() {
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000116 while (current_ < limit_) {
117 LOperand* current = instr_->InputAt(current_);
118 if (current != NULL && !current->IsConstantOperand()) break;
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000119 ++current_;
120 }
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000121}
122
123
124UseIterator::UseIterator(LInstruction* instr)
125 : input_iterator_(instr), env_iterator_(instr->environment()) { }
126
127
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000128bool UseIterator::Done() {
129 return input_iterator_.Done() && env_iterator_.Done();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000130}
131
132
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000133LOperand* UseIterator::Current() {
134 ASSERT(!Done());
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000135 LOperand* result = input_iterator_.Done()
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000136 ? env_iterator_.Current()
137 : input_iterator_.Current();
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000138 ASSERT(result != NULL);
139 return result;
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000140}
141
142
143void UseIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000144 input_iterator_.Done()
145 ? env_iterator_.Advance()
146 : input_iterator_.Advance();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000147}
148
danno@chromium.org94b0d6f2013-02-04 13:33:20 +0000149
jkummerow@chromium.orgc3669762013-09-30 13:42:25 +0000150void LAllocator::SetLiveRangeAssignedRegister(LiveRange* range, int reg) {
151 if (range->Kind() == DOUBLE_REGISTERS) {
danno@chromium.org94b0d6f2013-02-04 13:33:20 +0000152 assigned_double_registers_->Add(reg);
153 } else {
jkummerow@chromium.orgc3669762013-09-30 13:42:25 +0000154 ASSERT(range->Kind() == GENERAL_REGISTERS);
danno@chromium.org94b0d6f2013-02-04 13:33:20 +0000155 assigned_registers_->Add(reg);
156 }
jkummerow@chromium.orgc3669762013-09-30 13:42:25 +0000157 range->set_assigned_register(reg, chunk()->zone());
danno@chromium.org94b0d6f2013-02-04 13:33:20 +0000158}
159
160
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000161} } // namespace v8::internal
162
163#endif // V8_LITHIUM_ALLOCATOR_INL_H_