| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/constant_propagator.h" | 5 #include "vm/constant_propagator.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/flow_graph_compiler.h" | 9 #include "vm/flow_graph_compiler.h" |
| 10 #include "vm/flow_graph_range_analysis.h" | 10 #include "vm/flow_graph_range_analysis.h" |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 | 1371 |
| 1372 void ConstantPropagator::EliminateRedundantBranches() { | 1372 void ConstantPropagator::EliminateRedundantBranches() { |
| 1373 // Canonicalize branches that have no side-effects and where true- and | 1373 // Canonicalize branches that have no side-effects and where true- and |
| 1374 // false-targets are the same. | 1374 // false-targets are the same. |
| 1375 bool changed = false; | 1375 bool changed = false; |
| 1376 BitVector* empty_blocks = new (Z) BitVector(Z, graph_->preorder().length()); | 1376 BitVector* empty_blocks = new (Z) BitVector(Z, graph_->preorder().length()); |
| 1377 for (BlockIterator b = graph_->postorder_iterator(); !b.Done(); b.Advance()) { | 1377 for (BlockIterator b = graph_->postorder_iterator(); !b.Done(); b.Advance()) { |
| 1378 BlockEntryInstr* block = b.Current(); | 1378 BlockEntryInstr* block = b.Current(); |
| 1379 BranchInstr* branch = block->last_instruction()->AsBranch(); | 1379 BranchInstr* branch = block->last_instruction()->AsBranch(); |
| 1380 empty_blocks->Clear(); | 1380 empty_blocks->Clear(); |
| 1381 if ((branch != NULL) && branch->Effects().IsNone()) { | 1381 if ((branch != NULL) && !branch->HasUnknownSideEffects()) { |
| 1382 ASSERT(branch->previous() != NULL); // Not already eliminated. | 1382 ASSERT(branch->previous() != NULL); // Not already eliminated. |
| 1383 BlockEntryInstr* if_true = | 1383 BlockEntryInstr* if_true = |
| 1384 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); | 1384 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); |
| 1385 BlockEntryInstr* if_false = | 1385 BlockEntryInstr* if_false = |
| 1386 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); | 1386 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); |
| 1387 if (if_true == if_false) { | 1387 if (if_true == if_false) { |
| 1388 // Replace the branch with a jump to the common successor. | 1388 // Replace the branch with a jump to the common successor. |
| 1389 // Drop the comparison, which does not have side effects | 1389 // Drop the comparison, which does not have side effects |
| 1390 JoinEntryInstr* join = if_true->AsJoinEntry(); | 1390 JoinEntryInstr* join = if_true->AsJoinEntry(); |
| 1391 if (join->phis() == NULL) { | 1391 if (join->phis() == NULL) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 GrowableArray<BitVector*> dominance_frontier; | 1572 GrowableArray<BitVector*> dominance_frontier; |
| 1573 graph_->ComputeDominators(&dominance_frontier); | 1573 graph_->ComputeDominators(&dominance_frontier); |
| 1574 | 1574 |
| 1575 if (FLAG_trace_constant_propagation && | 1575 if (FLAG_trace_constant_propagation && |
| 1576 FlowGraphPrinter::ShouldPrint(graph_->function())) { | 1576 FlowGraphPrinter::ShouldPrint(graph_->function())) { |
| 1577 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1577 FlowGraphPrinter::PrintGraph("After CP", graph_); |
| 1578 } | 1578 } |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 } // namespace dart | 1581 } // namespace dart |
| OLD | NEW |