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-inl.h" | 7 #include "src/compiler/node-properties-inl.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" |
11 #include "testing/gmock-support.h" | 11 #include "testing/gmock-support.h" |
12 | 12 |
13 using testing::Capture; | 13 using testing::Capture; |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 class JSBuiltinReducerTest : public TypedGraphTest { | 19 class JSBuiltinReducerTest : public TypedGraphTest { |
20 public: | 20 public: |
21 JSBuiltinReducerTest() : javascript_(zone()) {} | 21 JSBuiltinReducerTest() : javascript_(zone()) {} |
22 | 22 |
23 protected: | 23 protected: |
24 Reduction Reduce(Node* node) { | 24 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
25 MachineOperatorBuilder machine; | 25 MachineOperatorBuilder::Flag::kNoFlags) { |
| 26 MachineOperatorBuilder machine(kMachPtr, flags); |
26 JSGraph jsgraph(graph(), common(), javascript(), &machine); | 27 JSGraph jsgraph(graph(), common(), javascript(), &machine); |
27 JSBuiltinReducer reducer(&jsgraph); | 28 JSBuiltinReducer reducer(&jsgraph); |
28 return reducer.Reduce(node); | 29 return reducer.Reduce(node); |
29 } | 30 } |
30 | 31 |
31 Node* Parameter(Type* t, int32_t index = 0) { | 32 Node* Parameter(Type* t, int32_t index = 0) { |
32 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); | 33 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); |
33 NodeProperties::SetBounds(n, Bounds(Type::None(), t)); | 34 NodeProperties::SetBounds(n, Bounds(Type::None(), t)); |
34 return n; | 35 return n; |
35 } | 36 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Node* call = | 231 Node* call = |
231 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), | 232 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), |
232 fun, UndefinedConstant(), p0); | 233 fun, UndefinedConstant(), p0); |
233 Reduction r = Reduce(call); | 234 Reduction r = Reduce(call); |
234 | 235 |
235 ASSERT_TRUE(r.Changed()); | 236 ASSERT_TRUE(r.Changed()); |
236 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 237 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
| 241 |
| 242 // ----------------------------------------------------------------------------- |
| 243 // Math.floor |
| 244 |
| 245 |
| 246 TEST_F(JSBuiltinReducerTest, MathFloorAvailable) { |
| 247 Handle<JSFunction> f = MathFunction("floor"); |
| 248 |
| 249 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 250 Node* p0 = Parameter(t0, 0); |
| 251 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 252 Node* call = |
| 253 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), |
| 254 fun, UndefinedConstant(), p0); |
| 255 Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kFloat64Floor); |
| 256 |
| 257 ASSERT_TRUE(r.Changed()); |
| 258 EXPECT_THAT(r.replacement(), IsFloat64Floor(p0)); |
| 259 } |
| 260 } |
| 261 |
| 262 |
| 263 TEST_F(JSBuiltinReducerTest, MathFloorUnavailable) { |
| 264 Handle<JSFunction> f = MathFunction("floor"); |
| 265 |
| 266 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 267 Node* p0 = Parameter(t0, 0); |
| 268 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 269 Node* call = |
| 270 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), |
| 271 fun, UndefinedConstant(), p0); |
| 272 Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kNoFlags); |
| 273 |
| 274 ASSERT_FALSE(r.Changed()); |
| 275 } |
| 276 } |
| 277 |
| 278 |
| 279 // ----------------------------------------------------------------------------- |
| 280 // Math.ceil |
| 281 |
| 282 |
| 283 TEST_F(JSBuiltinReducerTest, MathCeilAvailable) { |
| 284 Handle<JSFunction> f = MathFunction("ceil"); |
| 285 |
| 286 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 287 Node* p0 = Parameter(t0, 0); |
| 288 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 289 Node* call = |
| 290 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), |
| 291 fun, UndefinedConstant(), p0); |
| 292 Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kFloat64Ceil); |
| 293 |
| 294 ASSERT_TRUE(r.Changed()); |
| 295 EXPECT_THAT(r.replacement(), IsFloat64Ceil(p0)); |
| 296 } |
| 297 } |
| 298 |
| 299 |
| 300 TEST_F(JSBuiltinReducerTest, MathCeilUnavailable) { |
| 301 Handle<JSFunction> f = MathFunction("ceil"); |
| 302 |
| 303 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 304 Node* p0 = Parameter(t0, 0); |
| 305 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 306 Node* call = |
| 307 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), |
| 308 fun, UndefinedConstant(), p0); |
| 309 Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kNoFlags); |
| 310 |
| 311 ASSERT_FALSE(r.Changed()); |
| 312 } |
| 313 } |
240 } // namespace compiler | 314 } // namespace compiler |
241 } // namespace internal | 315 } // namespace internal |
242 } // namespace v8 | 316 } // namespace v8 |
OLD | NEW |