| 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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/control-reducer.h" | 6 #include "src/compiler/control-reducer.h" |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
| 10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| 11 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 namespace compiler { | 15 namespace compiler { |
| 16 | 16 |
| 17 enum VisitState { kUnvisited, kOnStack, kRevisit, kVisited }; | 17 enum VisitState { kUnvisited, kOnStack, kRevisit, kVisited }; |
| 18 | 18 |
| 19 #define TRACE(x) \ | 19 #define TRACE(x) \ |
| 20 if (FLAG_trace_turbo) PrintF x | 20 if (FLAG_trace_turbo) PrintF x |
| 21 | 21 |
| 22 class ControlReducerImpl { | 22 class ControlReducerImpl { |
| 23 public: | 23 public: |
| 24 ControlReducerImpl(JSGraph* jsgraph, CommonOperatorBuilder* common) | 24 ControlReducerImpl(Zone* zone, JSGraph* jsgraph, |
| 25 : zone_(jsgraph->zone()->isolate()), | 25 CommonOperatorBuilder* common) |
| 26 : zone_(zone), |
| 26 jsgraph_(jsgraph), | 27 jsgraph_(jsgraph), |
| 27 common_(common), | 28 common_(common), |
| 28 state_(jsgraph->graph()->NodeCount(), kUnvisited, &zone_), | 29 state_(jsgraph->graph()->NodeCount(), kUnvisited, zone_), |
| 29 stack_(&zone_), | 30 stack_(zone_), |
| 30 revisit_(&zone_), | 31 revisit_(zone_), |
| 31 dead_(NULL) {} | 32 dead_(NULL) {} |
| 32 | 33 |
| 33 Zone zone_; | 34 Zone* zone_; |
| 34 JSGraph* jsgraph_; | 35 JSGraph* jsgraph_; |
| 35 CommonOperatorBuilder* common_; | 36 CommonOperatorBuilder* common_; |
| 36 ZoneVector<VisitState> state_; | 37 ZoneVector<VisitState> state_; |
| 37 ZoneDeque<Node*> stack_; | 38 ZoneDeque<Node*> stack_; |
| 38 ZoneDeque<Node*> revisit_; | 39 ZoneDeque<Node*> revisit_; |
| 39 Node* dead_; | 40 Node* dead_; |
| 40 | 41 |
| 41 void Trim() { | 42 void Trim() { |
| 42 // Mark all nodes reachable from end. | 43 // Mark all nodes reachable from end. |
| 43 NodeVector nodes(&zone_); | 44 NodeVector nodes(zone_); |
| 44 state_.assign(jsgraph_->graph()->NodeCount(), kUnvisited); | 45 state_.assign(jsgraph_->graph()->NodeCount(), kUnvisited); |
| 45 Push(jsgraph_->graph()->end()); | 46 Push(jsgraph_->graph()->end()); |
| 46 while (!stack_.empty()) { | 47 while (!stack_.empty()) { |
| 47 Node* node = stack_[stack_.size() - 1]; | 48 Node* node = stack_[stack_.size() - 1]; |
| 48 stack_.pop_back(); | 49 stack_.pop_back(); |
| 49 state_[node->id()] = kVisited; | 50 state_[node->id()] = kVisited; |
| 50 nodes.push_back(node); | 51 nodes.push_back(node); |
| 51 for (InputIter i = node->inputs().begin(); i != node->inputs().end(); | 52 for (InputIter i = node->inputs().begin(); i != node->inputs().end(); |
| 52 ++i) { | 53 ++i) { |
| 53 Recurse(*i); // pushes node onto the stack if necessary. | 54 Recurse(*i); // pushes node onto the stack if necessary. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 Push(node); | 98 Push(node); |
| 98 return true; | 99 return true; |
| 99 } | 100 } |
| 100 | 101 |
| 101 void Push(Node* node) { | 102 void Push(Node* node) { |
| 102 state_[node->id()] = kOnStack; | 103 state_[node->id()] = kOnStack; |
| 103 stack_.push_back(node); | 104 stack_.push_back(node); |
| 104 } | 105 } |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 void ControlReducer::ReduceGraph(JSGraph* jsgraph, | 108 void ControlReducer::ReduceGraph(Zone* zone, JSGraph* jsgraph, |
| 108 CommonOperatorBuilder* common) { | 109 CommonOperatorBuilder* common) { |
| 109 ControlReducerImpl impl(jsgraph, NULL); | 110 ControlReducerImpl impl(zone, jsgraph, NULL); |
| 110 // Only trim the graph for now. Control reduction can reduce non-terminating | 111 // Only trim the graph for now. Control reduction can reduce non-terminating |
| 111 // loops to graphs that are unschedulable at the moment. | 112 // loops to graphs that are unschedulable at the moment. |
| 112 impl.Trim(); | 113 impl.Trim(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 | 116 |
| 116 void ControlReducer::TrimGraph(JSGraph* jsgraph) { | 117 void ControlReducer::TrimGraph(Zone* zone, JSGraph* jsgraph) { |
| 117 ControlReducerImpl impl(jsgraph, NULL); | 118 ControlReducerImpl impl(zone, jsgraph, NULL); |
| 118 impl.Trim(); | 119 impl.Trim(); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 } // namespace v8::internal::compiler | 123 } // namespace v8::internal::compiler |
| OLD | NEW |