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