OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-intrinsic-lowering.h" | 5 #include "src/compiler/js-intrinsic-lowering.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 case Runtime::kInlineIsArray: | 43 case Runtime::kInlineIsArray: |
44 return ReduceIsInstanceType(node, JS_ARRAY_TYPE); | 44 return ReduceIsInstanceType(node, JS_ARRAY_TYPE); |
45 case Runtime::kInlineIsTypedArray: | 45 case Runtime::kInlineIsTypedArray: |
46 return ReduceIsInstanceType(node, JS_TYPED_ARRAY_TYPE); | 46 return ReduceIsInstanceType(node, JS_TYPED_ARRAY_TYPE); |
47 case Runtime::kInlineIsRegExp: | 47 case Runtime::kInlineIsRegExp: |
48 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); | 48 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); |
49 case Runtime::kInlineIsJSReceiver: | 49 case Runtime::kInlineIsJSReceiver: |
50 return ReduceIsJSReceiver(node); | 50 return ReduceIsJSReceiver(node); |
51 case Runtime::kInlineIsSmi: | 51 case Runtime::kInlineIsSmi: |
52 return ReduceIsSmi(node); | 52 return ReduceIsSmi(node); |
| 53 case Runtime::kInlineValueOf: |
| 54 return ReduceValueOf(node); |
53 case Runtime::kInlineFixedArrayGet: | 55 case Runtime::kInlineFixedArrayGet: |
54 return ReduceFixedArrayGet(node); | 56 return ReduceFixedArrayGet(node); |
55 case Runtime::kInlineFixedArraySet: | 57 case Runtime::kInlineFixedArraySet: |
56 return ReduceFixedArraySet(node); | 58 return ReduceFixedArraySet(node); |
57 case Runtime::kInlineRegExpConstructResult: | 59 case Runtime::kInlineRegExpConstructResult: |
58 return ReduceRegExpConstructResult(node); | 60 return ReduceRegExpConstructResult(node); |
59 case Runtime::kInlineRegExpExec: | 61 case Runtime::kInlineRegExpExec: |
60 return ReduceRegExpExec(node); | 62 return ReduceRegExpExec(node); |
61 case Runtime::kInlineRegExpFlags: | 63 case Runtime::kInlineRegExpFlags: |
62 return ReduceRegExpFlags(node); | 64 return ReduceRegExpFlags(node); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { | 197 Reduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) { |
196 return Change(node, simplified()->ObjectIsReceiver()); | 198 return Change(node, simplified()->ObjectIsReceiver()); |
197 } | 199 } |
198 | 200 |
199 | 201 |
200 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { | 202 Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { |
201 return Change(node, simplified()->ObjectIsSmi()); | 203 return Change(node, simplified()->ObjectIsSmi()); |
202 } | 204 } |
203 | 205 |
204 | 206 |
| 207 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { |
| 208 // if (%_IsSmi(value)) { |
| 209 // return value; |
| 210 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { |
| 211 // return %_GetValue(value); |
| 212 // } else { |
| 213 // return value; |
| 214 // } |
| 215 const Operator* const merge_op = common()->Merge(2); |
| 216 const Operator* const ephi_op = common()->EffectPhi(2); |
| 217 const Operator* const phi_op = |
| 218 common()->Phi(MachineRepresentation::kTagged, 2); |
| 219 |
| 220 Node* value = NodeProperties::GetValueInput(node, 0); |
| 221 Node* effect = NodeProperties::GetEffectInput(node); |
| 222 Node* control = NodeProperties::GetControlInput(node); |
| 223 |
| 224 Node* check0 = graph()->NewNode(simplified()->ObjectIsSmi(), value); |
| 225 Node* branch0 = graph()->NewNode(common()->Branch(), check0, control); |
| 226 |
| 227 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); |
| 228 Node* etrue0 = effect; |
| 229 Node* vtrue0 = value; |
| 230 |
| 231 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); |
| 232 Node* efalse0; |
| 233 Node* vfalse0; |
| 234 { |
| 235 Node* check1 = graph()->NewNode( |
| 236 machine()->Word32Equal(), |
| 237 graph()->NewNode( |
| 238 simplified()->LoadField(AccessBuilder::ForMapInstanceType()), |
| 239 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), |
| 240 value, effect, if_false0), |
| 241 effect, if_false0), |
| 242 jsgraph()->Int32Constant(JS_VALUE_TYPE)); |
| 243 Node* branch1 = graph()->NewNode(common()->Branch(), check1, if_false0); |
| 244 |
| 245 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
| 246 Node* etrue1 = |
| 247 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForValue()), |
| 248 value, effect, if_true1); |
| 249 Node* vtrue1 = etrue1; |
| 250 |
| 251 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
| 252 Node* efalse1 = effect; |
| 253 Node* vfalse1 = value; |
| 254 |
| 255 Node* merge1 = graph()->NewNode(merge_op, if_true1, if_false1); |
| 256 efalse0 = graph()->NewNode(ephi_op, etrue1, efalse1, merge1); |
| 257 vfalse0 = graph()->NewNode(phi_op, vtrue1, vfalse1, merge1); |
| 258 } |
| 259 |
| 260 Node* merge0 = graph()->NewNode(merge_op, if_true0, if_false0); |
| 261 |
| 262 // Replace all effect uses of {node} with the {ephi0}. |
| 263 Node* ephi0 = graph()->NewNode(ephi_op, etrue0, efalse0, merge0); |
| 264 ReplaceWithValue(node, node, ephi0); |
| 265 |
| 266 // Turn the {node} into a Phi. |
| 267 return Change(node, phi_op, vtrue0, vfalse0, merge0); |
| 268 } |
| 269 |
| 270 |
205 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) { | 271 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) { |
206 // Replace all effect uses of {node} with the effect dependency. | 272 // Replace all effect uses of {node} with the effect dependency. |
207 RelaxEffectsAndControls(node); | 273 RelaxEffectsAndControls(node); |
208 // Remove the inputs corresponding to context, effect and control. | 274 // Remove the inputs corresponding to context, effect and control. |
209 NodeProperties::RemoveNonValueInputs(node); | 275 NodeProperties::RemoveNonValueInputs(node); |
210 // Finally update the operator to the new one. | 276 // Finally update the operator to the new one. |
211 NodeProperties::ChangeOp(node, op); | 277 NodeProperties::ChangeOp(node, op); |
212 return Changed(node); | 278 return Changed(node); |
213 } | 279 } |
214 | 280 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 479 } |
414 | 480 |
415 | 481 |
416 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 482 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { |
417 return jsgraph()->simplified(); | 483 return jsgraph()->simplified(); |
418 } | 484 } |
419 | 485 |
420 } // namespace compiler | 486 } // namespace compiler |
421 } // namespace internal | 487 } // namespace internal |
422 } // namespace v8 | 488 } // namespace v8 |
OLD | NEW |