| 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 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 ASSERT(branch->previous() != NULL); // Not already eliminated. | 1468 ASSERT(branch->previous() != NULL); // Not already eliminated. |
| 1469 BlockEntryInstr* if_true = | 1469 BlockEntryInstr* if_true = |
| 1470 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); | 1470 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); |
| 1471 BlockEntryInstr* if_false = | 1471 BlockEntryInstr* if_false = |
| 1472 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); | 1472 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); |
| 1473 if (if_true == if_false) { | 1473 if (if_true == if_false) { |
| 1474 // Replace the branch with a jump to the common successor. | 1474 // Replace the branch with a jump to the common successor. |
| 1475 // Drop the comparison, which does not have side effects | 1475 // Drop the comparison, which does not have side effects |
| 1476 JoinEntryInstr* join = if_true->AsJoinEntry(); | 1476 JoinEntryInstr* join = if_true->AsJoinEntry(); |
| 1477 if (join->phis() == NULL) { | 1477 if (join->phis() == NULL) { |
| 1478 GotoInstr* jump = new(I) GotoInstr(if_true->AsJoinEntry()); | 1478 GotoInstr* jump = new(Z) GotoInstr(if_true->AsJoinEntry()); |
| 1479 jump->InheritDeoptTarget(I, branch); | 1479 jump->InheritDeoptTarget(Z, branch); |
| 1480 | 1480 |
| 1481 Instruction* previous = branch->previous(); | 1481 Instruction* previous = branch->previous(); |
| 1482 branch->set_previous(NULL); | 1482 branch->set_previous(NULL); |
| 1483 previous->LinkTo(jump); | 1483 previous->LinkTo(jump); |
| 1484 | 1484 |
| 1485 // Remove uses from branch and all the empty blocks that | 1485 // Remove uses from branch and all the empty blocks that |
| 1486 // are now unreachable. | 1486 // are now unreachable. |
| 1487 branch->UnuseAllInputs(); | 1487 branch->UnuseAllInputs(); |
| 1488 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) { | 1488 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) { |
| 1489 BlockEntryInstr* empty_block = graph_->preorder()[it.Current()]; | 1489 BlockEntryInstr* empty_block = graph_->preorder()[it.Current()]; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 if (branch != NULL) { | 1612 if (branch != NULL) { |
| 1613 TargetEntryInstr* if_true = branch->true_successor(); | 1613 TargetEntryInstr* if_true = branch->true_successor(); |
| 1614 TargetEntryInstr* if_false = branch->false_successor(); | 1614 TargetEntryInstr* if_false = branch->false_successor(); |
| 1615 JoinEntryInstr* join = NULL; | 1615 JoinEntryInstr* join = NULL; |
| 1616 Instruction* next = NULL; | 1616 Instruction* next = NULL; |
| 1617 | 1617 |
| 1618 if (!reachable_->Contains(if_true->preorder_number())) { | 1618 if (!reachable_->Contains(if_true->preorder_number())) { |
| 1619 ASSERT(reachable_->Contains(if_false->preorder_number())); | 1619 ASSERT(reachable_->Contains(if_false->preorder_number())); |
| 1620 ASSERT(if_false->parallel_move() == NULL); | 1620 ASSERT(if_false->parallel_move() == NULL); |
| 1621 ASSERT(if_false->loop_info() == NULL); | 1621 ASSERT(if_false->loop_info() == NULL); |
| 1622 join = new(I) JoinEntryInstr(if_false->block_id(), | 1622 join = new(Z) JoinEntryInstr(if_false->block_id(), |
| 1623 if_false->try_index()); | 1623 if_false->try_index()); |
| 1624 join->InheritDeoptTarget(I, if_false); | 1624 join->InheritDeoptTarget(Z, if_false); |
| 1625 if_false->UnuseAllInputs(); | 1625 if_false->UnuseAllInputs(); |
| 1626 next = if_false->next(); | 1626 next = if_false->next(); |
| 1627 } else if (!reachable_->Contains(if_false->preorder_number())) { | 1627 } else if (!reachable_->Contains(if_false->preorder_number())) { |
| 1628 ASSERT(if_true->parallel_move() == NULL); | 1628 ASSERT(if_true->parallel_move() == NULL); |
| 1629 ASSERT(if_true->loop_info() == NULL); | 1629 ASSERT(if_true->loop_info() == NULL); |
| 1630 join = new(I) JoinEntryInstr(if_true->block_id(), | 1630 join = new(Z) JoinEntryInstr(if_true->block_id(), |
| 1631 if_true->try_index()); | 1631 if_true->try_index()); |
| 1632 join->InheritDeoptTarget(I, if_true); | 1632 join->InheritDeoptTarget(Z, if_true); |
| 1633 if_true->UnuseAllInputs(); | 1633 if_true->UnuseAllInputs(); |
| 1634 next = if_true->next(); | 1634 next = if_true->next(); |
| 1635 } | 1635 } |
| 1636 | 1636 |
| 1637 if (join != NULL) { | 1637 if (join != NULL) { |
| 1638 // Replace the branch with a jump to the reachable successor. | 1638 // Replace the branch with a jump to the reachable successor. |
| 1639 // Drop the comparison, which does not have side effects as long | 1639 // Drop the comparison, which does not have side effects as long |
| 1640 // as it is a strict compare (the only one we can determine is | 1640 // as it is a strict compare (the only one we can determine is |
| 1641 // constant with the current analysis). | 1641 // constant with the current analysis). |
| 1642 GotoInstr* jump = new(I) GotoInstr(join); | 1642 GotoInstr* jump = new(Z) GotoInstr(join); |
| 1643 jump->InheritDeoptTarget(I, branch); | 1643 jump->InheritDeoptTarget(Z, branch); |
| 1644 | 1644 |
| 1645 Instruction* previous = branch->previous(); | 1645 Instruction* previous = branch->previous(); |
| 1646 branch->set_previous(NULL); | 1646 branch->set_previous(NULL); |
| 1647 previous->LinkTo(jump); | 1647 previous->LinkTo(jump); |
| 1648 | 1648 |
| 1649 // Replace the false target entry with the new join entry. We will | 1649 // Replace the false target entry with the new join entry. We will |
| 1650 // recompute the dominators after this pass. | 1650 // recompute the dominators after this pass. |
| 1651 join->LinkTo(next); | 1651 join->LinkTo(next); |
| 1652 branch->UnuseAllInputs(); | 1652 branch->UnuseAllInputs(); |
| 1653 } | 1653 } |
| 1654 } | 1654 } |
| 1655 } | 1655 } |
| 1656 | 1656 |
| 1657 graph_->DiscoverBlocks(); | 1657 graph_->DiscoverBlocks(); |
| 1658 graph_->MergeBlocks(); | 1658 graph_->MergeBlocks(); |
| 1659 GrowableArray<BitVector*> dominance_frontier; | 1659 GrowableArray<BitVector*> dominance_frontier; |
| 1660 graph_->ComputeDominators(&dominance_frontier); | 1660 graph_->ComputeDominators(&dominance_frontier); |
| 1661 | 1661 |
| 1662 if (FLAG_trace_constant_propagation) { | 1662 if (FLAG_trace_constant_propagation) { |
| 1663 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1663 FlowGraphPrinter::PrintGraph("After CP", graph_); |
| 1664 } | 1664 } |
| 1665 } | 1665 } |
| 1666 | 1666 |
| 1667 } // namespace dart | 1667 } // namespace dart |
| OLD | NEW |