| 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" |
| 11 #include "src/compiler/node-properties.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 namespace compiler { | 15 namespace compiler { |
| 15 | 16 |
| 16 bool Reducer::Finish() { return true; } | 17 bool Reducer::Finish() { return true; } |
| 17 | 18 |
| 18 | 19 |
| 19 enum class GraphReducer::State : uint8_t { | 20 enum class GraphReducer::State : uint8_t { |
| 20 kUnvisited, | 21 kUnvisited, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 203 } |
| 203 // Unlink {node} if it's no longer used. | 204 // Unlink {node} if it's no longer used. |
| 204 if (node->uses().empty()) node->Kill(); | 205 if (node->uses().empty()) node->Kill(); |
| 205 | 206 |
| 206 // If there was a replacement, reduce it after popping {node}. | 207 // If there was a replacement, reduce it after popping {node}. |
| 207 Recurse(replacement); | 208 Recurse(replacement); |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 | 211 |
| 211 | 212 |
| 213 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect, |
| 214 Node* control) { |
| 215 if (!effect && node->op()->EffectInputCount() > 0) { |
| 216 effect = NodeProperties::GetEffectInput(node); |
| 217 } |
| 218 if (control == nullptr && node->op()->ControlInputCount() > 0) { |
| 219 control = NodeProperties::GetControlInput(node); |
| 220 } |
| 221 |
| 222 // Requires distinguishing between value, effect and control edges. |
| 223 for (Edge edge : node->use_edges()) { |
| 224 Node* user = edge.from(); |
| 225 if (NodeProperties::IsControlEdge(edge)) { |
| 226 if (user->opcode() == IrOpcode::kIfSuccess) { |
| 227 Replace(user, control); |
| 228 } else if (user->opcode() == IrOpcode::kIfException) { |
| 229 // TODO(titzer): replace with dead control from JSGraph, and |
| 230 // require the control reducer to propagate it. |
| 231 UNREACHABLE(); |
| 232 } else { |
| 233 UNREACHABLE(); |
| 234 } |
| 235 } else if (NodeProperties::IsEffectEdge(edge)) { |
| 236 DCHECK_NOT_NULL(effect); |
| 237 edge.UpdateTo(effect); |
| 238 Revisit(user); |
| 239 } else { |
| 240 edge.UpdateTo(value); |
| 241 Revisit(user); |
| 242 } |
| 243 } |
| 244 } |
| 245 |
| 246 |
| 212 void GraphReducer::Pop() { | 247 void GraphReducer::Pop() { |
| 213 Node* node = stack_.top().node; | 248 Node* node = stack_.top().node; |
| 214 state_.Set(node, State::kVisited); | 249 state_.Set(node, State::kVisited); |
| 215 stack_.pop(); | 250 stack_.pop(); |
| 216 } | 251 } |
| 217 | 252 |
| 218 | 253 |
| 219 void GraphReducer::Push(Node* const node) { | 254 void GraphReducer::Push(Node* const node) { |
| 220 DCHECK(state_.Get(node) != State::kOnStack); | 255 DCHECK(state_.Get(node) != State::kOnStack); |
| 221 state_.Set(node, State::kOnStack); | 256 state_.Set(node, State::kOnStack); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 233 void GraphReducer::Revisit(Node* node) { | 268 void GraphReducer::Revisit(Node* node) { |
| 234 if (state_.Get(node) == State::kVisited) { | 269 if (state_.Get(node) == State::kVisited) { |
| 235 state_.Set(node, State::kRevisit); | 270 state_.Set(node, State::kRevisit); |
| 236 revisit_.push(node); | 271 revisit_.push(node); |
| 237 } | 272 } |
| 238 } | 273 } |
| 239 | 274 |
| 240 } // namespace compiler | 275 } // namespace compiler |
| 241 } // namespace internal | 276 } // namespace internal |
| 242 } // namespace v8 | 277 } // namespace v8 |
| OLD | NEW |