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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 | 156 |
| 157 void GraphReducer::Replace(Node* node, Node* replacement) { | 157 void GraphReducer::Replace(Node* node, Node* replacement) { |
| 158 Replace(node, replacement, std::numeric_limits<NodeId>::max()); | 158 Replace(node, replacement, std::numeric_limits<NodeId>::max()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 namespace { | |
| 163 | |
| 164 | |
| 165 void VerifyUseReplacement(const Edge& edge, const Node* replacement) { | |
|
Michael Starzinger
2015/09/25 10:54:18
suggestion: We could move this verification method
| |
| 166 // Check that the user does not misuse the replacement. | |
| 167 DCHECK(!NodeProperties::IsControlEdge(edge) || | |
| 168 replacement->op()->ControlOutputCount() > 0); | |
| 169 DCHECK(!NodeProperties::IsEffectEdge(edge) || | |
| 170 replacement->op()->EffectOutputCount() > 0); | |
| 171 DCHECK(!NodeProperties::IsFrameStateEdge(edge) || | |
| 172 replacement->opcode() == IrOpcode::kFrameState); | |
| 173 } | |
| 174 | |
| 175 } // namespace | |
| 176 | |
| 177 | |
| 162 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) { | 178 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) { |
| 163 if (node == graph()->start()) graph()->SetStart(replacement); | 179 if (node == graph()->start()) graph()->SetStart(replacement); |
| 164 if (node == graph()->end()) graph()->SetEnd(replacement); | 180 if (node == graph()->end()) graph()->SetEnd(replacement); |
| 165 if (replacement->id() <= max_id) { | 181 if (replacement->id() <= max_id) { |
| 166 // {replacement} is an old node, so unlink {node} and assume that | 182 // {replacement} is an old node, so unlink {node} and assume that |
| 167 // {replacement} was already reduced and finish. | 183 // {replacement} was already reduced and finish. |
| 168 for (Edge edge : node->use_edges()) { | 184 for (Edge edge : node->use_edges()) { |
| 169 Node* const user = edge.from(); | 185 Node* const user = edge.from(); |
| 186 VerifyUseReplacement(edge, replacement); | |
| 170 edge.UpdateTo(replacement); | 187 edge.UpdateTo(replacement); |
| 171 // Don't revisit this node if it refers to itself. | 188 // Don't revisit this node if it refers to itself. |
| 172 if (user != node) Revisit(user); | 189 if (user != node) Revisit(user); |
| 173 } | 190 } |
| 174 node->Kill(); | 191 node->Kill(); |
| 175 } else { | 192 } else { |
| 176 // Replace all old uses of {node} with {replacement}, but allow new nodes | 193 // Replace all old uses of {node} with {replacement}, but allow new nodes |
| 177 // created by this reduction to use {node}. | 194 // created by this reduction to use {node}. |
| 178 for (Edge edge : node->use_edges()) { | 195 for (Edge edge : node->use_edges()) { |
| 179 Node* const user = edge.from(); | 196 Node* const user = edge.from(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 void GraphReducer::Revisit(Node* node) { | 269 void GraphReducer::Revisit(Node* node) { |
| 253 if (state_.Get(node) == State::kVisited) { | 270 if (state_.Get(node) == State::kVisited) { |
| 254 state_.Set(node, State::kRevisit); | 271 state_.Set(node, State::kRevisit); |
| 255 revisit_.push(node); | 272 revisit_.push(node); |
| 256 } | 273 } |
| 257 } | 274 } |
| 258 | 275 |
| 259 } // namespace compiler | 276 } // namespace compiler |
| 260 } // namespace internal | 277 } // namespace internal |
| 261 } // namespace v8 | 278 } // namespace v8 |
| OLD | NEW |