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 #include "src/compiler/node-properties.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace compiler { | 15 namespace compiler { |
16 | 16 |
17 bool Reducer::Finish() { return true; } | 17 bool Reducer::Finish() { return true; } |
18 | 18 |
19 | 19 |
20 enum class GraphReducer::State : uint8_t { | 20 enum class GraphReducer::State : uint8_t { |
21 kUnvisited, | 21 kUnvisited, |
22 kRevisit, | 22 kRevisit, |
23 kOnStack, | 23 kOnStack, |
24 kVisited | 24 kVisited |
25 }; | 25 }; |
26 | 26 |
27 | 27 |
28 GraphReducer::GraphReducer(Graph* graph, Zone* zone) | 28 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead_value, |
| 29 Node* dead_control) |
29 : graph_(graph), | 30 : graph_(graph), |
| 31 dead_value_(dead_value), |
| 32 dead_control_(dead_control), |
30 state_(graph, 4), | 33 state_(graph, 4), |
31 reducers_(zone), | 34 reducers_(zone), |
32 revisit_(zone), | 35 revisit_(zone), |
33 stack_(zone) {} | 36 stack_(zone) {} |
34 | 37 |
35 | 38 |
36 GraphReducer::~GraphReducer() {} | 39 GraphReducer::~GraphReducer() {} |
37 | 40 |
38 | 41 |
39 void GraphReducer::AddReducer(Reducer* reducer) { | 42 void GraphReducer::AddReducer(Reducer* reducer) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (node->uses().empty()) node->Kill(); | 208 if (node->uses().empty()) node->Kill(); |
206 | 209 |
207 // If there was a replacement, reduce it after popping {node}. | 210 // If there was a replacement, reduce it after popping {node}. |
208 Recurse(replacement); | 211 Recurse(replacement); |
209 } | 212 } |
210 } | 213 } |
211 | 214 |
212 | 215 |
213 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect, | 216 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect, |
214 Node* control) { | 217 Node* control) { |
215 if (!effect && node->op()->EffectInputCount() > 0) { | 218 if (effect == nullptr && node->op()->EffectInputCount() > 0) { |
216 effect = NodeProperties::GetEffectInput(node); | 219 effect = NodeProperties::GetEffectInput(node); |
217 } | 220 } |
218 if (control == nullptr && node->op()->ControlInputCount() > 0) { | 221 if (control == nullptr && node->op()->ControlInputCount() > 0) { |
219 control = NodeProperties::GetControlInput(node); | 222 control = NodeProperties::GetControlInput(node); |
220 } | 223 } |
221 | 224 |
222 // Requires distinguishing between value, effect and control edges. | 225 // Requires distinguishing between value, effect and control edges. |
223 for (Edge edge : node->use_edges()) { | 226 for (Edge edge : node->use_edges()) { |
224 Node* user = edge.from(); | 227 Node* user = edge.from(); |
225 if (NodeProperties::IsControlEdge(edge)) { | 228 if (NodeProperties::IsControlEdge(edge)) { |
226 if (user->opcode() == IrOpcode::kIfSuccess) { | 229 if (user->opcode() == IrOpcode::kIfSuccess) { |
227 Replace(user, control); | 230 Replace(user, control); |
228 } else if (user->opcode() == IrOpcode::kIfException) { | 231 } else if (user->opcode() == IrOpcode::kIfException) { |
229 // TODO(titzer): replace with dead control from JSGraph, and | 232 for (Edge e : user->use_edges()) { |
230 // require the control reducer to propagate it. | 233 if (NodeProperties::IsValueEdge(e)) e.UpdateTo(dead_value_); |
231 UNREACHABLE(); | 234 if (NodeProperties::IsControlEdge(e)) e.UpdateTo(dead_control_); |
| 235 } |
| 236 user->Kill(); |
232 } else { | 237 } else { |
233 UNREACHABLE(); | 238 UNREACHABLE(); |
234 } | 239 } |
235 } else if (NodeProperties::IsEffectEdge(edge)) { | 240 } else if (NodeProperties::IsEffectEdge(edge)) { |
236 DCHECK_NOT_NULL(effect); | 241 DCHECK_NOT_NULL(effect); |
237 edge.UpdateTo(effect); | 242 edge.UpdateTo(effect); |
238 Revisit(user); | 243 Revisit(user); |
239 } else { | 244 } else { |
240 edge.UpdateTo(value); | 245 edge.UpdateTo(value); |
241 Revisit(user); | 246 Revisit(user); |
(...skipping 26 matching lines...) Expand all Loading... |
268 void GraphReducer::Revisit(Node* node) { | 273 void GraphReducer::Revisit(Node* node) { |
269 if (state_.Get(node) == State::kVisited) { | 274 if (state_.Get(node) == State::kVisited) { |
270 state_.Set(node, State::kRevisit); | 275 state_.Set(node, State::kRevisit); |
271 revisit_.push(node); | 276 revisit_.push(node); |
272 } | 277 } |
273 } | 278 } |
274 | 279 |
275 } // namespace compiler | 280 } // namespace compiler |
276 } // namespace internal | 281 } // namespace internal |
277 } // namespace v8 | 282 } // namespace v8 |
OLD | NEW |