Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / node-properties-inl.h
1 // Copyright 2013 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_COMPILER_NODE_PROPERTIES_INL_H_
6 #define V8_COMPILER_NODE_PROPERTIES_INL_H_
7
8 #include "src/v8.h"
9
10 #include "src/compiler/common-operator.h"
11 #include "src/compiler/generic-node-inl.h"
12 #include "src/compiler/node-properties.h"
13 #include "src/compiler/opcodes.h"
14 #include "src/compiler/operator.h"
15 #include "src/compiler/operator-properties-inl.h"
16 #include "src/compiler/operator-properties.h"
17
18 namespace v8 {
19 namespace internal {
20 namespace compiler {
21
22 // -----------------------------------------------------------------------------
23 // Input layout.
24 // Inputs are always arranged in order as follows:
25 //     0 [ values, context, effects, control ] node->InputCount()
26
27 inline int NodeProperties::FirstValueIndex(Node* node) { return 0; }
28
29 inline int NodeProperties::FirstContextIndex(Node* node) {
30   return PastValueIndex(node);
31 }
32
33 inline int NodeProperties::FirstFrameStateIndex(Node* node) {
34   return PastContextIndex(node);
35 }
36
37 inline int NodeProperties::FirstEffectIndex(Node* node) {
38   return PastFrameStateIndex(node);
39 }
40
41 inline int NodeProperties::FirstControlIndex(Node* node) {
42   return PastEffectIndex(node);
43 }
44
45
46 inline int NodeProperties::PastValueIndex(Node* node) {
47   return FirstValueIndex(node) + node->op()->ValueInputCount();
48 }
49
50 inline int NodeProperties::PastContextIndex(Node* node) {
51   return FirstContextIndex(node) +
52          OperatorProperties::GetContextInputCount(node->op());
53 }
54
55 inline int NodeProperties::PastFrameStateIndex(Node* node) {
56   return FirstFrameStateIndex(node) +
57          OperatorProperties::GetFrameStateInputCount(node->op());
58 }
59
60 inline int NodeProperties::PastEffectIndex(Node* node) {
61   return FirstEffectIndex(node) + node->op()->EffectInputCount();
62 }
63
64 inline int NodeProperties::PastControlIndex(Node* node) {
65   return FirstControlIndex(node) + node->op()->ControlInputCount();
66 }
67
68
69 // -----------------------------------------------------------------------------
70 // Input accessors.
71
72 inline Node* NodeProperties::GetValueInput(Node* node, int index) {
73   DCHECK(0 <= index && index < node->op()->ValueInputCount());
74   return node->InputAt(FirstValueIndex(node) + index);
75 }
76
77 inline Node* NodeProperties::GetContextInput(Node* node) {
78   DCHECK(OperatorProperties::HasContextInput(node->op()));
79   return node->InputAt(FirstContextIndex(node));
80 }
81
82 inline Node* NodeProperties::GetFrameStateInput(Node* node) {
83   DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
84   return node->InputAt(FirstFrameStateIndex(node));
85 }
86
87 inline Node* NodeProperties::GetEffectInput(Node* node, int index) {
88   DCHECK(0 <= index && index < node->op()->EffectInputCount());
89   return node->InputAt(FirstEffectIndex(node) + index);
90 }
91
92 inline Node* NodeProperties::GetControlInput(Node* node, int index) {
93   DCHECK(0 <= index && index < node->op()->ControlInputCount());
94   return node->InputAt(FirstControlIndex(node) + index);
95 }
96
97 inline int NodeProperties::GetFrameStateIndex(Node* node) {
98   DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
99   return FirstFrameStateIndex(node);
100 }
101
102 // -----------------------------------------------------------------------------
103 // Edge kinds.
104
105 inline bool NodeProperties::IsInputRange(Node::Edge edge, int first, int num) {
106   // TODO(titzer): edge.index() is linear time;
107   // edges maybe need to be marked as value/effect/control.
108   if (num == 0) return false;
109   int index = edge.index();
110   return first <= index && index < first + num;
111 }
112
113 inline bool NodeProperties::IsValueEdge(Node::Edge edge) {
114   Node* node = edge.from();
115   return IsInputRange(edge, FirstValueIndex(node),
116                       node->op()->ValueInputCount());
117 }
118
119 inline bool NodeProperties::IsContextEdge(Node::Edge edge) {
120   Node* node = edge.from();
121   return IsInputRange(edge, FirstContextIndex(node),
122                       OperatorProperties::GetContextInputCount(node->op()));
123 }
124
125 inline bool NodeProperties::IsEffectEdge(Node::Edge edge) {
126   Node* node = edge.from();
127   return IsInputRange(edge, FirstEffectIndex(node),
128                       node->op()->EffectInputCount());
129 }
130
131 inline bool NodeProperties::IsControlEdge(Node::Edge edge) {
132   Node* node = edge.from();
133   return IsInputRange(edge, FirstControlIndex(node),
134                       node->op()->ControlInputCount());
135 }
136
137
138 // -----------------------------------------------------------------------------
139 // Miscellaneous predicates.
140
141 inline bool NodeProperties::IsControl(Node* node) {
142   return IrOpcode::IsControlOpcode(node->opcode());
143 }
144
145
146 // -----------------------------------------------------------------------------
147 // Miscellaneous mutators.
148
149 inline void NodeProperties::ReplaceControlInput(Node* node, Node* control) {
150   node->ReplaceInput(FirstControlIndex(node), control);
151 }
152
153 inline void NodeProperties::ReplaceEffectInput(Node* node, Node* effect,
154                                                int index) {
155   DCHECK(index < node->op()->EffectInputCount());
156   return node->ReplaceInput(FirstEffectIndex(node) + index, effect);
157 }
158
159 inline void NodeProperties::ReplaceFrameStateInput(Node* node,
160                                                    Node* frame_state) {
161   DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
162   node->ReplaceInput(FirstFrameStateIndex(node), frame_state);
163 }
164
165 inline void NodeProperties::RemoveNonValueInputs(Node* node) {
166   node->TrimInputCount(node->op()->ValueInputCount());
167 }
168
169
170 // Replace value uses of {node} with {value} and effect uses of {node} with
171 // {effect}. If {effect == NULL}, then use the effect input to {node}.
172 inline void NodeProperties::ReplaceWithValue(Node* node, Node* value,
173                                              Node* effect) {
174   DCHECK(node->op()->ControlOutputCount() == 0);
175   if (effect == NULL && node->op()->EffectInputCount() > 0) {
176     effect = NodeProperties::GetEffectInput(node);
177   }
178
179   // Requires distinguishing between value and effect edges.
180   UseIter iter = node->uses().begin();
181   while (iter != node->uses().end()) {
182     if (NodeProperties::IsEffectEdge(iter.edge())) {
183       DCHECK_NE(NULL, effect);
184       iter = iter.UpdateToAndIncrement(effect);
185     } else {
186       iter = iter.UpdateToAndIncrement(value);
187     }
188   }
189 }
190
191
192 // -----------------------------------------------------------------------------
193 // Type Bounds.
194
195 inline bool NodeProperties::IsTyped(Node* node) {
196   Bounds bounds = node->bounds();
197   DCHECK((bounds.lower == NULL) == (bounds.upper == NULL));
198   return bounds.upper != NULL;
199 }
200
201 inline Bounds NodeProperties::GetBounds(Node* node) {
202   DCHECK(IsTyped(node));
203   return node->bounds();
204 }
205
206 inline void NodeProperties::SetBounds(Node* node, Bounds b) {
207   DCHECK(b.lower != NULL && b.upper != NULL);
208   node->set_bounds(b);
209 }
210
211 inline bool NodeProperties::AllValueInputsAreTyped(Node* node) {
212   int input_count = node->op()->ValueInputCount();
213   for (int i = 0; i < input_count; ++i) {
214     if (!IsTyped(GetValueInput(node, i))) return false;
215   }
216   return true;
217 }
218
219
220 }
221 }
222 }  // namespace v8::internal::compiler
223
224 #endif  // V8_COMPILER_NODE_PROPERTIES_INL_H_