| 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/typer.h" | 8 #include "src/compiler/typer.h" |
| 9 #include "test/unittests/compiler/graph-unittest.h" | 9 #include "test/unittests/compiler/graph-unittest.h" |
| 10 #include "test/unittests/compiler/node-test-utils.h" | 10 #include "test/unittests/compiler/node-test-utils.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 | 72 |
| 73 // ----------------------------------------------------------------------------- | 73 // ----------------------------------------------------------------------------- |
| 74 // Math.max | 74 // Math.max |
| 75 | 75 |
| 76 | 76 |
| 77 TEST_F(JSBuiltinReducerTest, MathMax0) { | 77 TEST_F(JSBuiltinReducerTest, MathMax0) { |
| 78 Node* function = MathFunction("max"); | 78 Node* function = MathFunction("max"); |
| 79 | 79 |
| 80 Node* effect = graph()->start(); |
| 81 Node* control = graph()->start(); |
| 82 Node* frame_state = graph()->start(); |
| 80 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 83 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 81 Node* call = graph()->NewNode( | 84 Node* call = graph()->NewNode( |
| 82 javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, language_mode), | 85 javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, language_mode), |
| 83 function, UndefinedConstant()); | 86 function, UndefinedConstant(), frame_state, frame_state, effect, |
| 87 control); |
| 84 Reduction r = Reduce(call); | 88 Reduction r = Reduce(call); |
| 85 | 89 |
| 86 ASSERT_TRUE(r.Changed()); | 90 ASSERT_TRUE(r.Changed()); |
| 87 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); | 91 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); |
| 88 } | 92 } |
| 89 } | 93 } |
| 90 | 94 |
| 91 | 95 |
| 92 TEST_F(JSBuiltinReducerTest, MathMax1) { | 96 TEST_F(JSBuiltinReducerTest, MathMax1) { |
| 93 Node* function = MathFunction("max"); | 97 Node* function = MathFunction("max"); |
| 94 | 98 |
| 99 Node* effect = graph()->start(); |
| 100 Node* control = graph()->start(); |
| 101 Node* frame_state = graph()->start(); |
| 95 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 102 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 96 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 103 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 97 Node* p0 = Parameter(t0, 0); | 104 Node* p0 = Parameter(t0, 0); |
| 98 Node* call = graph()->NewNode( | 105 Node* call = graph()->NewNode( |
| 99 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), | 106 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), |
| 100 function, UndefinedConstant(), p0); | 107 function, UndefinedConstant(), p0, frame_state, frame_state, effect, |
| 108 control); |
| 101 Reduction r = Reduce(call); | 109 Reduction r = Reduce(call); |
| 102 | 110 |
| 103 ASSERT_TRUE(r.Changed()); | 111 ASSERT_TRUE(r.Changed()); |
| 104 EXPECT_THAT(r.replacement(), p0); | 112 EXPECT_THAT(r.replacement(), p0); |
| 105 } | 113 } |
| 106 } | 114 } |
| 107 } | 115 } |
| 108 | 116 |
| 109 | 117 |
| 110 TEST_F(JSBuiltinReducerTest, MathMax2) { | 118 TEST_F(JSBuiltinReducerTest, MathMax2) { |
| 111 Node* function = MathFunction("max"); | 119 Node* function = MathFunction("max"); |
| 112 | 120 |
| 121 Node* effect = graph()->start(); |
| 122 Node* control = graph()->start(); |
| 123 Node* frame_state = graph()->start(); |
| 113 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 124 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 114 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 125 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
| 115 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 126 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
| 116 Node* p0 = Parameter(t0, 0); | 127 Node* p0 = Parameter(t0, 0); |
| 117 Node* p1 = Parameter(t1, 1); | 128 Node* p1 = Parameter(t1, 1); |
| 118 Node* call = | 129 Node* call = |
| 119 graph()->NewNode(javascript()->CallFunction( | 130 graph()->NewNode(javascript()->CallFunction( |
| 120 4, NO_CALL_FUNCTION_FLAGS, language_mode), | 131 4, NO_CALL_FUNCTION_FLAGS, language_mode), |
| 121 function, UndefinedConstant(), p0, p1); | 132 function, UndefinedConstant(), p0, p1, frame_state, |
| 133 frame_state, effect, control); |
| 122 Reduction r = Reduce(call); | 134 Reduction r = Reduce(call); |
| 123 | 135 |
| 124 ASSERT_TRUE(r.Changed()); | 136 ASSERT_TRUE(r.Changed()); |
| 125 EXPECT_THAT(r.replacement(), | 137 EXPECT_THAT(r.replacement(), |
| 126 IsSelect(kMachNone, IsNumberLessThan(p1, p0), p0, p1)); | 138 IsSelect(kMachNone, IsNumberLessThan(p1, p0), p0, p1)); |
| 127 } | 139 } |
| 128 } | 140 } |
| 129 } | 141 } |
| 130 } | 142 } |
| 131 | 143 |
| 132 | 144 |
| 133 // ----------------------------------------------------------------------------- | 145 // ----------------------------------------------------------------------------- |
| 134 // Math.imul | 146 // Math.imul |
| 135 | 147 |
| 136 | 148 |
| 137 TEST_F(JSBuiltinReducerTest, MathImul) { | 149 TEST_F(JSBuiltinReducerTest, MathImul) { |
| 138 Node* function = MathFunction("imul"); | 150 Node* function = MathFunction("imul"); |
| 139 | 151 |
| 152 Node* effect = graph()->start(); |
| 153 Node* control = graph()->start(); |
| 154 Node* frame_state = graph()->start(); |
| 140 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 155 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 141 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 156 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
| 142 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 157 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
| 143 Node* p0 = Parameter(t0, 0); | 158 Node* p0 = Parameter(t0, 0); |
| 144 Node* p1 = Parameter(t1, 1); | 159 Node* p1 = Parameter(t1, 1); |
| 145 Node* call = | 160 Node* call = |
| 146 graph()->NewNode(javascript()->CallFunction( | 161 graph()->NewNode(javascript()->CallFunction( |
| 147 4, NO_CALL_FUNCTION_FLAGS, language_mode), | 162 4, NO_CALL_FUNCTION_FLAGS, language_mode), |
| 148 function, UndefinedConstant(), p0, p1); | 163 function, UndefinedConstant(), p0, p1, frame_state, |
| 164 frame_state, effect, control); |
| 149 Reduction r = Reduce(call); | 165 Reduction r = Reduce(call); |
| 150 | 166 |
| 151 ASSERT_TRUE(r.Changed()); | 167 ASSERT_TRUE(r.Changed()); |
| 152 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); | 168 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); |
| 153 } | 169 } |
| 154 } | 170 } |
| 155 } | 171 } |
| 156 } | 172 } |
| 157 | 173 |
| 158 | 174 |
| 159 // ----------------------------------------------------------------------------- | 175 // ----------------------------------------------------------------------------- |
| 160 // Math.fround | 176 // Math.fround |
| 161 | 177 |
| 162 | 178 |
| 163 TEST_F(JSBuiltinReducerTest, MathFround) { | 179 TEST_F(JSBuiltinReducerTest, MathFround) { |
| 164 Node* function = MathFunction("fround"); | 180 Node* function = MathFunction("fround"); |
| 165 | 181 |
| 182 Node* effect = graph()->start(); |
| 183 Node* control = graph()->start(); |
| 184 Node* frame_state = graph()->start(); |
| 166 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 185 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 167 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 186 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 168 Node* p0 = Parameter(t0, 0); | 187 Node* p0 = Parameter(t0, 0); |
| 169 Node* call = graph()->NewNode( | 188 Node* call = graph()->NewNode( |
| 170 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), | 189 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), |
| 171 function, UndefinedConstant(), p0); | 190 function, UndefinedConstant(), p0, frame_state, frame_state, effect, |
| 191 control); |
| 172 Reduction r = Reduce(call); | 192 Reduction r = Reduce(call); |
| 173 | 193 |
| 174 ASSERT_TRUE(r.Changed()); | 194 ASSERT_TRUE(r.Changed()); |
| 175 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 195 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
| 176 } | 196 } |
| 177 } | 197 } |
| 178 } | 198 } |
| 179 | 199 |
| 180 } // namespace compiler | 200 } // namespace compiler |
| 181 } // namespace internal | 201 } // namespace internal |
| 182 } // namespace v8 | 202 } // namespace v8 |
| OLD | NEW |