Chromium Code Reviews| 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 <functional> | 5 #include <functional> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/graph-reducer.h" | 9 #include "src/compiler/graph-reducer.h" |
| 10 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 void GraphReducer::ReduceTop() { | 111 void GraphReducer::ReduceTop() { |
| 112 NodeState& entry = stack_.top(); | 112 NodeState& entry = stack_.top(); |
| 113 Node* node = entry.node; | 113 Node* node = entry.node; |
| 114 DCHECK(state_.Get(node) == State::kOnStack); | 114 DCHECK(state_.Get(node) == State::kOnStack); |
| 115 | 115 |
| 116 if (node->IsDead()) return Pop(); // Node was killed while on stack. | 116 if (node->IsDead()) return Pop(); // Node was killed while on stack. |
| 117 | 117 |
| 118 Node::Inputs node_inputs = node->inputs(); | |
| 119 | |
| 118 // Recurse on an input if necessary. | 120 // Recurse on an input if necessary. |
| 119 int start = entry.input_index < node->InputCount() ? entry.input_index : 0; | 121 int start = entry.input_index < node_inputs.count() ? entry.input_index : 0; |
| 120 | 122 for (int i = start; i < node_inputs.count(); ++i) { |
| 121 Node::Inputs node_inputs = node->inputs(); | 123 Node* input = node_inputs[i]; |
|
Jarin
2017/01/10 10:53:39
Nice, I like this more than the iterator-heavy stu
| |
| 122 auto node_inputs_begin = node_inputs.begin(); | |
| 123 auto node_inputs_end = node_inputs.end(); | |
| 124 DCHECK(node_inputs_end == node_inputs_begin + node->InputCount()); | |
| 125 | |
| 126 for (auto it = node_inputs_begin + start; it != node_inputs_end; ++it) { | |
| 127 Node* input = *it; | |
| 128 if (input != node && Recurse(input)) { | 124 if (input != node && Recurse(input)) { |
| 129 entry.input_index = (it - node_inputs_begin) + 1; | 125 entry.input_index = i + 1; |
| 130 return; | 126 return; |
| 131 } | 127 } |
| 132 } | 128 } |
| 133 for (auto it = node_inputs_begin; it != node_inputs_begin + start; ++it) { | 129 for (int i = 0; i < start; ++i) { |
| 134 Node* input = *it; | 130 Node* input = node_inputs[i]; |
| 135 if (input != node && Recurse(input)) { | 131 if (input != node && Recurse(input)) { |
| 136 entry.input_index = (it - node_inputs_begin) + 1; | 132 entry.input_index = i + 1; |
| 137 return; | 133 return; |
| 138 } | 134 } |
| 139 } | 135 } |
| 140 | 136 |
| 141 // Remember the max node id before reduction. | 137 // Remember the max node id before reduction. |
| 142 NodeId const max_id = static_cast<NodeId>(graph()->NodeCount() - 1); | 138 NodeId const max_id = static_cast<NodeId>(graph()->NodeCount() - 1); |
| 143 | 139 |
| 144 // All inputs should be visited or on stack. Apply reductions to node. | 140 // All inputs should be visited or on stack. Apply reductions to node. |
| 145 Reduction reduction = Reduce(node); | 141 Reduction reduction = Reduce(node); |
| 146 | 142 |
| 147 // If there was no reduction, pop {node} and continue. | 143 // If there was no reduction, pop {node} and continue. |
| 148 if (!reduction.Changed()) return Pop(); | 144 if (!reduction.Changed()) return Pop(); |
| 149 | 145 |
| 150 // Check if the reduction is an in-place update of the {node}. | 146 // Check if the reduction is an in-place update of the {node}. |
| 151 Node* const replacement = reduction.replacement(); | 147 Node* const replacement = reduction.replacement(); |
| 152 if (replacement == node) { | 148 if (replacement == node) { |
| 153 // In-place update of {node}, may need to recurse on an input. | 149 // In-place update of {node}, may need to recurse on an input. |
| 154 Node::Inputs node_inputs = node->inputs(); | 150 Node::Inputs node_inputs = node->inputs(); |
| 155 auto node_inputs_begin = node_inputs.begin(); | 151 for (int i = 0; i < node_inputs.count(); ++i) { |
| 156 auto node_inputs_end = node_inputs.end(); | 152 Node* input = node_inputs[i]; |
| 157 for (auto it = node_inputs_begin; it != node_inputs_end; ++it) { | |
| 158 Node* input = *it; | |
| 159 if (input != node && Recurse(input)) { | 153 if (input != node && Recurse(input)) { |
| 160 entry.input_index = (it - node_inputs_begin) + 1; | 154 entry.input_index = i + 1; |
| 161 return; | 155 return; |
| 162 } | 156 } |
| 163 } | 157 } |
| 164 } | 158 } |
| 165 | 159 |
| 166 // After reducing the node, pop it off the stack. | 160 // After reducing the node, pop it off the stack. |
| 167 Pop(); | 161 Pop(); |
| 168 | 162 |
| 169 // Check if we have a new replacement. | 163 // Check if we have a new replacement. |
| 170 if (replacement != node) { | 164 if (replacement != node) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 void GraphReducer::Revisit(Node* node) { | 280 void GraphReducer::Revisit(Node* node) { |
| 287 if (state_.Get(node) == State::kVisited) { | 281 if (state_.Get(node) == State::kVisited) { |
| 288 state_.Set(node, State::kRevisit); | 282 state_.Set(node, State::kRevisit); |
| 289 revisit_.push(node); | 283 revisit_.push(node); |
| 290 } | 284 } |
| 291 } | 285 } |
| 292 | 286 |
| 293 } // namespace compiler | 287 } // namespace compiler |
| 294 } // namespace internal | 288 } // namespace internal |
| 295 } // namespace v8 | 289 } // namespace v8 |
| OLD | NEW |