| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/verifier.h" | 5 #include "src/compiler/verifier.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <sstream> | 10 #include <sstream> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "src/bit-vector.h" | 13 #include "src/bit-vector.h" |
| 14 #include "src/compiler/generic-algorithm.h" | 14 #include "src/compiler/all-nodes.h" |
| 15 #include "src/compiler/graph-inl.h" | |
| 16 #include "src/compiler/graph.h" | 15 #include "src/compiler/graph.h" |
| 17 #include "src/compiler/node.h" | 16 #include "src/compiler/node.h" |
| 18 #include "src/compiler/node-properties-inl.h" | 17 #include "src/compiler/node-properties-inl.h" |
| 19 #include "src/compiler/node-properties.h" | 18 #include "src/compiler/node-properties.h" |
| 20 #include "src/compiler/opcodes.h" | 19 #include "src/compiler/opcodes.h" |
| 21 #include "src/compiler/operator.h" | 20 #include "src/compiler/operator.h" |
| 22 #include "src/compiler/schedule.h" | 21 #include "src/compiler/schedule.h" |
| 23 #include "src/compiler/simplified-operator.h" | 22 #include "src/compiler/simplified-operator.h" |
| 24 #include "src/ostreams.h" | 23 #include "src/ostreams.h" |
| 25 | 24 |
| 26 namespace v8 { | 25 namespace v8 { |
| 27 namespace internal { | 26 namespace internal { |
| 28 namespace compiler { | 27 namespace compiler { |
| 29 | 28 |
| 30 | 29 |
| 31 static bool IsDefUseChainLinkPresent(Node* def, Node* use) { | 30 static bool IsDefUseChainLinkPresent(Node* def, Node* use) { |
| 32 auto const uses = def->uses(); | 31 auto const uses = def->uses(); |
| 33 return std::find(uses.begin(), uses.end(), use) != uses.end(); | 32 return std::find(uses.begin(), uses.end(), use) != uses.end(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 | 35 |
| 37 static bool IsUseDefChainLinkPresent(Node* def, Node* use) { | 36 static bool IsUseDefChainLinkPresent(Node* def, Node* use) { |
| 38 auto const inputs = use->inputs(); | 37 auto const inputs = use->inputs(); |
| 39 return std::find(inputs.begin(), inputs.end(), def) != inputs.end(); | 38 return std::find(inputs.begin(), inputs.end(), def) != inputs.end(); |
| 40 } | 39 } |
| 41 | 40 |
| 42 | 41 |
| 43 class Verifier::Visitor : public NullNodeVisitor { | 42 class Verifier::Visitor { |
| 44 public: | 43 public: |
| 45 Visitor(Zone* z, Typing typed) : zone(z), typing(typed) {} | 44 Visitor(Zone* z, Typing typed) : zone(z), typing(typed) {} |
| 46 | 45 |
| 47 // Fulfills the PreNodeCallback interface. | 46 void Check(Node* node); |
| 48 void Pre(Node* node); | |
| 49 | 47 |
| 50 Zone* zone; | 48 Zone* zone; |
| 51 Typing typing; | 49 Typing typing; |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 // TODO(rossberg): Get rid of these once we got rid of NodeProperties. | 52 // TODO(rossberg): Get rid of these once we got rid of NodeProperties. |
| 55 Bounds bounds(Node* node) { return NodeProperties::GetBounds(node); } | 53 Bounds bounds(Node* node) { return NodeProperties::GetBounds(node); } |
| 56 Node* ValueInput(Node* node, int i = 0) { | 54 Node* ValueInput(Node* node, int i = 0) { |
| 57 return NodeProperties::GetValueInput(node, i); | 55 return NodeProperties::GetValueInput(node, i); |
| 58 } | 56 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 << ") upper bound "; | 104 << ") upper bound "; |
| 107 bounds(input).upper->PrintTo(str); | 105 bounds(input).upper->PrintTo(str); |
| 108 str << " is not "; | 106 str << " is not "; |
| 109 type->PrintTo(str); | 107 type->PrintTo(str); |
| 110 V8_Fatal(__FILE__, __LINE__, str.str().c_str()); | 108 V8_Fatal(__FILE__, __LINE__, str.str().c_str()); |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 | 113 |
| 116 void Verifier::Visitor::Pre(Node* node) { | 114 void Verifier::Visitor::Check(Node* node) { |
| 117 int value_count = node->op()->ValueInputCount(); | 115 int value_count = node->op()->ValueInputCount(); |
| 118 int context_count = OperatorProperties::GetContextInputCount(node->op()); | 116 int context_count = OperatorProperties::GetContextInputCount(node->op()); |
| 119 int frame_state_count = | 117 int frame_state_count = |
| 120 OperatorProperties::GetFrameStateInputCount(node->op()); | 118 OperatorProperties::GetFrameStateInputCount(node->op()); |
| 121 int effect_count = node->op()->EffectInputCount(); | 119 int effect_count = node->op()->EffectInputCount(); |
| 122 int control_count = node->op()->ControlInputCount(); | 120 int control_count = node->op()->ControlInputCount(); |
| 123 | 121 |
| 124 // Verify number of inputs matches up. | 122 // Verify number of inputs matches up. |
| 125 int input_count = value_count + context_count + frame_state_count + | 123 int input_count = value_count + context_count + frame_state_count + |
| 126 effect_count + control_count; | 124 effect_count + control_count; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 case IrOpcode::kLoadStackPointer: | 745 case IrOpcode::kLoadStackPointer: |
| 748 case IrOpcode::kCheckedLoad: | 746 case IrOpcode::kCheckedLoad: |
| 749 case IrOpcode::kCheckedStore: | 747 case IrOpcode::kCheckedStore: |
| 750 // TODO(rossberg): Check. | 748 // TODO(rossberg): Check. |
| 751 break; | 749 break; |
| 752 } | 750 } |
| 753 } | 751 } |
| 754 | 752 |
| 755 | 753 |
| 756 void Verifier::Run(Graph* graph, Typing typing) { | 754 void Verifier::Run(Graph* graph, Typing typing) { |
| 757 Visitor visitor(graph->zone(), typing); | |
| 758 CHECK_NE(NULL, graph->start()); | 755 CHECK_NE(NULL, graph->start()); |
| 759 CHECK_NE(NULL, graph->end()); | 756 CHECK_NE(NULL, graph->end()); |
| 760 graph->VisitNodeInputsFromEnd(&visitor); | 757 Zone zone; |
| 758 Visitor visitor(&zone, typing); |
| 759 for (Node* node : AllNodes(&zone, graph).live) visitor.Check(node); |
| 761 } | 760 } |
| 762 | 761 |
| 763 | 762 |
| 764 // ----------------------------------------------------------------------------- | 763 // ----------------------------------------------------------------------------- |
| 765 | 764 |
| 766 static bool HasDominatingDef(Schedule* schedule, Node* node, | 765 static bool HasDominatingDef(Schedule* schedule, Node* node, |
| 767 BasicBlock* container, BasicBlock* use_block, | 766 BasicBlock* container, BasicBlock* use_block, |
| 768 int use_pos) { | 767 int use_pos) { |
| 769 BasicBlock* block = use_block; | 768 BasicBlock* block = use_block; |
| 770 while (true) { | 769 while (true) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 // Check inputs for all nodes in the block. | 990 // Check inputs for all nodes in the block. |
| 992 for (size_t i = 0; i < block->NodeCount(); i++) { | 991 for (size_t i = 0; i < block->NodeCount(); i++) { |
| 993 Node* node = block->NodeAt(i); | 992 Node* node = block->NodeAt(i); |
| 994 CheckInputsDominate(schedule, block, node, static_cast<int>(i) - 1); | 993 CheckInputsDominate(schedule, block, node, static_cast<int>(i) - 1); |
| 995 } | 994 } |
| 996 } | 995 } |
| 997 } | 996 } |
| 998 } | 997 } |
| 999 } | 998 } |
| 1000 } // namespace v8::internal::compiler | 999 } // namespace v8::internal::compiler |
| OLD | NEW |