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

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

Issue 1188433010: [turbofan] Move graph trimming functionality to dedicated GraphTrimmer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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/cctest/compiler/test-control-reducer.cc ('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-trimmer-unittest.cc
diff --git a/test/unittests/compiler/graph-trimmer-unittest.cc b/test/unittests/compiler/graph-trimmer-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36892e6ee88bc7671162e35c6f4f4490d59a58f5
--- /dev/null
+++ b/test/unittests/compiler/graph-trimmer-unittest.cc
@@ -0,0 +1,85 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/compiler/graph-trimmer.h"
+#include "test/unittests/compiler/graph-unittest.h"
+#include "testing/gmock-support.h"
+
+using testing::ElementsAre;
+using testing::UnorderedElementsAre;
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+class GraphTrimmerTest : public GraphTest {
+ public:
+ GraphTrimmerTest() : GraphTest(1) {}
+
+ protected:
+ void TrimGraph(Node* root) {
+ Node* const roots[1] = {root};
+ GraphTrimmer trimmer(zone(), graph());
+ trimmer.TrimGraph(&roots[0], &roots[arraysize(roots)]);
+ }
+ void TrimGraph() {
+ GraphTrimmer trimmer(zone(), graph());
+ trimmer.TrimGraph();
+ }
+};
+
+
+namespace {
+
+const Operator kDead0(IrOpcode::kDead, Operator::kNoProperties, "Dead0", 0, 0,
+ 1, 0, 0, 0);
+const Operator kLive0(IrOpcode::kDead, Operator::kNoProperties, "Live0", 0, 0,
+ 1, 0, 0, 1);
+
+} // namespace
+
+
+TEST_F(GraphTrimmerTest, Empty) {
+ Node* const start = graph()->NewNode(common()->Start(0));
+ Node* const end = graph()->NewNode(common()->End(1), start);
+ graph()->SetStart(start);
+ graph()->SetEnd(end);
+ TrimGraph();
+ EXPECT_EQ(end, graph()->end());
+ EXPECT_EQ(start, graph()->start());
+ EXPECT_EQ(start, end->InputAt(0));
+}
+
+
+TEST_F(GraphTrimmerTest, DeadUseOfStart) {
+ Node* const dead0 = graph()->NewNode(&kDead0, graph()->start());
+ graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start()));
+ TrimGraph();
+ EXPECT_THAT(dead0->inputs(), ElementsAre(nullptr));
+ EXPECT_THAT(graph()->start()->uses(), ElementsAre(graph()->end()));
+}
+
+
+TEST_F(GraphTrimmerTest, DeadAndLiveUsesOfStart) {
+ Node* const dead0 = graph()->NewNode(&kDead0, graph()->start());
+ Node* const live0 = graph()->NewNode(&kLive0, graph()->start());
+ graph()->SetEnd(graph()->NewNode(common()->End(1), live0));
+ TrimGraph();
+ EXPECT_THAT(dead0->inputs(), ElementsAre(nullptr));
+ EXPECT_THAT(graph()->start()->uses(), ElementsAre(live0));
+ EXPECT_THAT(live0->uses(), ElementsAre(graph()->end()));
+}
+
+
+TEST_F(GraphTrimmerTest, Roots) {
+ Node* const live0 = graph()->NewNode(&kLive0, graph()->start());
+ Node* const live1 = graph()->NewNode(&kLive0, graph()->start());
+ graph()->SetEnd(graph()->NewNode(common()->End(1), live0));
+ TrimGraph(live1);
+ EXPECT_THAT(graph()->start()->uses(), UnorderedElementsAre(live0, live1));
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/cctest/compiler/test-control-reducer.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698