| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 Type* const kNumberTypes[] = { | 80 Type* const kNumberTypes[] = { |
| 81 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), | 81 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), |
| 82 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), | 82 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), |
| 83 Type::Integral32(), Type::MinusZero(), Type::NaN(), | 83 Type::Integral32(), Type::MinusZero(), Type::NaN(), |
| 84 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; | 84 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 | 88 |
| 89 // ----------------------------------------------------------------------------- | 89 // ----------------------------------------------------------------------------- |
| 90 // Math.abs |
| 91 |
| 92 TEST_F(JSBuiltinReducerTest, MathAbsWithNumber) { |
| 93 Node* function = MathFunction("abs"); |
| 94 |
| 95 Node* effect = graph()->start(); |
| 96 Node* control = graph()->start(); |
| 97 Node* context = UndefinedConstant(); |
| 98 Node* frame_state = graph()->start(); |
| 99 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 100 Node* p0 = Parameter(t0, 0); |
| 101 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 102 UndefinedConstant(), p0, context, frame_state, |
| 103 effect, control); |
| 104 Reduction r = Reduce(call); |
| 105 |
| 106 ASSERT_TRUE(r.Changed()); |
| 107 EXPECT_THAT(r.replacement(), IsNumberAbs(p0)); |
| 108 } |
| 109 } |
| 110 |
| 111 TEST_F(JSBuiltinReducerTest, MathAbsWithPlainPrimitive) { |
| 112 Node* function = MathFunction("abs"); |
| 113 |
| 114 Node* effect = graph()->start(); |
| 115 Node* control = graph()->start(); |
| 116 Node* context = UndefinedConstant(); |
| 117 Node* frame_state = graph()->start(); |
| 118 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
| 119 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
| 120 UndefinedConstant(), p0, context, frame_state, |
| 121 effect, control); |
| 122 Reduction r = Reduce(call); |
| 123 |
| 124 ASSERT_TRUE(r.Changed()); |
| 125 EXPECT_THAT(r.replacement(), IsNumberAbs(IsPlainPrimitiveToNumber(p0))); |
| 126 } |
| 127 |
| 128 // ----------------------------------------------------------------------------- |
| 90 // Math.atan | 129 // Math.atan |
| 91 | 130 |
| 92 TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) { | 131 TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) { |
| 93 Node* function = MathFunction("atan"); | 132 Node* function = MathFunction("atan"); |
| 94 | 133 |
| 95 Node* effect = graph()->start(); | 134 Node* effect = graph()->start(); |
| 96 Node* control = graph()->start(); | 135 Node* control = graph()->start(); |
| 97 Node* context = UndefinedConstant(); | 136 Node* context = UndefinedConstant(); |
| 98 Node* frame_state = graph()->start(); | 137 Node* frame_state = graph()->start(); |
| 99 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 138 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 Reduction r = Reduce(call); | 983 Reduction r = Reduce(call); |
| 945 | 984 |
| 946 ASSERT_TRUE(r.Changed()); | 985 ASSERT_TRUE(r.Changed()); |
| 947 EXPECT_THAT(r.replacement(), | 986 EXPECT_THAT(r.replacement(), |
| 948 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); | 987 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); |
| 949 } | 988 } |
| 950 | 989 |
| 951 } // namespace compiler | 990 } // namespace compiler |
| 952 } // namespace internal | 991 } // namespace internal |
| 953 } // namespace v8 | 992 } // namespace v8 |
| OLD | NEW |