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-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/simplified-operator.h" | 8 #include "src/compiler/simplified-operator.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, | 746 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
747 UndefinedConstant(), p0, context, frame_state, | 747 UndefinedConstant(), p0, context, frame_state, |
748 effect, control); | 748 effect, control); |
749 Reduction r = Reduce(call); | 749 Reduction r = Reduce(call); |
750 | 750 |
751 ASSERT_TRUE(r.Changed()); | 751 ASSERT_TRUE(r.Changed()); |
752 EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0))); | 752 EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0))); |
753 } | 753 } |
754 | 754 |
755 // ----------------------------------------------------------------------------- | 755 // ----------------------------------------------------------------------------- |
| 756 // Math.sin |
| 757 |
| 758 TEST_F(JSBuiltinReducerTest, MathSinWithNumber) { |
| 759 Node* function = MathFunction("sin"); |
| 760 |
| 761 Node* effect = graph()->start(); |
| 762 Node* control = graph()->start(); |
| 763 Node* context = UndefinedConstant(); |
| 764 Node* frame_state = graph()->start(); |
| 765 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 766 Node* p0 = Parameter(t0, 0); |
| 767 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 768 UndefinedConstant(), p0, context, frame_state, |
| 769 effect, control); |
| 770 Reduction r = Reduce(call); |
| 771 |
| 772 ASSERT_TRUE(r.Changed()); |
| 773 EXPECT_THAT(r.replacement(), IsNumberSin(p0)); |
| 774 } |
| 775 } |
| 776 |
| 777 TEST_F(JSBuiltinReducerTest, MathSinWithPlainPrimitive) { |
| 778 Node* function = MathFunction("sin"); |
| 779 |
| 780 Node* effect = graph()->start(); |
| 781 Node* control = graph()->start(); |
| 782 Node* context = UndefinedConstant(); |
| 783 Node* frame_state = graph()->start(); |
| 784 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
| 785 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 786 UndefinedConstant(), p0, context, frame_state, |
| 787 effect, control); |
| 788 Reduction r = Reduce(call); |
| 789 |
| 790 ASSERT_TRUE(r.Changed()); |
| 791 EXPECT_THAT(r.replacement(), IsNumberSin(IsPlainPrimitiveToNumber(p0))); |
| 792 } |
| 793 |
| 794 // ----------------------------------------------------------------------------- |
756 // Math.sqrt | 795 // Math.sqrt |
757 | 796 |
758 TEST_F(JSBuiltinReducerTest, MathSqrtWithNumber) { | 797 TEST_F(JSBuiltinReducerTest, MathSqrtWithNumber) { |
759 Node* function = MathFunction("sqrt"); | 798 Node* function = MathFunction("sqrt"); |
760 | 799 |
761 Node* effect = graph()->start(); | 800 Node* effect = graph()->start(); |
762 Node* control = graph()->start(); | 801 Node* control = graph()->start(); |
763 Node* context = UndefinedConstant(); | 802 Node* context = UndefinedConstant(); |
764 Node* frame_state = graph()->start(); | 803 Node* frame_state = graph()->start(); |
765 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 804 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
(...skipping 19 matching lines...) Expand all Loading... |
785 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, | 824 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
786 UndefinedConstant(), p0, context, frame_state, | 825 UndefinedConstant(), p0, context, frame_state, |
787 effect, control); | 826 effect, control); |
788 Reduction r = Reduce(call); | 827 Reduction r = Reduce(call); |
789 | 828 |
790 ASSERT_TRUE(r.Changed()); | 829 ASSERT_TRUE(r.Changed()); |
791 EXPECT_THAT(r.replacement(), IsNumberSqrt(IsPlainPrimitiveToNumber(p0))); | 830 EXPECT_THAT(r.replacement(), IsNumberSqrt(IsPlainPrimitiveToNumber(p0))); |
792 } | 831 } |
793 | 832 |
794 // ----------------------------------------------------------------------------- | 833 // ----------------------------------------------------------------------------- |
| 834 // Math.tan |
| 835 |
| 836 TEST_F(JSBuiltinReducerTest, MathTanWithNumber) { |
| 837 Node* function = MathFunction("tan"); |
| 838 |
| 839 Node* effect = graph()->start(); |
| 840 Node* control = graph()->start(); |
| 841 Node* context = UndefinedConstant(); |
| 842 Node* frame_state = graph()->start(); |
| 843 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 844 Node* p0 = Parameter(t0, 0); |
| 845 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 846 UndefinedConstant(), p0, context, frame_state, |
| 847 effect, control); |
| 848 Reduction r = Reduce(call); |
| 849 |
| 850 ASSERT_TRUE(r.Changed()); |
| 851 EXPECT_THAT(r.replacement(), IsNumberTan(p0)); |
| 852 } |
| 853 } |
| 854 |
| 855 TEST_F(JSBuiltinReducerTest, MathTanWithPlainPrimitive) { |
| 856 Node* function = MathFunction("tan"); |
| 857 |
| 858 Node* effect = graph()->start(); |
| 859 Node* control = graph()->start(); |
| 860 Node* context = UndefinedConstant(); |
| 861 Node* frame_state = graph()->start(); |
| 862 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
| 863 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 864 UndefinedConstant(), p0, context, frame_state, |
| 865 effect, control); |
| 866 Reduction r = Reduce(call); |
| 867 |
| 868 ASSERT_TRUE(r.Changed()); |
| 869 EXPECT_THAT(r.replacement(), IsNumberTan(IsPlainPrimitiveToNumber(p0))); |
| 870 } |
| 871 |
| 872 // ----------------------------------------------------------------------------- |
795 // Math.trunc | 873 // Math.trunc |
796 | 874 |
797 TEST_F(JSBuiltinReducerTest, MathTruncWithNumber) { | 875 TEST_F(JSBuiltinReducerTest, MathTruncWithNumber) { |
798 Node* function = MathFunction("trunc"); | 876 Node* function = MathFunction("trunc"); |
799 | 877 |
800 Node* effect = graph()->start(); | 878 Node* effect = graph()->start(); |
801 Node* control = graph()->start(); | 879 Node* control = graph()->start(); |
802 Node* context = UndefinedConstant(); | 880 Node* context = UndefinedConstant(); |
803 Node* frame_state = graph()->start(); | 881 Node* frame_state = graph()->start(); |
804 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 882 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 Reduction r = Reduce(call); | 944 Reduction r = Reduce(call); |
867 | 945 |
868 ASSERT_TRUE(r.Changed()); | 946 ASSERT_TRUE(r.Changed()); |
869 EXPECT_THAT(r.replacement(), | 947 EXPECT_THAT(r.replacement(), |
870 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); | 948 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); |
871 } | 949 } |
872 | 950 |
873 } // namespace compiler | 951 } // namespace compiler |
874 } // namespace internal | 952 } // namespace internal |
875 } // namespace v8 | 953 } // namespace v8 |
OLD | NEW |