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

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

Issue 1122423003: [turbofan] Add support for advanced reducers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move comment Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/unittests/compiler/graph-reducer-unittest.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/graph-reducer-unittest.cc
diff --git a/test/unittests/compiler/graph-reducer-unittest.cc b/test/unittests/compiler/graph-reducer-unittest.cc
index ca3203e5d8a87dcedbb79a277cc674d34be5d30a..ea981ccaf3051778aeae25f8475d352428932372 100644
--- a/test/unittests/compiler/graph-reducer-unittest.cc
+++ b/test/unittests/compiler/graph-reducer-unittest.cc
@@ -3,11 +3,10 @@
// found in the LICENSE file.
#include "src/compiler/graph.h"
-#include "src/compiler/graph-reducer.h"
#include "src/compiler/node.h"
#include "src/compiler/operator.h"
+#include "test/unittests/compiler/graph-reducer-unittest.h"
#include "test/unittests/test-utils.h"
-#include "testing/gmock/include/gmock/gmock.h"
using testing::_;
using testing::DefaultValue;
@@ -55,9 +54,9 @@ struct MockReducer : public Reducer {
// Replaces all "A" operators with "B" operators without creating new nodes.
-class InPlaceABReducer : public Reducer {
+class InPlaceABReducer final : public Reducer {
public:
- virtual Reduction Reduce(Node* node) {
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
EXPECT_EQ(0, node->InputCount());
@@ -78,10 +77,11 @@ class InPlaceABReducer : public Reducer {
// Replaces all "A" operators with "B" operators by allocating new nodes.
-class NewABReducer : public Reducer {
+class NewABReducer final : public Reducer {
public:
explicit NewABReducer(Graph* graph) : graph_(graph) {}
- virtual Reduction Reduce(Node* node) {
+
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
EXPECT_EQ(0, node->InputCount());
@@ -96,7 +96,9 @@ class NewABReducer : public Reducer {
}
return NoChange();
}
- Graph* graph_;
+
+ private:
+ Graph* const graph_;
};
@@ -104,7 +106,8 @@ class NewABReducer : public Reducer {
class A0Wrapper final : public Reducer {
public:
explicit A0Wrapper(Graph* graph) : graph_(graph) {}
- virtual Reduction Reduce(Node* node) override {
+
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
EXPECT_EQ(0, node->InputCount());
@@ -112,7 +115,9 @@ class A0Wrapper final : public Reducer {
}
return NoChange();
}
- Graph* graph_;
+
+ private:
+ Graph* const graph_;
};
@@ -120,7 +125,8 @@ class A0Wrapper final : public Reducer {
class B0Wrapper final : public Reducer {
public:
explicit B0Wrapper(Graph* graph) : graph_(graph) {}
- virtual Reduction Reduce(Node* node) override {
+
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB0:
EXPECT_EQ(0, node->InputCount());
@@ -128,13 +134,16 @@ class B0Wrapper final : public Reducer {
}
return NoChange();
}
- Graph* graph_;
+
+ private:
+ Graph* const graph_;
};
// Replaces all "kOpA1" nodes with the first input.
-class A1Forwarder : public Reducer {
- virtual Reduction Reduce(Node* node) {
+class A1Forwarder final : public Reducer {
+ public:
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA1:
EXPECT_EQ(1, node->InputCount());
@@ -146,8 +155,9 @@ class A1Forwarder : public Reducer {
// Replaces all "kOpB1" nodes with the first input.
-class B1Forwarder : public Reducer {
- virtual Reduction Reduce(Node* node) {
+class B1Forwarder final : public Reducer {
+ public:
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB1:
EXPECT_EQ(1, node->InputCount());
@@ -159,9 +169,9 @@ class B1Forwarder : public Reducer {
// Replaces all "B" operators with "C" operators without creating new nodes.
-class InPlaceBCReducer : public Reducer {
+class InPlaceBCReducer final : public Reducer {
public:
- virtual Reduction Reduce(Node* node) {
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB0:
EXPECT_EQ(0, node->InputCount());
@@ -182,8 +192,9 @@ class InPlaceBCReducer : public Reducer {
// Swaps the inputs to "kOp2A" and "kOp2B" nodes based on ids.
-class AB2Sorter : public Reducer {
- virtual Reduction Reduce(Node* node) {
+class AB2Sorter final : public Reducer {
+ public:
+ Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA2:
case kOpcodeB2:
@@ -200,10 +211,59 @@ class AB2Sorter : public Reducer {
}
};
-
} // namespace
+class AdvancedReducerTest : public TestWithZone {
+ public:
+ AdvancedReducerTest() : graph_(zone()) {}
+
+ protected:
+ Graph* graph() { return &graph_; }
+
+ private:
+ Graph graph_;
+};
+
+
+TEST_F(AdvancedReducerTest, Replace) {
+ struct DummyReducer final : public AdvancedReducer {
+ explicit DummyReducer(Editor* editor) : AdvancedReducer(editor) {}
+ Reduction Reduce(Node* node) final {
+ Replace(node, node);
+ return NoChange();
+ }
+ };
+ StrictMock<MockAdvancedReducerEditor> e;
+ DummyReducer r(&e);
+ Node* node0 = graph()->NewNode(&kOpA0);
+ Node* node1 = graph()->NewNode(&kOpA1, node0);
+ EXPECT_CALL(e, Replace(node0, node0));
+ EXPECT_CALL(e, Replace(node1, node1));
+ EXPECT_FALSE(r.Reduce(node0).Changed());
+ EXPECT_FALSE(r.Reduce(node1).Changed());
+}
+
+
+TEST_F(AdvancedReducerTest, Revisit) {
+ struct DummyReducer final : public AdvancedReducer {
+ explicit DummyReducer(Editor* editor) : AdvancedReducer(editor) {}
+ Reduction Reduce(Node* node) final {
+ Revisit(node);
+ return NoChange();
+ }
+ };
+ StrictMock<MockAdvancedReducerEditor> e;
+ DummyReducer r(&e);
+ Node* node0 = graph()->NewNode(&kOpA0);
+ Node* node1 = graph()->NewNode(&kOpA1, node0);
+ EXPECT_CALL(e, Revisit(node0));
+ EXPECT_CALL(e, Revisit(node1));
+ EXPECT_FALSE(r.Reduce(node0).Changed());
+ EXPECT_FALSE(r.Reduce(node1).Changed());
+}
+
+
class GraphReducerTest : public TestWithZone {
public:
GraphReducerTest() : graph_(zone()) {}
@@ -573,6 +633,8 @@ TEST_F(GraphReducerTest, Sorter1) {
}
+namespace {
+
// Generate a node graph with the given permutations.
void GenDAG(Graph* graph, int* p3, int* p2, int* p1) {
Node* level4 = graph->NewNode(&kOpA0);
@@ -591,6 +653,8 @@ void GenDAG(Graph* graph, int* p3, int* p2, int* p1) {
graph->SetEnd(end);
}
+} // namespace
+
TEST_F(GraphReducerTest, SortForwardReduce) {
// Tests combined reductions on a series of DAGs.
@@ -667,7 +731,6 @@ TEST_F(GraphReducerTest, Order) {
}
}
-
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « test/unittests/compiler/graph-reducer-unittest.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698