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.
5 #ifndef V8_COMPILER_NODE_PROPERTIES_INL_H_
6 #define V8_COMPILER_NODE_PROPERTIES_INL_H_
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"
20 // -----------------------------------------------------------------------------
22 // Inputs are always arranged in order as follows:
23 // 0 [ values, context, effects, control ] node->InputCount()
25 inline int NodeProperties::FirstValueIndex(Node* node) { return 0; }
27 inline int NodeProperties::FirstContextIndex(Node* node) {
28 return PastValueIndex(node);
31 inline int NodeProperties::FirstFrameStateIndex(Node* node) {
32 return PastContextIndex(node);
35 inline int NodeProperties::FirstEffectIndex(Node* node) {
36 return PastFrameStateIndex(node);
39 inline int NodeProperties::FirstControlIndex(Node* node) {
40 return PastEffectIndex(node);
44 inline int NodeProperties::PastValueIndex(Node* node) {
45 return FirstValueIndex(node) + node->op()->ValueInputCount();
48 inline int NodeProperties::PastContextIndex(Node* node) {
49 return FirstContextIndex(node) +
50 OperatorProperties::GetContextInputCount(node->op());
53 inline int NodeProperties::PastFrameStateIndex(Node* node) {
54 return FirstFrameStateIndex(node) +
55 OperatorProperties::GetFrameStateInputCount(node->op());
58 inline int NodeProperties::PastEffectIndex(Node* node) {
59 return FirstEffectIndex(node) + node->op()->EffectInputCount();
62 inline int NodeProperties::PastControlIndex(Node* node) {
63 return FirstControlIndex(node) + node->op()->ControlInputCount();
67 // -----------------------------------------------------------------------------
70 inline Node* NodeProperties::GetValueInput(Node* node, int index) {
71 DCHECK(0 <= index && index < node->op()->ValueInputCount());
72 return node->InputAt(FirstValueIndex(node) + index);
75 inline Node* NodeProperties::GetContextInput(Node* node) {
76 DCHECK(OperatorProperties::HasContextInput(node->op()));
77 return node->InputAt(FirstContextIndex(node));
80 inline Node* NodeProperties::GetFrameStateInput(Node* node) {
81 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
82 return node->InputAt(FirstFrameStateIndex(node));
85 inline Node* NodeProperties::GetEffectInput(Node* node, int index) {
86 DCHECK(0 <= index && index < node->op()->EffectInputCount());
87 return node->InputAt(FirstEffectIndex(node) + index);
90 inline Node* NodeProperties::GetControlInput(Node* node, int index) {
91 DCHECK(0 <= index && index < node->op()->ControlInputCount());
92 return node->InputAt(FirstControlIndex(node) + index);
95 inline int NodeProperties::GetFrameStateIndex(Node* node) {
96 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
97 return FirstFrameStateIndex(node);
100 // -----------------------------------------------------------------------------
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;
111 inline bool NodeProperties::IsValueEdge(Edge edge) {
112 Node* node = edge.from();
113 return IsInputRange(edge, FirstValueIndex(node),
114 node->op()->ValueInputCount());
117 inline bool NodeProperties::IsContextEdge(Edge edge) {
118 Node* node = edge.from();
119 return IsInputRange(edge, FirstContextIndex(node),
120 OperatorProperties::GetContextInputCount(node->op()));
123 inline bool NodeProperties::IsEffectEdge(Edge edge) {
124 Node* node = edge.from();
125 return IsInputRange(edge, FirstEffectIndex(node),
126 node->op()->EffectInputCount());
129 inline bool NodeProperties::IsControlEdge(Edge edge) {
130 Node* node = edge.from();
131 return IsInputRange(edge, FirstControlIndex(node),
132 node->op()->ControlInputCount());
136 // -----------------------------------------------------------------------------
137 // Miscellaneous predicates.
139 inline bool NodeProperties::IsControl(Node* node) {
140 return IrOpcode::IsControlOpcode(node->opcode());
144 // -----------------------------------------------------------------------------
145 // Miscellaneous mutators.
147 inline void NodeProperties::ReplaceControlInput(Node* node, Node* control) {
148 node->ReplaceInput(FirstControlIndex(node), control);
151 inline void NodeProperties::ReplaceEffectInput(Node* node, Node* effect,
153 DCHECK(index < node->op()->EffectInputCount());
154 return node->ReplaceInput(FirstEffectIndex(node) + index, effect);
157 inline void NodeProperties::ReplaceFrameStateInput(Node* node,
159 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
160 node->ReplaceInput(FirstFrameStateIndex(node), frame_state);
163 inline void NodeProperties::RemoveNonValueInputs(Node* node) {
164 node->TrimInputCount(node->op()->ValueInputCount());
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,
172 DCHECK(node->op()->ControlOutputCount() == 0);
173 if (effect == NULL && node->op()->EffectInputCount() > 0) {
174 effect = NodeProperties::GetEffectInput(node);
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);
183 edge.UpdateTo(value);
189 // -----------------------------------------------------------------------------
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;
198 inline Bounds NodeProperties::GetBounds(Node* node) {
199 DCHECK(IsTyped(node));
200 return node->bounds();
203 inline void NodeProperties::RemoveBounds(Node* node) {
205 node->set_bounds(empty);
208 inline void NodeProperties::SetBounds(Node* node, Bounds b) {
209 DCHECK(b.lower != NULL && b.upper != NULL);
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;
224 } // namespace v8::internal::compiler
226 #endif // V8_COMPILER_NODE_PROPERTIES_INL_H_