OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/control-flow-optimizer.h" | 5 #include "src/compiler/control-flow-optimizer.h" |
6 | 6 |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 Node* cond1 = branch1->InputAt(0); | 235 Node* cond1 = branch1->InputAt(0); |
236 if (cond1->opcode() != IrOpcode::kWord32Equal) break; | 236 if (cond1->opcode() != IrOpcode::kWord32Equal) break; |
237 Int32BinopMatcher m1(cond1); | 237 Int32BinopMatcher m1(cond1); |
238 if (m1.left().node() != index) break; | 238 if (m1.left().node() != index) break; |
239 if (!m1.right().HasValue()) break; | 239 if (!m1.right().HasValue()) break; |
240 int32_t value1 = m1.right().Value(); | 240 int32_t value1 = m1.right().Value(); |
241 if (values.find(value1) != values.end()) break; | 241 if (values.find(value1) != values.end()) break; |
242 DCHECK_NE(value, value1); | 242 DCHECK_NE(value, value1); |
243 | 243 |
244 if (branch != node) { | 244 if (branch != node) { |
245 branch->RemoveAllInputs(); | 245 branch->NullAllInputs(); |
246 if_true->ReplaceInput(0, node); | 246 if_true->ReplaceInput(0, node); |
247 } | 247 } |
248 if_true->set_op(common()->IfValue(value)); | 248 if_true->set_op(common()->IfValue(value)); |
249 if_false->RemoveAllInputs(); | 249 if_false->NullAllInputs(); |
250 Enqueue(if_true); | 250 Enqueue(if_true); |
251 | 251 |
252 branch = branch1; | 252 branch = branch1; |
253 value = value1; | 253 value = value1; |
254 values.insert(value); | 254 values.insert(value); |
255 } | 255 } |
256 | 256 |
257 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); | 257 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); |
258 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); | 258 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); |
259 DCHECK_EQ(IrOpcode::kIfTrue, if_true->opcode()); | 259 DCHECK_EQ(IrOpcode::kIfTrue, if_true->opcode()); |
260 DCHECK_EQ(IrOpcode::kIfFalse, if_false->opcode()); | 260 DCHECK_EQ(IrOpcode::kIfFalse, if_false->opcode()); |
261 if (branch == node) { | 261 if (branch == node) { |
262 DCHECK_EQ(1u, values.size()); | 262 DCHECK_EQ(1u, values.size()); |
263 return false; | 263 return false; |
264 } | 264 } |
265 DCHECK_LT(1u, values.size()); | 265 DCHECK_LT(1u, values.size()); |
266 node->set_op(common()->Switch(values.size() + 1)); | 266 node->set_op(common()->Switch(values.size() + 1)); |
267 node->ReplaceInput(0, index); | 267 node->ReplaceInput(0, index); |
268 if_true->set_op(common()->IfValue(value)); | 268 if_true->set_op(common()->IfValue(value)); |
269 if_true->ReplaceInput(0, node); | 269 if_true->ReplaceInput(0, node); |
270 Enqueue(if_true); | 270 Enqueue(if_true); |
271 if_false->set_op(common()->IfDefault()); | 271 if_false->set_op(common()->IfDefault()); |
272 if_false->ReplaceInput(0, node); | 272 if_false->ReplaceInput(0, node); |
273 Enqueue(if_false); | 273 Enqueue(if_false); |
274 branch->RemoveAllInputs(); | 274 branch->NullAllInputs(); |
275 return true; | 275 return true; |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 CommonOperatorBuilder* ControlFlowOptimizer::common() const { | 279 CommonOperatorBuilder* ControlFlowOptimizer::common() const { |
280 return jsgraph()->common(); | 280 return jsgraph()->common(); |
281 } | 281 } |
282 | 282 |
283 | 283 |
284 Graph* ControlFlowOptimizer::graph() const { return jsgraph()->graph(); } | 284 Graph* ControlFlowOptimizer::graph() const { return jsgraph()->graph(); } |
285 | 285 |
286 | 286 |
287 MachineOperatorBuilder* ControlFlowOptimizer::machine() const { | 287 MachineOperatorBuilder* ControlFlowOptimizer::machine() const { |
288 return jsgraph()->machine(); | 288 return jsgraph()->machine(); |
289 } | 289 } |
290 | 290 |
291 } // namespace compiler | 291 } // namespace compiler |
292 } // namespace internal | 292 } // namespace internal |
293 } // namespace v8 | 293 } // namespace v8 |
OLD | NEW |