| OLD | NEW |
| (Empty) | |
| 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-inl.h" |
| 15 #include "src/compiler/operator-properties.h" |
| 16 |
| 17 namespace v8 { |
| 18 namespace internal { |
| 19 namespace compiler { |
| 20 |
| 21 // ----------------------------------------------------------------------------- |
| 22 // Input counts & layout. |
| 23 // Inputs are always arranged in order as follows: |
| 24 // 0 [ values, context, effects, control ] node->InputCount() |
| 25 |
| 26 inline bool NodeProperties::HasValueInput(Node* node) { |
| 27 return OperatorProperties::GetValueInputCount(node->op()) > 0; |
| 28 } |
| 29 |
| 30 inline bool NodeProperties::HasContextInput(Node* node) { |
| 31 return OperatorProperties::HasContextInput(node->op()); |
| 32 } |
| 33 |
| 34 inline bool NodeProperties::HasEffectInput(Node* node) { |
| 35 return OperatorProperties::GetEffectInputCount(node->op()) > 0; |
| 36 } |
| 37 |
| 38 inline bool NodeProperties::HasControlInput(Node* node) { |
| 39 return OperatorProperties::GetControlInputCount(node->op()) > 0; |
| 40 } |
| 41 |
| 42 |
| 43 inline int NodeProperties::GetValueInputCount(Node* node) { |
| 44 return OperatorProperties::GetValueInputCount(node->op()); |
| 45 } |
| 46 |
| 47 inline int NodeProperties::GetContextInputCount(Node* node) { |
| 48 return OperatorProperties::HasContextInput(node->op()) ? 1 : 0; |
| 49 } |
| 50 |
| 51 inline int NodeProperties::GetEffectInputCount(Node* node) { |
| 52 return OperatorProperties::GetEffectInputCount(node->op()); |
| 53 } |
| 54 |
| 55 inline int NodeProperties::GetControlInputCount(Node* node) { |
| 56 return OperatorProperties::GetControlInputCount(node->op()); |
| 57 } |
| 58 |
| 59 |
| 60 inline int NodeProperties::FirstValueIndex(Node* node) { |
| 61 return 0; |
| 62 } |
| 63 |
| 64 inline int NodeProperties::FirstContextIndex(Node* node) { |
| 65 return PastValueIndex(node); |
| 66 } |
| 67 |
| 68 inline int NodeProperties::FirstEffectIndex(Node* node) { |
| 69 return PastContextIndex(node); |
| 70 } |
| 71 |
| 72 inline int NodeProperties::FirstControlIndex(Node* node) { |
| 73 return PastEffectIndex(node); |
| 74 } |
| 75 |
| 76 |
| 77 inline int NodeProperties::PastValueIndex(Node* node) { |
| 78 return FirstValueIndex(node) + GetValueInputCount(node); |
| 79 } |
| 80 |
| 81 inline int NodeProperties::PastContextIndex(Node* node) { |
| 82 return FirstContextIndex(node) + GetContextInputCount(node); |
| 83 } |
| 84 |
| 85 inline int NodeProperties::PastEffectIndex(Node* node) { |
| 86 return FirstEffectIndex(node) + GetEffectInputCount(node); |
| 87 } |
| 88 |
| 89 inline int NodeProperties::PastControlIndex(Node* node) { |
| 90 return FirstControlIndex(node) + GetControlInputCount(node); |
| 91 } |
| 92 |
| 93 |
| 94 // ----------------------------------------------------------------------------- |
| 95 // Input accessors. |
| 96 |
| 97 inline Node* NodeProperties::GetValueInput(Node* node, int index) { |
| 98 ASSERT(0 <= index && index < GetValueInputCount(node)); |
| 99 return node->InputAt(FirstValueIndex(node) + index); |
| 100 } |
| 101 |
| 102 inline Node* NodeProperties::GetContextInput(Node* node) { |
| 103 ASSERT(GetContextInputCount(node) > 0); |
| 104 return node->InputAt(FirstContextIndex(node)); |
| 105 } |
| 106 |
| 107 inline Node* NodeProperties::GetEffectInput(Node* node, int index) { |
| 108 ASSERT(0 <= index && index < GetEffectInputCount(node)); |
| 109 return node->InputAt(FirstEffectIndex(node) + index); |
| 110 } |
| 111 |
| 112 inline Node* NodeProperties::GetControlInput(Node* node, int index) { |
| 113 ASSERT(0 <= index && index < GetControlInputCount(node)); |
| 114 return node->InputAt(FirstControlIndex(node) + index); |
| 115 } |
| 116 |
| 117 |
| 118 // ----------------------------------------------------------------------------- |
| 119 // Output counts. |
| 120 |
| 121 inline bool NodeProperties::HasValueOutput(Node* node) { |
| 122 return GetValueOutputCount(node) > 0; |
| 123 } |
| 124 |
| 125 inline bool NodeProperties::HasEffectOutput(Node* node) { |
| 126 return node->opcode() == IrOpcode::kStart || |
| 127 NodeProperties::GetEffectInputCount(node) > 0; |
| 128 } |
| 129 |
| 130 inline bool NodeProperties::HasControlOutput(Node* node) { |
| 131 return (node->opcode() != IrOpcode::kEnd && IsControl(node)) || |
| 132 NodeProperties::CanLazilyDeoptimize(node); |
| 133 } |
| 134 |
| 135 |
| 136 inline int NodeProperties::GetValueOutputCount(Node* node) { |
| 137 return OperatorProperties::GetValueOutputCount(node->op()); |
| 138 } |
| 139 |
| 140 inline int NodeProperties::GetEffectOutputCount(Node* node) { |
| 141 return HasEffectOutput(node) ? 1 : 0; |
| 142 } |
| 143 |
| 144 inline int NodeProperties::GetControlOutputCount(Node* node) { |
| 145 return node->opcode() == IrOpcode::kBranch ? 2 : |
| 146 HasControlOutput(node) ? 1 : 0; |
| 147 } |
| 148 |
| 149 |
| 150 // ----------------------------------------------------------------------------- |
| 151 // Edge kinds. |
| 152 |
| 153 inline bool NodeProperties::IsInputRange(Node::Edge edge, int first, int num) { |
| 154 // TODO(titzer): edge.index() is linear time; |
| 155 // edges maybe need to be marked as value/effect/control. |
| 156 if (num == 0) return false; |
| 157 int index = edge.index(); |
| 158 return first <= index && index < first + num; |
| 159 } |
| 160 |
| 161 inline bool NodeProperties::IsValueEdge(Node::Edge edge) { |
| 162 Node* node = edge.from(); |
| 163 return IsInputRange(edge, FirstValueIndex(node), GetValueInputCount(node)); |
| 164 } |
| 165 |
| 166 inline bool NodeProperties::IsContextEdge(Node::Edge edge) { |
| 167 Node* node = edge.from(); |
| 168 return IsInputRange( |
| 169 edge, FirstContextIndex(node), GetContextInputCount(node)); |
| 170 } |
| 171 |
| 172 inline bool NodeProperties::IsEffectEdge(Node::Edge edge) { |
| 173 Node* node = edge.from(); |
| 174 return IsInputRange(edge, FirstEffectIndex(node), GetEffectInputCount(node)); |
| 175 } |
| 176 |
| 177 inline bool NodeProperties::IsControlEdge(Node::Edge edge) { |
| 178 Node* node = edge.from(); |
| 179 return IsInputRange( |
| 180 edge, FirstControlIndex(node), GetControlInputCount(node)); |
| 181 } |
| 182 |
| 183 |
| 184 // ----------------------------------------------------------------------------- |
| 185 // Miscellaneous predicates. |
| 186 |
| 187 inline bool NodeProperties::IsControl(Node* node) { |
| 188 return IrOpcode::IsControlOpcode(node->opcode()); |
| 189 } |
| 190 |
| 191 inline bool NodeProperties::IsBasicBlockBegin(Node* node) { |
| 192 return OperatorProperties::IsBasicBlockBegin(node->op()); |
| 193 } |
| 194 |
| 195 inline bool NodeProperties::CanBeScheduled(Node* node) { |
| 196 return OperatorProperties::CanBeScheduled(node->op()); |
| 197 } |
| 198 |
| 199 inline bool NodeProperties::HasFixedSchedulePosition(Node* node) { |
| 200 return OperatorProperties::HasFixedSchedulePosition(node->op()); |
| 201 } |
| 202 |
| 203 inline bool NodeProperties::IsScheduleRoot(Node* node) { |
| 204 return OperatorProperties::IsScheduleRoot(node->op()); |
| 205 } |
| 206 |
| 207 |
| 208 // ----------------------------------------------------------------------------- |
| 209 // Miscellaneous mutators. |
| 210 |
| 211 inline void NodeProperties::ReplaceEffectInput( |
| 212 Node* node, Node* effect, int index) { |
| 213 ASSERT(index < GetEffectInputCount(node)); |
| 214 return node->ReplaceInput(GetValueInputCount(node) + |
| 215 GetContextInputCount(node) + |
| 216 index, effect); |
| 217 } |
| 218 |
| 219 inline void NodeProperties::RemoveNonValueInputs(Node* node) { |
| 220 node->TrimInputCount(GetValueInputCount(node)); |
| 221 } |
| 222 |
| 223 |
| 224 // ----------------------------------------------------------------------------- |
| 225 // Type Bounds. |
| 226 |
| 227 inline Bounds NodeProperties::GetBounds(Node* node) { |
| 228 return node->bounds(); |
| 229 } |
| 230 |
| 231 inline void NodeProperties::SetBounds(Node* node, Bounds b) { |
| 232 node->set_bounds(b); |
| 233 } |
| 234 |
| 235 |
| 236 inline bool NodeProperties::CanLazilyDeoptimize(Node* node) { |
| 237 return OperatorProperties::CanLazilyDeoptimize(node->op()); |
| 238 } |
| 239 } } } // namespace v8::internal::compiler |
| 240 |
| 241 #endif // V8_COMPILER_NODE_PROPERTIES_INL_H_ |
| OLD | NEW |