| 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/load-elimination.h" | 6 #include "src/compiler/load-elimination.h" |
| 7 #include "src/compiler/simplified-operator.h" | 7 #include "src/compiler/simplified-operator.h" |
| 8 #include "test/unittests/compiler/graph-unittest.h" | 8 #include "test/unittests/compiler/graph-unittest.h" |
| 9 #include "test/unittests/compiler/node-test-utils.h" | 9 #include "test/unittests/compiler/node-test-utils.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 class LoadEliminationTest : public GraphTest { | 15 class LoadEliminationTest : public TypedGraphTest { |
| 16 public: | 16 public: |
| 17 LoadEliminationTest() : GraphTest(3), simplified_(zone()) {} | 17 LoadEliminationTest() |
| 18 : TypedGraphTest(3), common_(zone()), simplified_(zone()) {} |
| 18 ~LoadEliminationTest() override {} | 19 ~LoadEliminationTest() override {} |
| 19 | 20 |
| 20 protected: | 21 protected: |
| 21 Reduction Reduce(Node* node) { | 22 Reduction Reduce(Node* node) { |
| 22 // TODO(titzer): mock the GraphReducer here for better unit testing. | 23 // TODO(titzer): mock the GraphReducer here for better unit testing. |
| 23 GraphReducer graph_reducer(zone(), graph()); | 24 GraphReducer graph_reducer(zone(), graph()); |
| 24 LoadElimination reducer(&graph_reducer); | 25 LoadElimination reducer(&graph_reducer, graph(), common()); |
| 25 return reducer.Reduce(node); | 26 return reducer.Reduce(node); |
| 26 } | 27 } |
| 27 | 28 |
| 28 SimplifiedOperatorBuilder* simplified() { return &simplified_; } | 29 SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
| 30 CommonOperatorBuilder* common() { return &common_; } |
| 29 | 31 |
| 30 private: | 32 private: |
| 33 CommonOperatorBuilder common_; |
| 31 SimplifiedOperatorBuilder simplified_; | 34 SimplifiedOperatorBuilder simplified_; |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 | 37 |
| 35 TEST_F(LoadEliminationTest, LoadFieldWithStoreField) { | 38 TEST_F(LoadEliminationTest, LoadFieldWithStoreField) { |
| 36 Node* object1 = Parameter(0); | 39 Node* object1 = Parameter(Type::Any(), 0); |
| 37 Node* object2 = Parameter(1); | 40 Node* object2 = Parameter(Type::Any(), 1); |
| 38 Node* value = Parameter(2); | 41 Node* value = Parameter(Type::Any(), 2); |
| 39 Node* effect = graph()->start(); | 42 Node* effect = graph()->start(); |
| 40 Node* control = graph()->start(); | 43 Node* control = graph()->start(); |
| 41 | 44 |
| 42 FieldAccess access1 = AccessBuilder::ForContextSlot(42); | 45 FieldAccess access1 = AccessBuilder::ForContextSlot(42); |
| 43 Node* store1 = graph()->NewNode(simplified()->StoreField(access1), object1, | 46 Node* store1 = graph()->NewNode(simplified()->StoreField(access1), object1, |
| 44 value, effect, control); | 47 value, effect, control); |
| 45 Reduction r1 = Reduce(graph()->NewNode(simplified()->LoadField(access1), | 48 Reduction r1 = Reduce(graph()->NewNode(simplified()->LoadField(access1), |
| 46 object1, store1, control)); | 49 object1, store1, control)); |
| 47 ASSERT_TRUE(r1.Changed()); | 50 ASSERT_TRUE(r1.Changed()); |
| 48 EXPECT_EQ(value, r1.replacement()); | 51 EXPECT_EQ(value, r1.replacement()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 65 | 68 |
| 66 Reduction r4 = Reduce(graph()->NewNode(simplified()->LoadField(access1), | 69 Reduction r4 = Reduce(graph()->NewNode(simplified()->LoadField(access1), |
| 67 object1, store3, control)); | 70 object1, store3, control)); |
| 68 ASSERT_TRUE(r4.Changed()); | 71 ASSERT_TRUE(r4.Changed()); |
| 69 EXPECT_EQ(value, r4.replacement()); | 72 EXPECT_EQ(value, r4.replacement()); |
| 70 } | 73 } |
| 71 | 74 |
| 72 } // namespace compiler | 75 } // namespace compiler |
| 73 } // namespace internal | 76 } // namespace internal |
| 74 } // namespace v8 | 77 } // namespace v8 |
| OLD | NEW |