blob: 8f660ce0e00373bdd5521b183527e972fc68c75c [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"
37#elif V8_TARGET_ARCH_ARM
38#include "arm/lithium-arm.h"
lrn@chromium.org7516f052011-03-30 08:52:27 +000039#elif V8_TARGET_ARCH_MIPS
40#include "mips/lithium-mips.h"
ricow@chromium.org83aa5492011-02-07 12:42:56 +000041#else
42#error "Unknown architecture."
43#endif
44
45namespace v8 {
46namespace internal {
47
48bool LAllocator::IsGapAt(int index) { return chunk_->IsGapAt(index); }
49
50
51LInstruction* LAllocator::InstructionAt(int index) {
52 return chunk_->instructions()->at(index);
53}
54
55
56LGap* LAllocator::GapAt(int index) {
57 return chunk_->GetGapAt(index);
58}
59
60
61TempIterator::TempIterator(LInstruction* instr)
62 : instr_(instr),
63 limit_(instr->TempCount()),
64 current_(0) {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000065 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000066}
67
68
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000069bool TempIterator::Done() { return current_ >= limit_; }
ricow@chromium.org83aa5492011-02-07 12:42:56 +000070
71
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000072LOperand* TempIterator::Current() {
73 ASSERT(!Done());
ricow@chromium.org83aa5492011-02-07 12:42:56 +000074 return instr_->TempAt(current_);
75}
76
77
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000078void TempIterator::SkipUninteresting() {
79 while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_;
ricow@chromium.org83aa5492011-02-07 12:42:56 +000080}
81
82
83void TempIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000084 ++current_;
85 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000086}
87
88
89InputIterator::InputIterator(LInstruction* instr)
90 : instr_(instr),
91 limit_(instr->InputCount()),
92 current_(0) {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000093 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +000094}
95
96
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000097bool InputIterator::Done() { return current_ >= limit_; }
ricow@chromium.org83aa5492011-02-07 12:42:56 +000098
99
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000100LOperand* InputIterator::Current() {
101 ASSERT(!Done());
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000102 return instr_->InputAt(current_);
103}
104
105
106void InputIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000107 ++current_;
108 SkipUninteresting();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000109}
110
111
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000112void InputIterator::SkipUninteresting() {
113 while (current_ < limit_ && instr_->InputAt(current_)->IsConstantOperand()) {
114 ++current_;
115 }
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000116}
117
118
119UseIterator::UseIterator(LInstruction* instr)
120 : input_iterator_(instr), env_iterator_(instr->environment()) { }
121
122
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000123bool UseIterator::Done() {
124 return input_iterator_.Done() && env_iterator_.Done();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000125}
126
127
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000128LOperand* UseIterator::Current() {
129 ASSERT(!Done());
130 return input_iterator_.Done()
131 ? env_iterator_.Current()
132 : input_iterator_.Current();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000133}
134
135
136void UseIterator::Advance() {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000137 input_iterator_.Done()
138 ? env_iterator_.Advance()
139 : input_iterator_.Advance();
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000140}
141
142} } // namespace v8::internal
143
144#endif // V8_LITHIUM_ALLOCATOR_INL_H_