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/graph.h" | 5 #include "src/compiler/graph.h" |
6 #include "src/compiler/graph-reducer.h" | 6 #include "src/compiler/graph-reducer.h" |
7 #include "src/compiler/operator.h" | 7 #include "src/compiler/operator.h" |
8 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 DefaultValue<Reduction>::Set(Reducer::NoChange()); | 48 DefaultValue<Reduction>::Set(Reducer::NoChange()); |
49 } | 49 } |
50 | 50 |
51 static void TearDownTestCase() { | 51 static void TearDownTestCase() { |
52 DefaultValue<Reduction>::Clear(); | 52 DefaultValue<Reduction>::Clear(); |
53 TestWithZone::TearDownTestCase(); | 53 TestWithZone::TearDownTestCase(); |
54 } | 54 } |
55 | 55 |
56 protected: | 56 protected: |
57 void ReduceNode(Node* node, Reducer* r) { | 57 void ReduceNode(Node* node, Reducer* r) { |
58 GraphReducer reducer(graph(), zone()); | 58 GraphReducer reducer(graph()); |
59 reducer.AddReducer(r); | 59 reducer.AddReducer(r); |
60 reducer.ReduceNode(node); | 60 reducer.ReduceNode(node); |
61 } | 61 } |
62 | 62 |
63 void ReduceNode(Node* node, Reducer* r1, Reducer* r2) { | 63 void ReduceNode(Node* node, Reducer* r1, Reducer* r2) { |
64 GraphReducer reducer(graph(), zone()); | 64 GraphReducer reducer(graph()); |
65 reducer.AddReducer(r1); | 65 reducer.AddReducer(r1); |
66 reducer.AddReducer(r2); | 66 reducer.AddReducer(r2); |
67 reducer.ReduceNode(node); | 67 reducer.ReduceNode(node); |
68 } | 68 } |
69 | 69 |
70 void ReduceNode(Node* node, Reducer* r1, Reducer* r2, Reducer* r3) { | 70 void ReduceNode(Node* node, Reducer* r1, Reducer* r2, Reducer* r3) { |
71 GraphReducer reducer(graph(), zone()); | 71 GraphReducer reducer(graph()); |
72 reducer.AddReducer(r1); | 72 reducer.AddReducer(r1); |
73 reducer.AddReducer(r2); | 73 reducer.AddReducer(r2); |
74 reducer.AddReducer(r3); | 74 reducer.AddReducer(r3); |
75 reducer.ReduceNode(node); | 75 reducer.ReduceNode(node); |
76 } | 76 } |
77 | 77 |
78 Graph* graph() { return &graph_; } | 78 Graph* graph() { return &graph_; } |
79 | 79 |
80 private: | 80 private: |
81 Graph graph_; | 81 Graph graph_; |
82 }; | 82 }; |
83 | 83 |
84 | 84 |
85 TEST_F(GraphReducerTest, NodeIsDeadAfterReplace) { | 85 TEST_F(GraphReducerTest, NodeIsDeadAfterReplace) { |
86 StrictMock<MockReducer> r; | 86 StrictMock<MockReducer> r; |
87 Node* node0 = graph()->NewNode(&OP0); | 87 Node* node0 = graph()->NewNode(&OP0); |
88 Node* node1 = graph()->NewNode(&OP1, node0); | 88 Node* node1 = graph()->NewNode(&OP1, node0); |
89 Node* node2 = graph()->NewNode(&OP1, node0); | 89 Node* node2 = graph()->NewNode(&OP1, node0); |
90 EXPECT_CALL(r, Reduce(node0)).WillOnce(Return(Reducer::NoChange())); | |
91 EXPECT_CALL(r, Reduce(node1)).WillOnce(Return(Reducer::Replace(node2))); | 90 EXPECT_CALL(r, Reduce(node1)).WillOnce(Return(Reducer::Replace(node2))); |
92 ReduceNode(node1, &r); | 91 ReduceNode(node1, &r); |
93 EXPECT_FALSE(node0->IsDead()); | 92 EXPECT_FALSE(node0->IsDead()); |
94 EXPECT_TRUE(node1->IsDead()); | 93 EXPECT_TRUE(node1->IsDead()); |
95 EXPECT_FALSE(node2->IsDead()); | 94 EXPECT_FALSE(node2->IsDead()); |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 TEST_F(GraphReducerTest, ReduceOnceForEveryReducer) { | 98 TEST_F(GraphReducerTest, ReduceOnceForEveryReducer) { |
100 StrictMock<MockReducer> r1, r2; | 99 StrictMock<MockReducer> r1, r2; |
101 Node* node0 = graph()->NewNode(&OP0); | 100 Node* node0 = graph()->NewNode(&OP0); |
102 EXPECT_CALL(r1, Reduce(node0)); | 101 EXPECT_CALL(r1, Reduce(node0)); |
103 EXPECT_CALL(r2, Reduce(node0)); | 102 EXPECT_CALL(r2, Reduce(node0)); |
104 ReduceNode(node0, &r1, &r2); | 103 ReduceNode(node0, &r1, &r2); |
105 } | 104 } |
106 | 105 |
107 | 106 |
108 TEST_F(GraphReducerTest, ReduceAgainAfterChanged) { | 107 TEST_F(GraphReducerTest, ReduceAgainAfterChanged) { |
109 Sequence s1, s2, s3; | 108 Sequence s1, s2, s3; |
110 StrictMock<MockReducer> r1, r2, r3; | 109 StrictMock<MockReducer> r1, r2, r3; |
111 Node* node0 = graph()->NewNode(&OP0); | 110 Node* node0 = graph()->NewNode(&OP0); |
112 EXPECT_CALL(r1, Reduce(node0)); | 111 EXPECT_CALL(r1, Reduce(node0)); |
113 EXPECT_CALL(r2, Reduce(node0)); | 112 EXPECT_CALL(r2, Reduce(node0)); |
114 EXPECT_CALL(r3, Reduce(node0)).InSequence(s1, s2, s3).WillOnce( | 113 EXPECT_CALL(r3, Reduce(node0)).InSequence(s1, s2, s3).WillOnce( |
115 Return(Reducer::Changed(node0))); | 114 Return(Reducer::Changed(node0))); |
116 EXPECT_CALL(r1, Reduce(node0)).InSequence(s1); | 115 EXPECT_CALL(r1, Reduce(node0)).InSequence(s1); |
117 EXPECT_CALL(r2, Reduce(node0)).InSequence(s2); | 116 EXPECT_CALL(r2, Reduce(node0)).InSequence(s2); |
| 117 EXPECT_CALL(r3, Reduce(node0)).InSequence(s3); |
118 ReduceNode(node0, &r1, &r2, &r3); | 118 ReduceNode(node0, &r1, &r2, &r3); |
119 } | 119 } |
120 | 120 |
121 } // namespace compiler | 121 } // namespace compiler |
122 } // namespace internal | 122 } // namespace internal |
123 } // namespace v8 | 123 } // namespace v8 |
OLD | NEW |