ASSERT(Output() == NULL ||
LUnallocated::cast(Output())->HasFixedPolicy() ||
!LUnallocated::cast(Output())->HasRegisterPolicy());
- for (UseIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (UseIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||
operand->IsUsedAtStart());
}
- for (TempIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (TempIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
}
}
ASSERT(Output() == NULL ||
LUnallocated::cast(Output())->HasFixedPolicy() ||
!LUnallocated::cast(Output())->HasRegisterPolicy());
- for (UseIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (UseIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||
operand->IsUsedAtStart());
}
- for (TempIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (TempIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
}
}
-// Copyright 2010 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
: instr_(instr),
limit_(instr->TempCount()),
current_(0) {
- current_ = AdvanceToNext(0);
+ SkipUninteresting();
}
-bool TempIterator::HasNext() { return current_ < limit_; }
+bool TempIterator::Done() { return current_ >= limit_; }
-LOperand* TempIterator::Next() {
- ASSERT(HasNext());
+LOperand* TempIterator::Current() {
+ ASSERT(!Done());
return instr_->TempAt(current_);
}
-int TempIterator::AdvanceToNext(int start) {
- while (start < limit_ && instr_->TempAt(start) == NULL) start++;
- return start;
+void TempIterator::SkipUninteresting() {
+ while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_;
}
void TempIterator::Advance() {
- current_ = AdvanceToNext(current_ + 1);
+ ++current_;
+ SkipUninteresting();
}
: instr_(instr),
limit_(instr->InputCount()),
current_(0) {
- current_ = AdvanceToNext(0);
+ SkipUninteresting();
}
-bool InputIterator::HasNext() { return current_ < limit_; }
+bool InputIterator::Done() { return current_ >= limit_; }
-LOperand* InputIterator::Next() {
- ASSERT(HasNext());
+LOperand* InputIterator::Current() {
+ ASSERT(!Done());
return instr_->InputAt(current_);
}
void InputIterator::Advance() {
- current_ = AdvanceToNext(current_ + 1);
+ ++current_;
+ SkipUninteresting();
}
-int InputIterator::AdvanceToNext(int start) {
- while (start < limit_ && instr_->InputAt(start)->IsConstantOperand()) start++;
- return start;
+void InputIterator::SkipUninteresting() {
+ while (current_ < limit_ && instr_->InputAt(current_)->IsConstantOperand()) {
+ ++current_;
+ }
}
: input_iterator_(instr), env_iterator_(instr->environment()) { }
-bool UseIterator::HasNext() {
- return input_iterator_.HasNext() || env_iterator_.HasNext();
+bool UseIterator::Done() {
+ return input_iterator_.Done() && env_iterator_.Done();
}
-LOperand* UseIterator::Next() {
- ASSERT(HasNext());
- return input_iterator_.HasNext()
- ? input_iterator_.Next()
- : env_iterator_.Next();
+LOperand* UseIterator::Current() {
+ ASSERT(!Done());
+ return input_iterator_.Done()
+ ? env_iterator_.Current()
+ : input_iterator_.Current();
}
void UseIterator::Advance() {
- input_iterator_.HasNext()
- ? input_iterator_.Advance()
- : env_iterator_.Advance();
+ input_iterator_.Done()
+ ? env_iterator_.Advance()
+ : input_iterator_.Advance();
}
} } // namespace v8::internal
-// Copyright 2010 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
int gap_index) {
// Handle fixed temporaries.
if (first != NULL) {
- for (TempIterator it(first); it.HasNext(); it.Advance()) {
- LUnallocated* temp = LUnallocated::cast(it.Next());
+ for (TempIterator it(first); !it.Done(); it.Advance()) {
+ LUnallocated* temp = LUnallocated::cast(it.Current());
if (temp->HasFixedPolicy()) {
AllocateFixed(temp, gap_index - 1, false);
}
// Handle fixed input operands of second instruction.
if (second != NULL) {
- for (UseIterator it(second); it.HasNext(); it.Advance()) {
- LUnallocated* cur_input = LUnallocated::cast(it.Next());
+ for (UseIterator it(second); !it.Done(); it.Advance()) {
+ LUnallocated* cur_input = LUnallocated::cast(it.Current());
if (cur_input->HasFixedPolicy()) {
LUnallocated* input_copy = cur_input->CopyUnconstrained();
bool is_tagged = HasTaggedValue(cur_input->VirtualRegister());
}
}
- for (UseIterator it(instr); it.HasNext(); it.Advance()) {
- LOperand* input = it.Next();
+ for (UseIterator it(instr); !it.Done(); it.Advance()) {
+ LOperand* input = it.Current();
LifetimePosition use_pos;
if (input->IsUnallocated() &&
if (input->IsUnallocated()) live->Add(input->VirtualRegister());
}
- for (TempIterator it(instr); it.HasNext(); it.Advance()) {
- LOperand* temp = it.Next();
+ for (TempIterator it(instr); !it.Done(); it.Advance()) {
+ LOperand* temp = it.Current();
if (instr->IsMarkedAsCall()) {
if (temp->IsRegister()) continue;
if (temp->IsUnallocated()) {
class TempIterator BASE_EMBEDDED {
public:
inline explicit TempIterator(LInstruction* instr);
- inline bool HasNext();
- inline LOperand* Next();
+ inline bool Done();
+ inline LOperand* Current();
inline void Advance();
private:
- inline int AdvanceToNext(int start);
+ inline void SkipUninteresting();
LInstruction* instr_;
int limit_;
int current_;
class InputIterator BASE_EMBEDDED {
public:
inline explicit InputIterator(LInstruction* instr);
- inline bool HasNext();
- inline LOperand* Next();
+ inline bool Done();
+ inline LOperand* Current();
inline void Advance();
private:
- inline int AdvanceToNext(int start);
+ inline void SkipUninteresting();
LInstruction* instr_;
int limit_;
int current_;
class UseIterator BASE_EMBEDDED {
public:
inline explicit UseIterator(LInstruction* instr);
- inline bool HasNext();
- inline LOperand* Next();
+ inline bool Done();
+ inline LOperand* Current();
inline void Advance();
private:
: env_(env),
limit_(env != NULL ? env->values()->length() : 0),
current_(0) {
- current_ = AdvanceToNext(0);
+ SkipUninteresting();
}
- inline bool HasNext() {
- return env_ != NULL && current_ < limit_;
- }
+ bool Done() { return current_ >= limit_; }
- inline LOperand* Next() {
- ASSERT(HasNext());
+ LOperand* Current() {
+ ASSERT(!Done());
return env_->values()->at(current_);
}
- inline void Advance() {
- current_ = AdvanceToNext(current_ + 1);
+ void Advance() {
+ ASSERT(!Done());
+ ++current_;
+ SkipUninteresting();
}
- inline LEnvironment* env() { return env_; }
+ LEnvironment* env() { return env_; }
private:
- inline bool ShouldSkip(LOperand* op) {
+ bool ShouldSkip(LOperand* op) {
return op == NULL || op->IsConstantOperand() || op->IsArgument();
}
- inline int AdvanceToNext(int start) {
- while (start < limit_ && ShouldSkip(env_->values()->at(start))) {
- start++;
+ // Skip until something interesting, beginning with and including current_.
+ void SkipUninteresting() {
+ while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) {
+ ++current_;
}
- return start;
}
LEnvironment* env_;
class DeepIterator BASE_EMBEDDED {
public:
explicit DeepIterator(LEnvironment* env)
- : current_iterator_(env) { }
-
- inline bool HasNext() {
- if (current_iterator_.HasNext()) return true;
- if (current_iterator_.env() == NULL) return false;
- AdvanceToOuter();
- return current_iterator_.HasNext();
+ : current_iterator_(env) {
+ SkipUninteresting();
}
- inline LOperand* Next() {
- ASSERT(current_iterator_.HasNext());
- return current_iterator_.Next();
+ bool Done() { return current_iterator_.Done(); }
+
+ LOperand* Current() {
+ ASSERT(!current_iterator_.Done());
+ return current_iterator_.Current();
}
- inline void Advance() {
- if (current_iterator_.HasNext()) {
- current_iterator_.Advance();
- } else {
- AdvanceToOuter();
- }
+ void Advance() {
+ current_iterator_.Advance();
+ SkipUninteresting();
}
private:
- inline void AdvanceToOuter() {
- current_iterator_ = ShallowIterator(current_iterator_.env()->outer());
+ void SkipUninteresting() {
+ while (current_iterator_.env() != NULL && current_iterator_.Done()) {
+ current_iterator_ = ShallowIterator(current_iterator_.env()->outer());
+ }
}
ShallowIterator current_iterator_;
ASSERT(Output() == NULL ||
LUnallocated::cast(Output())->HasFixedPolicy() ||
!LUnallocated::cast(Output())->HasRegisterPolicy());
- for (UseIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (UseIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||
operand->IsUsedAtStart());
}
- for (TempIterator it(this); it.HasNext(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Next());
+ for (TempIterator it(this); !it.Done(); it.Advance()) {
+ LUnallocated* operand = LUnallocated::cast(it.Current());
ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
}
}
--- /dev/null
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+// Test that the Lithium environment iterator does stop iteration early.
+"use strict";
+
+function f0() {
+ return f1('literal', true);
+}
+
+function f1(x, y) {
+ return f2(x, y);
+}
+
+// Because it's strict, f2 has an environment containing only the constants
+// undefined, 'literal', and false. Bug 1423 would cause environment
+// iteration to stop early.
+//
+// Bug manifests as UNREACHABLE code (due to an unallocated register) in
+// debug builds.
+function f2(x, y) {
+ if (y) {
+ if (f3(x, 'other-literal')) {
+ return 0;
+ } else {
+ return 1;
+ }
+ } else {
+ return 2;
+ }
+}
+
+function f3(x, y) {
+ return x === y;
+}
+
+for (var i = 0; i < 5; ++i) f0();
+%OptimizeFunctionOnNextCall(f0);
+assertEquals(1, f0());