OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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-operator.h" | 5 #include "src/compiler/js-operator.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/lazy-instance.h" | 9 #include "src/base/lazy-instance.h" |
10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 case TailCallMode::kAllow: | 56 case TailCallMode::kAllow: |
57 return os << "ALLOW_TAIL_CALLS"; | 57 return os << "ALLOW_TAIL_CALLS"; |
58 case TailCallMode::kDisallow: | 58 case TailCallMode::kDisallow: |
59 return os << "DISALLOW_TAIL_CALLS"; | 59 return os << "DISALLOW_TAIL_CALLS"; |
60 } | 60 } |
61 UNREACHABLE(); | 61 UNREACHABLE(); |
62 return os; | 62 return os; |
63 } | 63 } |
64 | 64 |
65 | 65 |
| 66 bool operator==(BinaryOperationParameters const& lhs, |
| 67 BinaryOperationParameters const& rhs) { |
| 68 return lhs.language_mode() == rhs.language_mode() && |
| 69 lhs.hints() == rhs.hints(); |
| 70 } |
| 71 |
| 72 |
| 73 bool operator!=(BinaryOperationParameters const& lhs, |
| 74 BinaryOperationParameters const& rhs) { |
| 75 return !(lhs == rhs); |
| 76 } |
| 77 |
| 78 |
| 79 size_t hash_value(BinaryOperationParameters const& p) { |
| 80 return base::hash_combine(p.language_mode(), p.hints()); |
| 81 } |
| 82 |
| 83 |
| 84 std::ostream& operator<<(std::ostream& os, BinaryOperationParameters const& p) { |
| 85 return os << p.language_mode() << ", " << p.hints(); |
| 86 } |
| 87 |
| 88 |
| 89 BinaryOperationParameters const& BinaryOperationParametersOf( |
| 90 Operator const* op) { |
| 91 DCHECK(op->opcode() == IrOpcode::kJSBitwiseOr || |
| 92 op->opcode() == IrOpcode::kJSBitwiseXor || |
| 93 op->opcode() == IrOpcode::kJSBitwiseAnd || |
| 94 op->opcode() == IrOpcode::kJSShiftLeft || |
| 95 op->opcode() == IrOpcode::kJSShiftRight || |
| 96 op->opcode() == IrOpcode::kJSShiftRightLogical || |
| 97 op->opcode() == IrOpcode::kJSAdd || |
| 98 op->opcode() == IrOpcode::kJSSubtract || |
| 99 op->opcode() == IrOpcode::kJSMultiply || |
| 100 op->opcode() == IrOpcode::kJSDivide || |
| 101 op->opcode() == IrOpcode::kJSModulus); |
| 102 return OpParameter<BinaryOperationParameters>(op); |
| 103 } |
| 104 |
| 105 |
66 bool operator==(CallConstructParameters const& lhs, | 106 bool operator==(CallConstructParameters const& lhs, |
67 CallConstructParameters const& rhs) { | 107 CallConstructParameters const& rhs) { |
68 return lhs.arity() == rhs.arity() && lhs.feedback() == rhs.feedback(); | 108 return lhs.arity() == rhs.arity() && lhs.feedback() == rhs.feedback(); |
69 } | 109 } |
70 | 110 |
71 | 111 |
72 bool operator!=(CallConstructParameters const& lhs, | 112 bool operator!=(CallConstructParameters const& lhs, |
73 CallConstructParameters const& rhs) { | 113 CallConstructParameters const& rhs) { |
74 return !(lhs == rhs); | 114 return !(lhs == rhs); |
75 } | 115 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 V(ForInNext, Operator::kNoProperties, 4, 1) \ | 501 V(ForInNext, Operator::kNoProperties, 4, 1) \ |
462 V(ForInPrepare, Operator::kNoProperties, 1, 3) \ | 502 V(ForInPrepare, Operator::kNoProperties, 1, 3) \ |
463 V(ForInStep, Operator::kPure, 1, 1) \ | 503 V(ForInStep, Operator::kPure, 1, 1) \ |
464 V(LoadMessage, Operator::kNoThrow, 0, 1) \ | 504 V(LoadMessage, Operator::kNoThrow, 0, 1) \ |
465 V(StoreMessage, Operator::kNoThrow, 1, 0) \ | 505 V(StoreMessage, Operator::kNoThrow, 1, 0) \ |
466 V(StackCheck, Operator::kNoProperties, 0, 0) \ | 506 V(StackCheck, Operator::kNoProperties, 0, 0) \ |
467 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ | 507 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ |
468 V(CreateModuleContext, Operator::kNoProperties, 2, 1) | 508 V(CreateModuleContext, Operator::kNoProperties, 2, 1) |
469 | 509 |
470 | 510 |
471 #define CACHED_OP_LIST_WITH_LANGUAGE_MODE(V) \ | 511 #define CACHED_OP_LIST_WITH_LANGUAGE_MODE(V) \ |
472 V(LessThan, Operator::kNoProperties, 2, 1) \ | 512 V(LessThan, Operator::kNoProperties, 2, 1) \ |
473 V(GreaterThan, Operator::kNoProperties, 2, 1) \ | 513 V(GreaterThan, Operator::kNoProperties, 2, 1) \ |
474 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \ | 514 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
475 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \ | 515 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) |
476 V(BitwiseOr, Operator::kNoProperties, 2, 1) \ | |
477 V(BitwiseXor, Operator::kNoProperties, 2, 1) \ | |
478 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \ | |
479 V(ShiftLeft, Operator::kNoProperties, 2, 1) \ | |
480 V(ShiftRight, Operator::kNoProperties, 2, 1) \ | |
481 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \ | |
482 V(Add, Operator::kNoProperties, 2, 1) \ | |
483 V(Subtract, Operator::kNoProperties, 2, 1) \ | |
484 V(Multiply, Operator::kNoProperties, 2, 1) \ | |
485 V(Divide, Operator::kNoProperties, 2, 1) \ | |
486 V(Modulus, Operator::kNoProperties, 2, 1) | |
487 | 516 |
488 | 517 |
489 struct JSOperatorGlobalCache final { | 518 struct JSOperatorGlobalCache final { |
490 #define CACHED(Name, properties, value_input_count, value_output_count) \ | 519 #define CACHED(Name, properties, value_input_count, value_output_count) \ |
491 struct Name##Operator final : public Operator { \ | 520 struct Name##Operator final : public Operator { \ |
492 Name##Operator() \ | 521 Name##Operator() \ |
493 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \ | 522 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \ |
494 value_input_count, Operator::ZeroIfPure(properties), \ | 523 value_input_count, Operator::ZeroIfPure(properties), \ |
495 Operator::ZeroIfEliminatable(properties), \ | 524 Operator::ZeroIfEliminatable(properties), \ |
496 value_output_count, Operator::ZeroIfPure(properties), \ | 525 value_output_count, Operator::ZeroIfPure(properties), \ |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 default: \ | 579 default: \ |
551 break; /* %*!%^$#@ */ \ | 580 break; /* %*!%^$#@ */ \ |
552 } \ | 581 } \ |
553 UNREACHABLE(); \ | 582 UNREACHABLE(); \ |
554 return nullptr; \ | 583 return nullptr; \ |
555 } | 584 } |
556 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_LANGUAGE_MODE) | 585 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_LANGUAGE_MODE) |
557 #undef CACHED_WITH_LANGUAGE_MODE | 586 #undef CACHED_WITH_LANGUAGE_MODE |
558 | 587 |
559 | 588 |
| 589 const Operator* JSOperatorBuilder::BitwiseOr(LanguageMode language_mode, |
| 590 BinaryOperationHints hints) { |
| 591 // TODO(turbofan): Cache most important versions of this operator. |
| 592 BinaryOperationParameters parameters(language_mode, hints); |
| 593 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 594 IrOpcode::kJSBitwiseOr, Operator::kNoProperties, // opcode |
| 595 "JSBitwiseOr", // name |
| 596 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 597 parameters); // parameter |
| 598 } |
| 599 |
| 600 |
| 601 const Operator* JSOperatorBuilder::BitwiseXor(LanguageMode language_mode, |
| 602 BinaryOperationHints hints) { |
| 603 // TODO(turbofan): Cache most important versions of this operator. |
| 604 BinaryOperationParameters parameters(language_mode, hints); |
| 605 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 606 IrOpcode::kJSBitwiseXor, Operator::kNoProperties, // opcode |
| 607 "JSBitwiseXor", // name |
| 608 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 609 parameters); // parameter |
| 610 } |
| 611 |
| 612 |
| 613 const Operator* JSOperatorBuilder::BitwiseAnd(LanguageMode language_mode, |
| 614 BinaryOperationHints hints) { |
| 615 // TODO(turbofan): Cache most important versions of this operator. |
| 616 BinaryOperationParameters parameters(language_mode, hints); |
| 617 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 618 IrOpcode::kJSBitwiseAnd, Operator::kNoProperties, // opcode |
| 619 "JSBitwiseAnd", // name |
| 620 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 621 parameters); // parameter |
| 622 } |
| 623 |
| 624 |
| 625 const Operator* JSOperatorBuilder::ShiftLeft(LanguageMode language_mode, |
| 626 BinaryOperationHints hints) { |
| 627 // TODO(turbofan): Cache most important versions of this operator. |
| 628 BinaryOperationParameters parameters(language_mode, hints); |
| 629 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 630 IrOpcode::kJSShiftLeft, Operator::kNoProperties, // opcode |
| 631 "JSShiftLeft", // name |
| 632 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 633 parameters); // parameter |
| 634 } |
| 635 |
| 636 |
| 637 const Operator* JSOperatorBuilder::ShiftRight(LanguageMode language_mode, |
| 638 BinaryOperationHints hints) { |
| 639 // TODO(turbofan): Cache most important versions of this operator. |
| 640 BinaryOperationParameters parameters(language_mode, hints); |
| 641 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 642 IrOpcode::kJSShiftRight, Operator::kNoProperties, // opcode |
| 643 "JSShiftRight", // name |
| 644 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 645 parameters); // parameter |
| 646 } |
| 647 |
| 648 |
| 649 const Operator* JSOperatorBuilder::ShiftRightLogical( |
| 650 LanguageMode language_mode, BinaryOperationHints hints) { |
| 651 // TODO(turbofan): Cache most important versions of this operator. |
| 652 BinaryOperationParameters parameters(language_mode, hints); |
| 653 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 654 IrOpcode::kJSShiftRightLogical, Operator::kNoProperties, // opcode |
| 655 "JSShiftRightLogical", // name |
| 656 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 657 parameters); // parameter |
| 658 } |
| 659 |
| 660 |
| 661 const Operator* JSOperatorBuilder::Add(LanguageMode language_mode, |
| 662 BinaryOperationHints hints) { |
| 663 // TODO(turbofan): Cache most important versions of this operator. |
| 664 BinaryOperationParameters parameters(language_mode, hints); |
| 665 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 666 IrOpcode::kJSAdd, Operator::kNoProperties, // opcode |
| 667 "JSAdd", // name |
| 668 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 669 parameters); // parameter |
| 670 } |
| 671 |
| 672 |
| 673 const Operator* JSOperatorBuilder::Subtract(LanguageMode language_mode, |
| 674 BinaryOperationHints hints) { |
| 675 // TODO(turbofan): Cache most important versions of this operator. |
| 676 BinaryOperationParameters parameters(language_mode, hints); |
| 677 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 678 IrOpcode::kJSSubtract, Operator::kNoProperties, // opcode |
| 679 "JSSubtract", // name |
| 680 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 681 parameters); // parameter |
| 682 } |
| 683 |
| 684 |
| 685 const Operator* JSOperatorBuilder::Multiply(LanguageMode language_mode, |
| 686 BinaryOperationHints hints) { |
| 687 // TODO(turbofan): Cache most important versions of this operator. |
| 688 BinaryOperationParameters parameters(language_mode, hints); |
| 689 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 690 IrOpcode::kJSMultiply, Operator::kNoProperties, // opcode |
| 691 "JSMultiply", // name |
| 692 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 693 parameters); // parameter |
| 694 } |
| 695 |
| 696 |
| 697 const Operator* JSOperatorBuilder::Divide(LanguageMode language_mode, |
| 698 BinaryOperationHints hints) { |
| 699 // TODO(turbofan): Cache most important versions of this operator. |
| 700 BinaryOperationParameters parameters(language_mode, hints); |
| 701 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 702 IrOpcode::kJSDivide, Operator::kNoProperties, // opcode |
| 703 "JSDivide", // name |
| 704 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 705 parameters); // parameter |
| 706 } |
| 707 |
| 708 |
| 709 const Operator* JSOperatorBuilder::Modulus(LanguageMode language_mode, |
| 710 BinaryOperationHints hints) { |
| 711 // TODO(turbofan): Cache most important versions of this operator. |
| 712 BinaryOperationParameters parameters(language_mode, hints); |
| 713 return new (zone()) Operator1<BinaryOperationParameters>( //-- |
| 714 IrOpcode::kJSModulus, Operator::kNoProperties, // opcode |
| 715 "JSModulus", // name |
| 716 2, 1, 1, 1, 1, 2, // inputs/outputs |
| 717 parameters); // parameter |
| 718 } |
| 719 |
| 720 |
560 const Operator* JSOperatorBuilder::CallFunction( | 721 const Operator* JSOperatorBuilder::CallFunction( |
561 size_t arity, LanguageMode language_mode, VectorSlotPair const& feedback, | 722 size_t arity, LanguageMode language_mode, VectorSlotPair const& feedback, |
562 ConvertReceiverMode convert_mode, TailCallMode tail_call_mode) { | 723 ConvertReceiverMode convert_mode, TailCallMode tail_call_mode) { |
563 CallFunctionParameters parameters(arity, language_mode, feedback, | 724 CallFunctionParameters parameters(arity, language_mode, feedback, |
564 tail_call_mode, convert_mode); | 725 tail_call_mode, convert_mode); |
565 return new (zone()) Operator1<CallFunctionParameters>( // -- | 726 return new (zone()) Operator1<CallFunctionParameters>( // -- |
566 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode | 727 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode |
567 "JSCallFunction", // name | 728 "JSCallFunction", // name |
568 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs | 729 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs |
569 parameters); // parameter | 730 parameters); // parameter |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 return new (zone()) Operator1<Handle<ScopeInfo>>( // -- | 986 return new (zone()) Operator1<Handle<ScopeInfo>>( // -- |
826 IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode | 987 IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode |
827 "JSCreateScriptContext", // name | 988 "JSCreateScriptContext", // name |
828 1, 1, 1, 1, 1, 2, // counts | 989 1, 1, 1, 1, 1, 2, // counts |
829 scpope_info); // parameter | 990 scpope_info); // parameter |
830 } | 991 } |
831 | 992 |
832 } // namespace compiler | 993 } // namespace compiler |
833 } // namespace internal | 994 } // namespace internal |
834 } // namespace v8 | 995 } // namespace v8 |
OLD | NEW |