1// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_CRANKSHAFT_LITHIUM_INL_H_
6#define V8_CRANKSHAFT_LITHIUM_INL_H_
7
8#include "src/crankshaft/lithium.h"
9
10#if V8_TARGET_ARCH_IA32
11#include "src/crankshaft/ia32/lithium-ia32.h"  // NOLINT
12#elif V8_TARGET_ARCH_X64
13#include "src/crankshaft/x64/lithium-x64.h"  // NOLINT
14#elif V8_TARGET_ARCH_ARM64
15#include "src/crankshaft/arm64/lithium-arm64.h"  // NOLINT
16#elif V8_TARGET_ARCH_ARM
17#include "src/crankshaft/arm/lithium-arm.h"  // NOLINT
18#elif V8_TARGET_ARCH_MIPS
19#include "src/crankshaft/mips/lithium-mips.h"  // NOLINT
20#elif V8_TARGET_ARCH_MIPS64
21#include "src/crankshaft/mips64/lithium-mips64.h"  // NOLINT
22#elif V8_TARGET_ARCH_PPC
23#include "src/crankshaft/ppc/lithium-ppc.h"  // NOLINT
24#elif V8_TARGET_ARCH_S390
25#include "src/crankshaft/s390/lithium-s390.h"  // NOLINT
26#elif V8_TARGET_ARCH_X87
27#include "src/crankshaft/x87/lithium-x87.h"  // NOLINT
28#else
29#error "Unknown architecture."
30#endif
31
32namespace v8 {
33namespace internal {
34
35TempIterator::TempIterator(LInstruction* instr)
36    : instr_(instr), limit_(instr->TempCount()), current_(0) {
37  SkipUninteresting();
38}
39
40
41bool TempIterator::Done() { return current_ >= limit_; }
42
43
44LOperand* TempIterator::Current() {
45  DCHECK(!Done());
46  return instr_->TempAt(current_);
47}
48
49
50void TempIterator::SkipUninteresting() {
51  while (current_ < limit_ && instr_->TempAt(current_) == NULL) ++current_;
52}
53
54
55void TempIterator::Advance() {
56  ++current_;
57  SkipUninteresting();
58}
59
60
61InputIterator::InputIterator(LInstruction* instr)
62    : instr_(instr), limit_(instr->InputCount()), current_(0) {
63  SkipUninteresting();
64}
65
66
67bool InputIterator::Done() { return current_ >= limit_; }
68
69
70LOperand* InputIterator::Current() {
71  DCHECK(!Done());
72  DCHECK(instr_->InputAt(current_) != NULL);
73  return instr_->InputAt(current_);
74}
75
76
77void InputIterator::Advance() {
78  ++current_;
79  SkipUninteresting();
80}
81
82
83void InputIterator::SkipUninteresting() {
84  while (current_ < limit_) {
85    LOperand* current = instr_->InputAt(current_);
86    if (current != NULL && !current->IsConstantOperand()) break;
87    ++current_;
88  }
89}
90
91
92UseIterator::UseIterator(LInstruction* instr)
93    : input_iterator_(instr), env_iterator_(instr->environment()) {}
94
95
96bool UseIterator::Done() {
97  return input_iterator_.Done() && env_iterator_.Done();
98}
99
100
101LOperand* UseIterator::Current() {
102  DCHECK(!Done());
103  LOperand* result = input_iterator_.Done() ? env_iterator_.Current()
104                                            : input_iterator_.Current();
105  DCHECK(result != NULL);
106  return result;
107}
108
109
110void UseIterator::Advance() {
111  input_iterator_.Done() ? env_iterator_.Advance() : input_iterator_.Advance();
112}
113}  // namespace internal
114}  // namespace v8
115
116#endif  // V8_CRANKSHAFT_LITHIUM_INL_H_
117