From dac7c953768bb1741e8e7e72fc0e58e9414fae44 Mon Sep 17 00:00:00 2001 From: jarin Date: Mon, 28 Sep 2015 01:12:41 -0700 Subject: [PATCH] [turbofan] Move node verification methods to the Verifier class. Review URL: https://codereview.chromium.org/1367423002 Cr-Commit-Position: refs/heads/master@{#30962} --- src/compiler/graph-reducer.cc | 19 ++----------- src/compiler/graph.cc | 5 ++-- src/compiler/node-properties.cc | 51 ++------------------------------- src/compiler/node-properties.h | 11 -------- src/compiler/verifier.cc | 62 +++++++++++++++++++++++++++++++++++++++++ src/compiler/verifier.h | 24 ++++++++++++++++ 6 files changed, 92 insertions(+), 80 deletions(-) diff --git a/src/compiler/graph-reducer.cc b/src/compiler/graph-reducer.cc index cd4822d..1be0b6d 100644 --- a/src/compiler/graph-reducer.cc +++ b/src/compiler/graph-reducer.cc @@ -9,6 +9,7 @@ #include "src/compiler/graph-reducer.h" #include "src/compiler/node.h" #include "src/compiler/node-properties.h" +#include "src/compiler/verifier.h" namespace v8 { namespace internal { @@ -159,22 +160,6 @@ void GraphReducer::Replace(Node* node, Node* replacement) { } -namespace { - - -void VerifyUseReplacement(const Edge& edge, const Node* replacement) { - // Check that the user does not misuse the replacement. - DCHECK(!NodeProperties::IsControlEdge(edge) || - replacement->op()->ControlOutputCount() > 0); - DCHECK(!NodeProperties::IsEffectEdge(edge) || - replacement->op()->EffectOutputCount() > 0); - DCHECK(!NodeProperties::IsFrameStateEdge(edge) || - replacement->opcode() == IrOpcode::kFrameState); -} - -} // namespace - - void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) { if (node == graph()->start()) graph()->SetStart(replacement); if (node == graph()->end()) graph()->SetEnd(replacement); @@ -183,7 +168,7 @@ void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) { // {replacement} was already reduced and finish. for (Edge edge : node->use_edges()) { Node* const user = edge.from(); - VerifyUseReplacement(edge, replacement); + Verifier::VerifyEdgeInputReplacement(edge, replacement); edge.UpdateTo(replacement); // Don't revisit this node if it refers to itself. if (user != node) Revisit(user); diff --git a/src/compiler/graph.cc b/src/compiler/graph.cc index 7956df4..3d4d6da 100644 --- a/src/compiler/graph.cc +++ b/src/compiler/graph.cc @@ -9,6 +9,7 @@ #include "src/base/bits.h" #include "src/compiler/node.h" #include "src/compiler/node-properties.h" +#include "src/compiler/verifier.h" namespace v8 { namespace internal { @@ -45,9 +46,7 @@ void Graph::RemoveDecorator(GraphDecorator* decorator) { Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs, bool incomplete) { Node* node = NewNodeUnchecked(op, input_count, inputs, incomplete); -#ifdef DEBUG - NodeProperties::Verify(node); -#endif // DEBUG + Verifier::VerifyNode(node); return node; } diff --git a/src/compiler/node-properties.cc b/src/compiler/node-properties.cc index fffd4da..0d061a3 100644 --- a/src/compiler/node-properties.cc +++ b/src/compiler/node-properties.cc @@ -6,6 +6,7 @@ #include "src/compiler/graph.h" #include "src/compiler/node-properties.h" #include "src/compiler/operator-properties.h" +#include "src/compiler/verifier.h" namespace v8 { namespace internal { @@ -198,10 +199,7 @@ void NodeProperties::ReplaceUses(Node* node, Node* value, Node* effect, // static void NodeProperties::ChangeOp(Node* node, const Operator* new_op) { node->set_op(new_op); - -#ifdef DEBUG - Verify(node); -#endif // DEBUG + Verifier::VerifyNode(node); } @@ -271,51 +269,6 @@ void NodeProperties::CollectControlProjections(Node* node, Node** projections, // static -void NodeProperties::Verify(Node* node) { - CHECK_EQ(OperatorProperties::GetTotalInputCount(node->op()), - node->InputCount()); - // If this node has no effect or no control outputs, - // we check that no its uses are effect or control inputs. - bool check_no_control = node->op()->ControlOutputCount() == 0; - bool check_no_effect = node->op()->EffectOutputCount() == 0; - bool check_no_frame_state = node->opcode() != IrOpcode::kFrameState; - if (check_no_effect || check_no_control) { - for (Edge edge : node->use_edges()) { - Node* const user = edge.from(); - CHECK(!user->IsDead()); - if (NodeProperties::IsControlEdge(edge)) { - CHECK(!check_no_control); - } else if (NodeProperties::IsEffectEdge(edge)) { - CHECK(!check_no_effect); - } else if (NodeProperties::IsFrameStateEdge(edge)) { - CHECK(!check_no_frame_state); - } - } - } - // Frame state inputs should be frame states (or sentinels). - for (int i = 0; i < OperatorProperties::GetFrameStateInputCount(node->op()); - i++) { - Node* input = NodeProperties::GetFrameStateInput(node, i); - CHECK(input->opcode() == IrOpcode::kFrameState || - input->opcode() == IrOpcode::kStart || - input->opcode() == IrOpcode::kDead); - } - // Effect inputs should be effect-producing nodes (or sentinels). - for (int i = 0; i < node->op()->EffectInputCount(); i++) { - Node* input = NodeProperties::GetEffectInput(node, i); - CHECK(input->op()->EffectOutputCount() > 0 || - input->opcode() == IrOpcode::kDead); - } - // Control inputs should be control-producing nodes (or sentinels). - for (int i = 0; i < node->op()->ControlInputCount(); i++) { - Node* input = NodeProperties::GetControlInput(node, i); - CHECK(input->op()->ControlOutputCount() > 0 || - input->opcode() == IrOpcode::kDead); - } -} - - -// static bool NodeProperties::AllValueInputsAreTyped(Node* node) { int input_count = node->op()->ValueInputCount(); for (int index = 0; index < input_count; ++index) { diff --git a/src/compiler/node-properties.h b/src/compiler/node-properties.h index 18c6367..313d374 100644 --- a/src/compiler/node-properties.h +++ b/src/compiler/node-properties.h @@ -110,17 +110,6 @@ class NodeProperties final { // - Switch: [ IfValue, ..., IfDefault ] static void CollectControlProjections(Node* node, Node** proj, size_t count); - // Verifies consistency of node inputs and uses: - // - node inputs should agree with the input count computed from - // the node's operator. - // - effect inputs should have effect outputs. - // - control inputs should have control outputs. - // - frame state inputs should be frame states. - // - if the node has control uses, it should produce control. - // - if the node has effect uses, it should produce effect. - // - if the node has frame state uses, it must be a frame state. - static void Verify(Node* node); - // --------------------------------------------------------------------------- // Type. diff --git a/src/compiler/verifier.cc b/src/compiler/verifier.cc index 20a0d76..9e0a0da 100644 --- a/src/compiler/verifier.cc +++ b/src/compiler/verifier.cc @@ -1154,6 +1154,68 @@ void ScheduleVerifier::Run(Schedule* schedule) { } } } + + +#ifdef DEBUG + +// static +void Verifier::VerifyNode(Node* node) { + CHECK_EQ(OperatorProperties::GetTotalInputCount(node->op()), + node->InputCount()); + // If this node has no effect or no control outputs, + // we check that no its uses are effect or control inputs. + bool check_no_control = node->op()->ControlOutputCount() == 0; + bool check_no_effect = node->op()->EffectOutputCount() == 0; + bool check_no_frame_state = node->opcode() != IrOpcode::kFrameState; + if (check_no_effect || check_no_control) { + for (Edge edge : node->use_edges()) { + Node* const user = edge.from(); + CHECK(!user->IsDead()); + if (NodeProperties::IsControlEdge(edge)) { + CHECK(!check_no_control); + } else if (NodeProperties::IsEffectEdge(edge)) { + CHECK(!check_no_effect); + } else if (NodeProperties::IsFrameStateEdge(edge)) { + CHECK(!check_no_frame_state); + } + } + } + // Frame state inputs should be frame states (or sentinels). + for (int i = 0; i < OperatorProperties::GetFrameStateInputCount(node->op()); + i++) { + Node* input = NodeProperties::GetFrameStateInput(node, i); + CHECK(input->opcode() == IrOpcode::kFrameState || + input->opcode() == IrOpcode::kStart || + input->opcode() == IrOpcode::kDead); + } + // Effect inputs should be effect-producing nodes (or sentinels). + for (int i = 0; i < node->op()->EffectInputCount(); i++) { + Node* input = NodeProperties::GetEffectInput(node, i); + CHECK(input->op()->EffectOutputCount() > 0 || + input->opcode() == IrOpcode::kDead); + } + // Control inputs should be control-producing nodes (or sentinels). + for (int i = 0; i < node->op()->ControlInputCount(); i++) { + Node* input = NodeProperties::GetControlInput(node, i); + CHECK(input->op()->ControlOutputCount() > 0 || + input->opcode() == IrOpcode::kDead); + } +} + + +void Verifier::VerifyEdgeInputReplacement(const Edge& edge, + const Node* replacement) { + // Check that the user does not misuse the replacement. + DCHECK(!NodeProperties::IsControlEdge(edge) || + replacement->op()->ControlOutputCount() > 0); + DCHECK(!NodeProperties::IsEffectEdge(edge) || + replacement->op()->EffectOutputCount() > 0); + DCHECK(!NodeProperties::IsFrameStateEdge(edge) || + replacement->opcode() == IrOpcode::kFrameState); +} + +#endif // DEBUG + } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/verifier.h b/src/compiler/verifier.h index 8c5962f..cee323e 100644 --- a/src/compiler/verifier.h +++ b/src/compiler/verifier.h @@ -12,6 +12,8 @@ namespace internal { namespace compiler { class Graph; +class Edge; +class Node; class Schedule; // Verifies properties of a graph, such as the well-formedness of inputs to @@ -22,6 +24,28 @@ class Verifier { static void Run(Graph* graph, Typing typing = TYPED); +#ifdef DEBUG + // Verifies consistency of node inputs and uses: + // - node inputs should agree with the input count computed from + // the node's operator. + // - effect inputs should have effect outputs. + // - control inputs should have control outputs. + // - frame state inputs should be frame states. + // - if the node has control uses, it should produce control. + // - if the node has effect uses, it should produce effect. + // - if the node has frame state uses, it must be a frame state. + static void VerifyNode(Node* node); + + // Verify that {replacement} has the required outputs + // (effect, control or frame state) to be used as an input for {edge}. + static void VerifyEdgeInputReplacement(const Edge& edge, + const Node* replacement); +#else + static void VerifyNode(Node* node) {} + static void VerifyEdgeInputReplacement(const Edge& edge, + const Node* replacement) {} +#endif // DEBUG + private: class Visitor; DISALLOW_COPY_AND_ASSIGN(Verifier); -- 2.7.4