Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1267)

Side by Side Diff: test/unittests/compiler/graph-reducer-unittest.cc

Issue 726513002: [turbofan] Smartify the GraphReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()); 58 GraphReducer reducer(graph(), zone());
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()); 64 GraphReducer reducer(graph(), zone());
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()); 71 GraphReducer reducer(graph(), zone());
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()));
90 EXPECT_CALL(r, Reduce(node1)).WillOnce(Return(Reducer::Replace(node2))); 91 EXPECT_CALL(r, Reduce(node1)).WillOnce(Return(Reducer::Replace(node2)));
91 ReduceNode(node1, &r); 92 ReduceNode(node1, &r);
92 EXPECT_FALSE(node0->IsDead()); 93 EXPECT_FALSE(node0->IsDead());
93 EXPECT_TRUE(node1->IsDead()); 94 EXPECT_TRUE(node1->IsDead());
94 EXPECT_FALSE(node2->IsDead()); 95 EXPECT_FALSE(node2->IsDead());
95 } 96 }
96 97
97 98
98 TEST_F(GraphReducerTest, ReduceOnceForEveryReducer) { 99 TEST_F(GraphReducerTest, ReduceOnceForEveryReducer) {
99 StrictMock<MockReducer> r1, r2; 100 StrictMock<MockReducer> r1, r2;
100 Node* node0 = graph()->NewNode(&OP0); 101 Node* node0 = graph()->NewNode(&OP0);
101 EXPECT_CALL(r1, Reduce(node0)); 102 EXPECT_CALL(r1, Reduce(node0));
102 EXPECT_CALL(r2, Reduce(node0)); 103 EXPECT_CALL(r2, Reduce(node0));
103 ReduceNode(node0, &r1, &r2); 104 ReduceNode(node0, &r1, &r2);
104 } 105 }
105 106
106 107
107 TEST_F(GraphReducerTest, ReduceAgainAfterChanged) { 108 TEST_F(GraphReducerTest, ReduceAgainAfterChanged) {
108 Sequence s1, s2, s3; 109 Sequence s1, s2, s3;
109 StrictMock<MockReducer> r1, r2, r3; 110 StrictMock<MockReducer> r1, r2, r3;
110 Node* node0 = graph()->NewNode(&OP0); 111 Node* node0 = graph()->NewNode(&OP0);
111 EXPECT_CALL(r1, Reduce(node0)); 112 EXPECT_CALL(r1, Reduce(node0));
112 EXPECT_CALL(r2, Reduce(node0)); 113 EXPECT_CALL(r2, Reduce(node0));
113 EXPECT_CALL(r3, Reduce(node0)).InSequence(s1, s2, s3).WillOnce( 114 EXPECT_CALL(r3, Reduce(node0)).InSequence(s1, s2, s3).WillOnce(
114 Return(Reducer::Changed(node0))); 115 Return(Reducer::Changed(node0)));
115 EXPECT_CALL(r1, Reduce(node0)).InSequence(s1); 116 EXPECT_CALL(r1, Reduce(node0)).InSequence(s1);
116 EXPECT_CALL(r2, Reduce(node0)).InSequence(s2); 117 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
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698