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 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 ASSERT(branch->previous() != NULL); // Not already eliminated. | 1544 ASSERT(branch->previous() != NULL); // Not already eliminated. |
1545 BlockEntryInstr* if_true = | 1545 BlockEntryInstr* if_true = |
1546 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); | 1546 FindFirstNonEmptySuccessor(branch->true_successor(), empty_blocks); |
1547 BlockEntryInstr* if_false = | 1547 BlockEntryInstr* if_false = |
1548 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); | 1548 FindFirstNonEmptySuccessor(branch->false_successor(), empty_blocks); |
1549 if (if_true == if_false) { | 1549 if (if_true == if_false) { |
1550 // Replace the branch with a jump to the common successor. | 1550 // Replace the branch with a jump to the common successor. |
1551 // Drop the comparison, which does not have side effects | 1551 // Drop the comparison, which does not have side effects |
1552 JoinEntryInstr* join = if_true->AsJoinEntry(); | 1552 JoinEntryInstr* join = if_true->AsJoinEntry(); |
1553 if (join->phis() == NULL) { | 1553 if (join->phis() == NULL) { |
1554 GotoInstr* jump = new (Z) GotoInstr(if_true->AsJoinEntry()); | 1554 GotoInstr* jump = |
| 1555 new (Z) GotoInstr(if_true->AsJoinEntry(), Thread::kNoDeoptId); |
1555 jump->InheritDeoptTarget(Z, branch); | 1556 jump->InheritDeoptTarget(Z, branch); |
1556 | 1557 |
1557 Instruction* previous = branch->previous(); | 1558 Instruction* previous = branch->previous(); |
1558 branch->set_previous(NULL); | 1559 branch->set_previous(NULL); |
1559 previous->LinkTo(jump); | 1560 previous->LinkTo(jump); |
1560 | 1561 |
1561 // Remove uses from branch and all the empty blocks that | 1562 // Remove uses from branch and all the empty blocks that |
1562 // are now unreachable. | 1563 // are now unreachable. |
1563 branch->UnuseAllInputs(); | 1564 branch->UnuseAllInputs(); |
1564 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) { | 1565 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 if (branch != NULL) { | 1688 if (branch != NULL) { |
1688 TargetEntryInstr* if_true = branch->true_successor(); | 1689 TargetEntryInstr* if_true = branch->true_successor(); |
1689 TargetEntryInstr* if_false = branch->false_successor(); | 1690 TargetEntryInstr* if_false = branch->false_successor(); |
1690 JoinEntryInstr* join = NULL; | 1691 JoinEntryInstr* join = NULL; |
1691 Instruction* next = NULL; | 1692 Instruction* next = NULL; |
1692 | 1693 |
1693 if (!reachable_->Contains(if_true->preorder_number())) { | 1694 if (!reachable_->Contains(if_true->preorder_number())) { |
1694 ASSERT(reachable_->Contains(if_false->preorder_number())); | 1695 ASSERT(reachable_->Contains(if_false->preorder_number())); |
1695 ASSERT(if_false->parallel_move() == NULL); | 1696 ASSERT(if_false->parallel_move() == NULL); |
1696 ASSERT(if_false->loop_info() == NULL); | 1697 ASSERT(if_false->loop_info() == NULL); |
1697 join = | 1698 join = new (Z) JoinEntryInstr( |
1698 new (Z) JoinEntryInstr(if_false->block_id(), if_false->try_index()); | 1699 if_false->block_id(), if_false->try_index(), Thread::kNoDeoptId); |
1699 join->InheritDeoptTarget(Z, if_false); | 1700 join->InheritDeoptTarget(Z, if_false); |
1700 if_false->UnuseAllInputs(); | 1701 if_false->UnuseAllInputs(); |
1701 next = if_false->next(); | 1702 next = if_false->next(); |
1702 } else if (!reachable_->Contains(if_false->preorder_number())) { | 1703 } else if (!reachable_->Contains(if_false->preorder_number())) { |
1703 ASSERT(if_true->parallel_move() == NULL); | 1704 ASSERT(if_true->parallel_move() == NULL); |
1704 ASSERT(if_true->loop_info() == NULL); | 1705 ASSERT(if_true->loop_info() == NULL); |
1705 join = | 1706 join = new (Z) JoinEntryInstr(if_true->block_id(), if_true->try_index(), |
1706 new (Z) JoinEntryInstr(if_true->block_id(), if_true->try_index()); | 1707 Thread::kNoDeoptId); |
1707 join->InheritDeoptTarget(Z, if_true); | 1708 join->InheritDeoptTarget(Z, if_true); |
1708 if_true->UnuseAllInputs(); | 1709 if_true->UnuseAllInputs(); |
1709 next = if_true->next(); | 1710 next = if_true->next(); |
1710 } | 1711 } |
1711 | 1712 |
1712 if (join != NULL) { | 1713 if (join != NULL) { |
1713 // Replace the branch with a jump to the reachable successor. | 1714 // Replace the branch with a jump to the reachable successor. |
1714 // Drop the comparison, which does not have side effects as long | 1715 // Drop the comparison, which does not have side effects as long |
1715 // as it is a strict compare (the only one we can determine is | 1716 // as it is a strict compare (the only one we can determine is |
1716 // constant with the current analysis). | 1717 // constant with the current analysis). |
1717 GotoInstr* jump = new (Z) GotoInstr(join); | 1718 GotoInstr* jump = new (Z) GotoInstr(join, Thread::kNoDeoptId); |
1718 jump->InheritDeoptTarget(Z, branch); | 1719 jump->InheritDeoptTarget(Z, branch); |
1719 | 1720 |
1720 Instruction* previous = branch->previous(); | 1721 Instruction* previous = branch->previous(); |
1721 branch->set_previous(NULL); | 1722 branch->set_previous(NULL); |
1722 previous->LinkTo(jump); | 1723 previous->LinkTo(jump); |
1723 | 1724 |
1724 // Replace the false target entry with the new join entry. We will | 1725 // Replace the false target entry with the new join entry. We will |
1725 // recompute the dominators after this pass. | 1726 // recompute the dominators after this pass. |
1726 join->LinkTo(next); | 1727 join->LinkTo(next); |
1727 branch->UnuseAllInputs(); | 1728 branch->UnuseAllInputs(); |
1728 } | 1729 } |
1729 } | 1730 } |
1730 } | 1731 } |
1731 | 1732 |
1732 graph_->DiscoverBlocks(); | 1733 graph_->DiscoverBlocks(); |
1733 graph_->MergeBlocks(); | 1734 graph_->MergeBlocks(); |
1734 GrowableArray<BitVector*> dominance_frontier; | 1735 GrowableArray<BitVector*> dominance_frontier; |
1735 graph_->ComputeDominators(&dominance_frontier); | 1736 graph_->ComputeDominators(&dominance_frontier); |
1736 | 1737 |
1737 if (FLAG_trace_constant_propagation && | 1738 if (FLAG_trace_constant_propagation && |
1738 FlowGraphPrinter::ShouldPrint(graph_->function())) { | 1739 FlowGraphPrinter::ShouldPrint(graph_->function())) { |
1739 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1740 FlowGraphPrinter::PrintGraph("After CP", graph_); |
1740 } | 1741 } |
1741 } | 1742 } |
1742 | 1743 |
1743 } // namespace dart | 1744 } // namespace dart |
OLD | NEW |