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