v8/test/unittests/compiler/graph-trimmer-unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.5 KiB
C++
Raw Normal View History

// 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 {
[turbofan] Proper dead code elimination as regular reducer. The three different concerns that the ControlReducer used to deal with are now properly separated into a.) DeadCodeElimination, which is a regular AdvancedReducer, that propagates Dead via control edges, b.) CommonOperatorReducer, which does strength reduction on common operators (i.e. Branch, Phi, and friends), and c.) GraphTrimming, which removes dead->live edges from the graph. This will make it possible to run the DeadCodeElimination together with other passes that actually introduce Dead nodes, i.e. typed lowering; and it opens the door for general inlining without two stage fix point iteration. To make the DeadCodeElimination easier and more uniform, we basically reverted the introduction of DeadValue and DeadEffect, and changed the Dead operator to produce control, value and effect. Note however that this is not a requirement, but merely a way to make dead propagation easier and more uniform. We could always go back and decide to have different Dead operators if some other change requires that. Note that there are several additional opportunities for cleanup now, i.e. OSR deconstruction could be a regular reducer now, and we don't need to use TheHole as dead value marker in the GraphReducer. And we can actually run the dead code elimination together with the other passes instead of using separate passes over the graph. We will do this in follow up CLs. R=jarin@chromium.org, mstarzinger@chromium.org Review URL: https://codereview.chromium.org/1193833002 Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
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