Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/compiler/node-properties.h" |
| 12 | #include "src/compiler/opcodes.h" |
| 13 | #include "src/compiler/operator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 45 | return FirstValueIndex(node) + node->op()->ValueInputCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 59 | return FirstEffectIndex(node) + node->op()->EffectInputCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | inline int NodeProperties::PastControlIndex(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 63 | return FirstControlIndex(node) + node->op()->ControlInputCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | |
| 67 | // ----------------------------------------------------------------------------- |
| 68 | // Input accessors. |
| 69 | |
| 70 | inline Node* NodeProperties::GetValueInput(Node* node, int index) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 71 | DCHECK(0 <= index && index < node->op()->ValueInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 86 | DCHECK(0 <= index && index < node->op()->EffectInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 87 | return node->InputAt(FirstEffectIndex(node) + index); |
| 88 | } |
| 89 | |
| 90 | inline Node* NodeProperties::GetControlInput(Node* node, int index) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 91 | DCHECK(0 <= index && index < node->op()->ControlInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 103 | inline bool NodeProperties::IsInputRange(Edge edge, int first, int num) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 111 | inline bool NodeProperties::IsValueEdge(Edge edge) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | Node* node = edge.from(); |
| 113 | return IsInputRange(edge, FirstValueIndex(node), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 114 | node->op()->ValueInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 117 | inline bool NodeProperties::IsContextEdge(Edge edge) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | Node* node = edge.from(); |
| 119 | return IsInputRange(edge, FirstContextIndex(node), |
| 120 | OperatorProperties::GetContextInputCount(node->op())); |
| 121 | } |
| 122 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 123 | inline bool NodeProperties::IsEffectEdge(Edge edge) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | Node* node = edge.from(); |
| 125 | return IsInputRange(edge, FirstEffectIndex(node), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 126 | node->op()->EffectInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 129 | inline bool NodeProperties::IsControlEdge(Edge edge) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | Node* node = edge.from(); |
| 131 | return IsInputRange(edge, FirstControlIndex(node), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 132 | node->op()->ControlInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 153 | DCHECK(index < node->op()->EffectInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 164 | node->TrimInputCount(node->op()->ValueInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 172 | DCHECK(node->op()->ControlOutputCount() == 0); |
| 173 | if (effect == NULL && node->op()->EffectInputCount() > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | effect = NodeProperties::GetEffectInput(node); |
| 175 | } |
| 176 | |
| 177 | // Requires distinguishing between value and effect edges. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 178 | for (Edge edge : node->use_edges()) { |
| 179 | if (NodeProperties::IsEffectEdge(edge)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | DCHECK_NE(NULL, effect); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | edge.UpdateTo(effect); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 182 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 183 | edge.UpdateTo(value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | // ----------------------------------------------------------------------------- |
| 190 | // Type Bounds. |
| 191 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 207 | |
| 208 | inline void NodeProperties::SetBounds(Node* node, Bounds b) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 209 | DCHECK(b.lower != NULL && b.upper != NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | node->set_bounds(b); |
| 211 | } |
| 212 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 221 | |
| 222 | } |
| 223 | } |
| 224 | } // namespace v8::internal::compiler |
| 225 | |
| 226 | #endif // V8_COMPILER_NODE_PROPERTIES_INL_H_ |