• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 the V8 project authors. All rights reserved.
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"
39 #elif V8_TARGET_ARCH_MIPS
40 #include "mips/lithium-mips.h"
41 #else
42 #error "Unknown architecture."
43 #endif
44 
45 namespace v8 {
46 namespace internal {
47 
IsGapAt(int index)48 bool LAllocator::IsGapAt(int index) { return chunk_->IsGapAt(index); }
49 
50 
InstructionAt(int index)51 LInstruction* LAllocator::InstructionAt(int index) {
52   return chunk_->instructions()->at(index);
53 }
54 
55 
GapAt(int index)56 LGap* LAllocator::GapAt(int index) {
57   return chunk_->GetGapAt(index);
58 }
59 
60 
TempIterator(LInstruction * instr)61 TempIterator::TempIterator(LInstruction* instr)
62     : instr_(instr),
63       limit_(instr->TempCount()),
64       current_(0) {
65   current_ = AdvanceToNext(0);
66 }
67 
68 
HasNext()69 bool TempIterator::HasNext() { return current_ < limit_; }
70 
71 
Next()72 LOperand* TempIterator::Next() {
73   ASSERT(HasNext());
74   return instr_->TempAt(current_);
75 }
76 
77 
AdvanceToNext(int start)78 int TempIterator::AdvanceToNext(int start) {
79   while (start < limit_ && instr_->TempAt(start) == NULL) start++;
80   return start;
81 }
82 
83 
Advance()84 void TempIterator::Advance() {
85   current_ = AdvanceToNext(current_ + 1);
86 }
87 
88 
InputIterator(LInstruction * instr)89 InputIterator::InputIterator(LInstruction* instr)
90     : instr_(instr),
91       limit_(instr->InputCount()),
92       current_(0) {
93   current_ = AdvanceToNext(0);
94 }
95 
96 
HasNext()97 bool InputIterator::HasNext() { return current_ < limit_; }
98 
99 
Next()100 LOperand* InputIterator::Next() {
101   ASSERT(HasNext());
102   return instr_->InputAt(current_);
103 }
104 
105 
Advance()106 void InputIterator::Advance() {
107   current_ = AdvanceToNext(current_ + 1);
108 }
109 
110 
AdvanceToNext(int start)111 int InputIterator::AdvanceToNext(int start) {
112   while (start < limit_ && instr_->InputAt(start)->IsConstantOperand()) start++;
113   return start;
114 }
115 
116 
UseIterator(LInstruction * instr)117 UseIterator::UseIterator(LInstruction* instr)
118     : input_iterator_(instr), env_iterator_(instr->environment()) { }
119 
120 
HasNext()121 bool UseIterator::HasNext() {
122   return input_iterator_.HasNext() || env_iterator_.HasNext();
123 }
124 
125 
Next()126 LOperand* UseIterator::Next() {
127   ASSERT(HasNext());
128   return input_iterator_.HasNext()
129       ? input_iterator_.Next()
130       : env_iterator_.Next();
131 }
132 
133 
Advance()134 void UseIterator::Advance() {
135   input_iterator_.HasNext()
136       ? input_iterator_.Advance()
137       : env_iterator_.Advance();
138 }
139 
140 } }  // namespace v8::internal
141 
142 #endif  // V8_LITHIUM_ALLOCATOR_INL_H_
143