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/access-builder.h" | 5 #include "src/compiler/access-builder.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/simplified-operator-reducer.h" | 9 #include "src/compiler/simplified-operator-reducer.h" |
10 #include "src/conversions-inl.h" | 10 #include "src/conversions-inl.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 explicit SimplifiedOperatorReducerTest(int num_parameters = 1) | 25 explicit SimplifiedOperatorReducerTest(int num_parameters = 1) |
26 : TypedGraphTest(num_parameters), simplified_(zone()) {} | 26 : TypedGraphTest(num_parameters), simplified_(zone()) {} |
27 ~SimplifiedOperatorReducerTest() override {} | 27 ~SimplifiedOperatorReducerTest() override {} |
28 | 28 |
29 protected: | 29 protected: |
30 Reduction Reduce(Node* node) { | 30 Reduction Reduce(Node* node) { |
31 MachineOperatorBuilder machine(zone()); | 31 MachineOperatorBuilder machine(zone()); |
32 JSOperatorBuilder javascript(zone()); | 32 JSOperatorBuilder javascript(zone()); |
33 JSGraph jsgraph(isolate(), graph(), common(), &javascript, simplified(), | 33 JSGraph jsgraph(isolate(), graph(), common(), &javascript, simplified(), |
34 &machine); | 34 &machine); |
35 SimplifiedOperatorReducer reducer(&jsgraph); | 35 GraphReducer graph_reducer(zone(), graph()); |
| 36 SimplifiedOperatorReducer reducer(&graph_reducer, &jsgraph); |
36 return reducer.Reduce(node); | 37 return reducer.Reduce(node); |
37 } | 38 } |
38 | 39 |
39 SimplifiedOperatorBuilder* simplified() { return &simplified_; } | 40 SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
40 | 41 |
41 private: | 42 private: |
42 SimplifiedOperatorBuilder simplified_; | 43 SimplifiedOperatorBuilder simplified_; |
43 }; | 44 }; |
44 | 45 |
45 | 46 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 TEST_F(SimplifiedOperatorReducerTest, TruncateTaggedToWord32WithConstant) { | 337 TEST_F(SimplifiedOperatorReducerTest, TruncateTaggedToWord32WithConstant) { |
337 TRACED_FOREACH(double, n, kFloat64Values) { | 338 TRACED_FOREACH(double, n, kFloat64Values) { |
338 Reduction reduction = Reduce(graph()->NewNode( | 339 Reduction reduction = Reduce(graph()->NewNode( |
339 simplified()->TruncateTaggedToWord32(), NumberConstant(n))); | 340 simplified()->TruncateTaggedToWord32(), NumberConstant(n))); |
340 ASSERT_TRUE(reduction.Changed()); | 341 ASSERT_TRUE(reduction.Changed()); |
341 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(n))); | 342 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(n))); |
342 } | 343 } |
343 } | 344 } |
344 | 345 |
345 // ----------------------------------------------------------------------------- | 346 // ----------------------------------------------------------------------------- |
346 // TruncateTaggedToWord32 | 347 // CheckTaggedPointer |
| 348 |
| 349 TEST_F(SimplifiedOperatorReducerTest, CheckTaggedPointerWithChangeBitToTagged) { |
| 350 Node* param0 = Parameter(0); |
| 351 Node* effect = graph()->start(); |
| 352 Node* control = graph()->start(); |
| 353 Node* value = graph()->NewNode(simplified()->ChangeBitToTagged(), param0); |
| 354 Reduction reduction = Reduce(graph()->NewNode( |
| 355 simplified()->CheckTaggedPointer(), value, effect, control)); |
| 356 ASSERT_TRUE(reduction.Changed()); |
| 357 EXPECT_EQ(value, reduction.replacement()); |
| 358 } |
| 359 |
| 360 TEST_F(SimplifiedOperatorReducerTest, CheckTaggedPointerWithHeapConstant) { |
| 361 Node* effect = graph()->start(); |
| 362 Node* control = graph()->start(); |
| 363 Handle<HeapObject> kHeapObjects[] = { |
| 364 factory()->empty_string(), factory()->null_value(), |
| 365 factory()->species_symbol(), factory()->undefined_value()}; |
| 366 TRACED_FOREACH(Handle<HeapObject>, object, kHeapObjects) { |
| 367 Node* value = HeapConstant(object); |
| 368 Reduction reduction = Reduce(graph()->NewNode( |
| 369 simplified()->CheckTaggedPointer(), value, effect, control)); |
| 370 ASSERT_TRUE(reduction.Changed()); |
| 371 EXPECT_EQ(value, reduction.replacement()); |
| 372 } |
| 373 } |
| 374 |
| 375 // ----------------------------------------------------------------------------- |
| 376 // CheckTaggedSigned |
| 377 |
| 378 TEST_F(SimplifiedOperatorReducerTest, |
| 379 CheckTaggedSignedWithChangeInt31ToTaggedSigned) { |
| 380 Node* param0 = Parameter(0); |
| 381 Node* effect = graph()->start(); |
| 382 Node* control = graph()->start(); |
| 383 Node* value = |
| 384 graph()->NewNode(simplified()->ChangeInt31ToTaggedSigned(), param0); |
| 385 Reduction reduction = Reduce(graph()->NewNode( |
| 386 simplified()->CheckTaggedSigned(), value, effect, control)); |
| 387 ASSERT_TRUE(reduction.Changed()); |
| 388 EXPECT_EQ(value, reduction.replacement()); |
| 389 } |
| 390 |
| 391 TEST_F(SimplifiedOperatorReducerTest, CheckTaggedSignedWithNumberConstant) { |
| 392 Node* effect = graph()->start(); |
| 393 Node* control = graph()->start(); |
| 394 Node* value = NumberConstant(1.0); |
| 395 Reduction reduction = Reduce(graph()->NewNode( |
| 396 simplified()->CheckTaggedSigned(), value, effect, control)); |
| 397 ASSERT_TRUE(reduction.Changed()); |
| 398 EXPECT_EQ(value, reduction.replacement()); |
| 399 } |
| 400 |
| 401 // ----------------------------------------------------------------------------- |
| 402 // ObjectIsSmi |
347 | 403 |
348 TEST_F(SimplifiedOperatorReducerTest, ObjectIsSmiWithChangeBitToTagged) { | 404 TEST_F(SimplifiedOperatorReducerTest, ObjectIsSmiWithChangeBitToTagged) { |
349 Node* param0 = Parameter(0); | 405 Node* param0 = Parameter(0); |
350 Reduction reduction = Reduce(graph()->NewNode( | 406 Reduction reduction = Reduce(graph()->NewNode( |
351 simplified()->ObjectIsSmi(), | 407 simplified()->ObjectIsSmi(), |
352 graph()->NewNode(simplified()->ChangeBitToTagged(), param0))); | 408 graph()->NewNode(simplified()->ChangeBitToTagged(), param0))); |
353 ASSERT_TRUE(reduction.Changed()); | 409 ASSERT_TRUE(reduction.Changed()); |
354 EXPECT_THAT(reduction.replacement(), IsFalseConstant()); | 410 EXPECT_THAT(reduction.replacement(), IsFalseConstant()); |
355 } | 411 } |
356 | 412 |
(...skipping 24 matching lines...) Expand all Loading... |
381 Reduction reduction = Reduce( | 437 Reduction reduction = Reduce( |
382 graph()->NewNode(simplified()->ObjectIsSmi(), NumberConstant(n))); | 438 graph()->NewNode(simplified()->ObjectIsSmi(), NumberConstant(n))); |
383 ASSERT_TRUE(reduction.Changed()); | 439 ASSERT_TRUE(reduction.Changed()); |
384 EXPECT_THAT(reduction.replacement(), IsBooleanConstant(IsSmiDouble(n))); | 440 EXPECT_THAT(reduction.replacement(), IsBooleanConstant(IsSmiDouble(n))); |
385 } | 441 } |
386 } | 442 } |
387 | 443 |
388 } // namespace compiler | 444 } // namespace compiler |
389 } // namespace internal | 445 } // namespace internal |
390 } // namespace v8 | 446 } // namespace v8 |
OLD | NEW |