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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 case Runtime::kInlineJSValueGetValue: | 66 case Runtime::kInlineJSValueGetValue: |
67 return ReduceJSValueGetValue(node); | 67 return ReduceJSValueGetValue(node); |
68 case Runtime::kInlineMapGetInstanceType: | 68 case Runtime::kInlineMapGetInstanceType: |
69 return ReduceMapGetInstanceType(node); | 69 return ReduceMapGetInstanceType(node); |
70 case Runtime::kInlineMathClz32: | 70 case Runtime::kInlineMathClz32: |
71 return ReduceMathClz32(node); | 71 return ReduceMathClz32(node); |
72 case Runtime::kInlineMathFloor: | 72 case Runtime::kInlineMathFloor: |
73 return ReduceMathFloor(node); | 73 return ReduceMathFloor(node); |
74 case Runtime::kInlineMathSqrt: | 74 case Runtime::kInlineMathSqrt: |
75 return ReduceMathSqrt(node); | 75 return ReduceMathSqrt(node); |
76 case Runtime::kInlineStringGetLength: | |
77 return ReduceStringGetLength(node); | |
78 case Runtime::kInlineValueOf: | 76 case Runtime::kInlineValueOf: |
79 return ReduceValueOf(node); | 77 return ReduceValueOf(node); |
80 case Runtime::kInlineIsMinusZero: | 78 case Runtime::kInlineIsMinusZero: |
81 return ReduceIsMinusZero(node); | 79 return ReduceIsMinusZero(node); |
82 case Runtime::kInlineFixedArrayGet: | 80 case Runtime::kInlineFixedArrayGet: |
83 return ReduceFixedArrayGet(node); | 81 return ReduceFixedArrayGet(node); |
84 case Runtime::kInlineFixedArraySet: | 82 case Runtime::kInlineFixedArraySet: |
85 return ReduceFixedArraySet(node); | 83 return ReduceFixedArraySet(node); |
| 84 case Runtime::kInlineRegExpConstructResult: |
| 85 return ReduceRegExpConstructResult(node); |
| 86 case Runtime::kInlineRegExpExec: |
| 87 return ReduceRegExpExec(node); |
| 88 case Runtime::kInlineRegExpFlags: |
| 89 return ReduceRegExpFlags(node); |
| 90 case Runtime::kInlineRegExpSource: |
| 91 return ReduceRegExpSource(node); |
| 92 case Runtime::kInlineSubString: |
| 93 return ReduceSubString(node); |
86 case Runtime::kInlineToInteger: | 94 case Runtime::kInlineToInteger: |
87 return ReduceToInteger(node); | 95 return ReduceToInteger(node); |
88 case Runtime::kInlineToLength: | 96 case Runtime::kInlineToLength: |
89 return ReduceToLength(node); | 97 return ReduceToLength(node); |
90 case Runtime::kInlineToName: | 98 case Runtime::kInlineToName: |
91 return ReduceToName(node); | 99 return ReduceToName(node); |
92 case Runtime::kInlineToNumber: | 100 case Runtime::kInlineToNumber: |
93 return ReduceToNumber(node); | 101 return ReduceToNumber(node); |
94 case Runtime::kInlineToObject: | 102 case Runtime::kInlineToObject: |
95 return ReduceToObject(node); | 103 return ReduceToObject(node); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 if (!machine()->Float64RoundDown().IsSupported()) return NoChange(); | 327 if (!machine()->Float64RoundDown().IsSupported()) return NoChange(); |
320 return Change(node, machine()->Float64RoundDown().op()); | 328 return Change(node, machine()->Float64RoundDown().op()); |
321 } | 329 } |
322 | 330 |
323 | 331 |
324 Reduction JSIntrinsicLowering::ReduceMathSqrt(Node* node) { | 332 Reduction JSIntrinsicLowering::ReduceMathSqrt(Node* node) { |
325 return Change(node, machine()->Float64Sqrt()); | 333 return Change(node, machine()->Float64Sqrt()); |
326 } | 334 } |
327 | 335 |
328 | 336 |
329 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { | |
330 Node* value = NodeProperties::GetValueInput(node, 0); | |
331 Node* effect = NodeProperties::GetEffectInput(node); | |
332 Node* control = NodeProperties::GetControlInput(node); | |
333 return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), | |
334 value, effect, control); | |
335 } | |
336 | |
337 | |
338 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { | 337 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { |
339 // if (%_IsSmi(value)) { | 338 // if (%_IsSmi(value)) { |
340 // return value; | 339 // return value; |
341 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { | 340 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { |
342 // return %_GetValue(value); | 341 // return %_GetValue(value); |
343 // } else { | 342 // } else { |
344 // return value; | 343 // return value; |
345 // } | 344 // } |
346 const Operator* const merge_op = common()->Merge(2); | 345 const Operator* const merge_op = common()->Merge(2); |
347 const Operator* const ephi_op = common()->EffectPhi(2); | 346 const Operator* const ephi_op = common()->EffectPhi(2); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 Node* effect = NodeProperties::GetEffectInput(node); | 451 Node* effect = NodeProperties::GetEffectInput(node); |
453 Node* control = NodeProperties::GetControlInput(node); | 452 Node* control = NodeProperties::GetControlInput(node); |
454 Node* store = (graph()->NewNode( | 453 Node* store = (graph()->NewNode( |
455 simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), base, | 454 simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), base, |
456 index, value, effect, control)); | 455 index, value, effect, control)); |
457 ReplaceWithValue(node, value, store); | 456 ReplaceWithValue(node, value, store); |
458 return Changed(store); | 457 return Changed(store); |
459 } | 458 } |
460 | 459 |
461 | 460 |
| 461 Reduction JSIntrinsicLowering::ReduceRegExpConstructResult(Node* node) { |
| 462 // TODO(bmeurer): Introduce JSCreateRegExpResult? |
| 463 return Change(node, CodeFactory::RegExpConstructResult(isolate()), 0); |
| 464 } |
| 465 |
| 466 |
| 467 Reduction JSIntrinsicLowering::ReduceRegExpExec(Node* node) { |
| 468 return Change(node, CodeFactory::RegExpExec(isolate()), 4); |
| 469 } |
| 470 |
| 471 |
| 472 Reduction JSIntrinsicLowering::ReduceRegExpFlags(Node* node) { |
| 473 Node* const receiver = NodeProperties::GetValueInput(node, 0); |
| 474 Node* const effect = NodeProperties::GetEffectInput(node); |
| 475 Node* const control = NodeProperties::GetControlInput(node); |
| 476 Operator const* const op = |
| 477 simplified()->LoadField(AccessBuilder::ForJSRegExpFlags()); |
| 478 return Change(node, op, receiver, effect, control); |
| 479 } |
| 480 |
| 481 |
| 482 Reduction JSIntrinsicLowering::ReduceRegExpSource(Node* node) { |
| 483 Node* const receiver = NodeProperties::GetValueInput(node, 0); |
| 484 Node* const effect = NodeProperties::GetEffectInput(node); |
| 485 Node* const control = NodeProperties::GetControlInput(node); |
| 486 Operator const* const op = |
| 487 simplified()->LoadField(AccessBuilder::ForJSRegExpSource()); |
| 488 return Change(node, op, receiver, effect, control); |
| 489 } |
| 490 |
| 491 |
| 492 Reduction JSIntrinsicLowering::ReduceSubString(Node* node) { |
| 493 return Change(node, CodeFactory::SubString(isolate()), 3); |
| 494 } |
| 495 |
| 496 |
462 Reduction JSIntrinsicLowering::ReduceThrowNotDateError(Node* node) { | 497 Reduction JSIntrinsicLowering::ReduceThrowNotDateError(Node* node) { |
463 if (mode() != kDeoptimizationEnabled) return NoChange(); | 498 if (mode() != kDeoptimizationEnabled) return NoChange(); |
464 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 1); | 499 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 1); |
465 Node* const effect = NodeProperties::GetEffectInput(node); | 500 Node* const effect = NodeProperties::GetEffectInput(node); |
466 Node* const control = NodeProperties::GetControlInput(node); | 501 Node* const control = NodeProperties::GetControlInput(node); |
467 | 502 |
468 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer. | 503 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer. |
469 Node* deoptimize = | 504 Node* deoptimize = |
470 graph()->NewNode(common()->Deoptimize(DeoptimizeKind::kEager), | 505 graph()->NewNode(common()->Deoptimize(DeoptimizeKind::kEager), |
471 frame_state, effect, control); | 506 frame_state, effect, control); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 jsgraph()->Constant(kMaxSafeInteger), value), | 560 jsgraph()->Constant(kMaxSafeInteger), value), |
526 jsgraph()->Constant(kMaxSafeInteger), value); | 561 jsgraph()->Constant(kMaxSafeInteger), value); |
527 value_type = | 562 value_type = |
528 Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone()); | 563 Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone()); |
529 NodeProperties::SetType(value, value_type); | 564 NodeProperties::SetType(value, value_type); |
530 } | 565 } |
531 } | 566 } |
532 ReplaceWithValue(node, value); | 567 ReplaceWithValue(node, value); |
533 return Replace(value); | 568 return Replace(value); |
534 } | 569 } |
535 Callable callable = CodeFactory::ToLength(isolate()); | 570 return Change(node, CodeFactory::ToLength(isolate()), 0); |
536 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( | |
537 isolate(), graph()->zone(), callable.descriptor(), 0, | |
538 CallDescriptor::kNeedsFrameState, node->op()->properties()); | |
539 node->InsertInput(graph()->zone(), 0, | |
540 jsgraph()->HeapConstant(callable.code())); | |
541 NodeProperties::ChangeOp(node, common()->Call(desc)); | |
542 return Changed(node); | |
543 } | 571 } |
544 | 572 |
545 | 573 |
546 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) { | 574 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) { |
547 NodeProperties::ChangeOp(node, javascript()->ToObject()); | 575 NodeProperties::ChangeOp(node, javascript()->ToObject()); |
548 return Changed(node); | 576 return Changed(node); |
549 } | 577 } |
550 | 578 |
551 | 579 |
552 Reduction JSIntrinsicLowering::ReduceToPrimitive(Node* node) { | 580 Reduction JSIntrinsicLowering::ReduceToPrimitive(Node* node) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return Changed(node); | 649 return Changed(node); |
622 } | 650 } |
623 | 651 |
624 | 652 |
625 Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { | 653 Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { |
626 ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect); | 654 ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect); |
627 return Changed(node); | 655 return Changed(node); |
628 } | 656 } |
629 | 657 |
630 | 658 |
| 659 Reduction JSIntrinsicLowering::Change(Node* node, Callable const& callable, |
| 660 int stack_parameter_count) { |
| 661 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( |
| 662 isolate(), graph()->zone(), callable.descriptor(), stack_parameter_count, |
| 663 CallDescriptor::kNeedsFrameState, node->op()->properties()); |
| 664 node->InsertInput(graph()->zone(), 0, |
| 665 jsgraph()->HeapConstant(callable.code())); |
| 666 NodeProperties::ChangeOp(node, common()->Call(desc)); |
| 667 return Changed(node); |
| 668 } |
| 669 |
| 670 |
631 Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); } | 671 Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); } |
632 | 672 |
633 | 673 |
634 Isolate* JSIntrinsicLowering::isolate() const { return jsgraph()->isolate(); } | 674 Isolate* JSIntrinsicLowering::isolate() const { return jsgraph()->isolate(); } |
635 | 675 |
636 | 676 |
637 CommonOperatorBuilder* JSIntrinsicLowering::common() const { | 677 CommonOperatorBuilder* JSIntrinsicLowering::common() const { |
638 return jsgraph()->common(); | 678 return jsgraph()->common(); |
639 } | 679 } |
640 | 680 |
641 JSOperatorBuilder* JSIntrinsicLowering::javascript() const { | 681 JSOperatorBuilder* JSIntrinsicLowering::javascript() const { |
642 return jsgraph_->javascript(); | 682 return jsgraph_->javascript(); |
643 } | 683 } |
644 | 684 |
645 | 685 |
646 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 686 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
647 return jsgraph()->machine(); | 687 return jsgraph()->machine(); |
648 } | 688 } |
649 | 689 |
650 | 690 |
651 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 691 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { |
652 return jsgraph()->simplified(); | 692 return jsgraph()->simplified(); |
653 } | 693 } |
654 | 694 |
655 } // namespace compiler | 695 } // namespace compiler |
656 } // namespace internal | 696 } // namespace internal |
657 } // namespace v8 | 697 } // namespace v8 |
OLD | NEW |