From aed44ecee39e66d19c0f9788992c0578a3742ec3 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Fri, 5 Sep 2014 11:10:28 +0000 Subject: [PATCH] [turbofan] Nodes are killed by resetting all their inputs to zero. TEST=compiler-unittests,mjsunit/numops-fuzz R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/540253003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23725 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler/graph-reducer-unittest.cc | 27 ++++++++++--------- src/compiler/node.cc | 1 - src/compiler/node.h | 2 ++ .../value-numbering-reducer-unittest.cc | 8 +++--- src/compiler/value-numbering-reducer.cc | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/compiler/graph-reducer-unittest.cc b/src/compiler/graph-reducer-unittest.cc index 9dbc9ea2ad..6567203e88 100644 --- a/src/compiler/graph-reducer-unittest.cc +++ b/src/compiler/graph-reducer-unittest.cc @@ -20,7 +20,8 @@ namespace compiler { namespace { -SimpleOperator OP0(0, Operator::kNoWrite, 0, 0, "op0"); +SimpleOperator OP0(0, Operator::kNoWrite, 0, 1, "op0"); +SimpleOperator OP1(1, Operator::kNoProperties, 1, 1, "op1"); struct MockReducer : public Reducer { @@ -73,6 +74,19 @@ class GraphReducerTest : public TestWithZone { }; +TEST_F(GraphReducerTest, NodeIsDeadAfterReplace) { + StrictMock r; + Node* node0 = graph()->NewNode(&OP0); + Node* node1 = graph()->NewNode(&OP1, node0); + Node* node2 = graph()->NewNode(&OP1, node0); + EXPECT_CALL(r, Reduce(node1)).WillOnce(Return(Reducer::Replace(node2))); + ReduceNode(node1, &r); + EXPECT_FALSE(node0->IsDead()); + EXPECT_TRUE(node1->IsDead()); + EXPECT_FALSE(node2->IsDead()); +} + + TEST_F(GraphReducerTest, ReduceOnceForEveryReducer) { StrictMock r1, r2; Node* node0 = graph()->NewNode(&OP0); @@ -95,17 +109,6 @@ TEST_F(GraphReducerTest, ReduceAgainAfterChanged) { ReduceNode(node0, &r1, &r2, &r3); } - -TEST_F(GraphReducerTest, OperatorIsNullAfterReplace) { - StrictMock r; - Node* node0 = graph()->NewNode(&OP0); - Node* node1 = graph()->NewNode(&OP0); - EXPECT_CALL(r, Reduce(node0)).WillOnce(Return(Reducer::Replace(node1))); - ReduceNode(node0, &r); - EXPECT_EQ(NULL, node0->op()); - EXPECT_EQ(&OP0, node1->op()); -} - } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/node.cc b/src/compiler/node.cc index 8e5c0df215..66294bd180 100644 --- a/src/compiler/node.cc +++ b/src/compiler/node.cc @@ -14,7 +14,6 @@ void Node::Kill() { DCHECK_NOT_NULL(op()); RemoveAllInputs(); DCHECK(uses().empty()); - set_op(NULL); } diff --git a/src/compiler/node.h b/src/compiler/node.h index d8a44939f3..ac2f332210 100644 --- a/src/compiler/node.h +++ b/src/compiler/node.h @@ -53,6 +53,8 @@ class Node FINAL : public GenericNode { : GenericNode(graph, input_count) {} void Initialize(const Operator* op) { set_op(op); } + + bool IsDead() const { return InputCount() > 0 && InputAt(0) == NULL; } void Kill(); void CollectProjections(ZoneVector* projections); diff --git a/src/compiler/value-numbering-reducer-unittest.cc b/src/compiler/value-numbering-reducer-unittest.cc index 28a9856059..8db6458031 100644 --- a/src/compiler/value-numbering-reducer-unittest.cc +++ b/src/compiler/value-numbering-reducer-unittest.cc @@ -15,6 +15,7 @@ namespace compiler { namespace { const SimpleOperator kOp0(0, Operator::kNoProperties, 0, 1, "op0"); +const SimpleOperator kOp1(1, Operator::kNoProperties, 1, 1, "op1"); } // namespace @@ -44,11 +45,12 @@ TEST_F(ValueNumberingReducerTest, AllInputsAreChecked) { } -TEST_F(ValueNumberingReducerTest, KilledNodesAreNeverReturned) { - Node* n1 = graph()->NewNode(&kOp0); +TEST_F(ValueNumberingReducerTest, DeadNodesAreNeverReturned) { + Node* n0 = graph()->NewNode(&kOp0); + Node* n1 = graph()->NewNode(&kOp1, n0); EXPECT_FALSE(Reduce(n1).Changed()); n1->Kill(); - EXPECT_FALSE(Reduce(graph()->NewNode(&kOp0)).Changed()); + EXPECT_FALSE(Reduce(graph()->NewNode(&kOp1, n0)).Changed()); } diff --git a/src/compiler/value-numbering-reducer.cc b/src/compiler/value-numbering-reducer.cc index bdc9a52017..595a4f3017 100644 --- a/src/compiler/value-numbering-reducer.cc +++ b/src/compiler/value-numbering-reducer.cc @@ -59,7 +59,7 @@ ValueNumberingReducer::~ValueNumberingReducer() {} Reduction ValueNumberingReducer::Reduce(Node* node) { Entry** head = &buckets_[HashCode(node) % arraysize(buckets_)]; for (Entry* entry = *head; entry; entry = entry->next()) { - if (entry->node()->op() == NULL) continue; + if (entry->node()->IsDead()) continue; if (entry->node() == node) return NoChange(); if (Equals(node, entry->node())) { return Replace(entry->node());