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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, | 785 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
786 UndefinedConstant(), p0, context, frame_state, | 786 UndefinedConstant(), p0, context, frame_state, |
787 effect, control); | 787 effect, control); |
788 Reduction r = Reduce(call); | 788 Reduction r = Reduce(call); |
789 | 789 |
790 ASSERT_TRUE(r.Changed()); | 790 ASSERT_TRUE(r.Changed()); |
791 EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0))); | 791 EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0))); |
792 } | 792 } |
793 | 793 |
794 // ----------------------------------------------------------------------------- | 794 // ----------------------------------------------------------------------------- |
| 795 // Math.pow |
| 796 |
| 797 TEST_F(JSBuiltinReducerTest, MathPowWithNumber) { |
| 798 Node* function = MathFunction("pow"); |
| 799 |
| 800 Node* effect = graph()->start(); |
| 801 Node* control = graph()->start(); |
| 802 Node* context = UndefinedConstant(); |
| 803 Node* frame_state = graph()->start(); |
| 804 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 805 Node* p0 = Parameter(t0, 0); |
| 806 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
| 807 Node* p1 = Parameter(t1, 0); |
| 808 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
| 809 UndefinedConstant(), p0, p1, context, |
| 810 frame_state, effect, control); |
| 811 Reduction r = Reduce(call); |
| 812 |
| 813 ASSERT_TRUE(r.Changed()); |
| 814 EXPECT_THAT(r.replacement(), IsNumberPow(p0, p1)); |
| 815 } |
| 816 } |
| 817 } |
| 818 |
| 819 TEST_F(JSBuiltinReducerTest, MathPowWithPlainPrimitive) { |
| 820 Node* function = MathFunction("pow"); |
| 821 |
| 822 Node* effect = graph()->start(); |
| 823 Node* control = graph()->start(); |
| 824 Node* context = UndefinedConstant(); |
| 825 Node* frame_state = graph()->start(); |
| 826 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
| 827 Node* p1 = Parameter(Type::PlainPrimitive(), 0); |
| 828 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
| 829 UndefinedConstant(), p0, p1, context, |
| 830 frame_state, effect, control); |
| 831 Reduction r = Reduce(call); |
| 832 |
| 833 ASSERT_TRUE(r.Changed()); |
| 834 EXPECT_THAT(r.replacement(), IsNumberPow(IsPlainPrimitiveToNumber(p0), |
| 835 IsPlainPrimitiveToNumber(p1))); |
| 836 } |
| 837 |
| 838 // ----------------------------------------------------------------------------- |
795 // Math.sin | 839 // Math.sin |
796 | 840 |
797 TEST_F(JSBuiltinReducerTest, MathSinWithNumber) { | 841 TEST_F(JSBuiltinReducerTest, MathSinWithNumber) { |
798 Node* function = MathFunction("sin"); | 842 Node* function = MathFunction("sin"); |
799 | 843 |
800 Node* effect = graph()->start(); | 844 Node* effect = graph()->start(); |
801 Node* control = graph()->start(); | 845 Node* control = graph()->start(); |
802 Node* context = UndefinedConstant(); | 846 Node* context = UndefinedConstant(); |
803 Node* frame_state = graph()->start(); | 847 Node* frame_state = graph()->start(); |
804 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 848 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 Reduction r = Reduce(call); | 1027 Reduction r = Reduce(call); |
984 | 1028 |
985 ASSERT_TRUE(r.Changed()); | 1029 ASSERT_TRUE(r.Changed()); |
986 EXPECT_THAT(r.replacement(), | 1030 EXPECT_THAT(r.replacement(), |
987 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); | 1031 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); |
988 } | 1032 } |
989 | 1033 |
990 } // namespace compiler | 1034 } // namespace compiler |
991 } // namespace internal | 1035 } // namespace internal |
992 } // namespace v8 | 1036 } // namespace v8 |
OLD | NEW |