| 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/flow_graph_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 4694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4705 if (candidates.length() == 0) { | 4705 if (candidates.length() == 0) { |
| 4706 return; | 4706 return; |
| 4707 } | 4707 } |
| 4708 | 4708 |
| 4709 // Step 2. For each block in the graph compute which loop it belongs to. | 4709 // Step 2. For each block in the graph compute which loop it belongs to. |
| 4710 // We will use this information later during computation of the widening's | 4710 // We will use this information later during computation of the widening's |
| 4711 // gain: we are going to assume that only conversion occuring inside the | 4711 // gain: we are going to assume that only conversion occuring inside the |
| 4712 // same loop should be counted against the gain, all other conversions | 4712 // same loop should be counted against the gain, all other conversions |
| 4713 // can be hoisted and thus cost nothing compared to the loop cost itself. | 4713 // can be hoisted and thus cost nothing compared to the loop cost itself. |
| 4714 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = | 4714 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = |
| 4715 flow_graph()->loop_headers(); | 4715 flow_graph()->LoopHeaders(); |
| 4716 | 4716 |
| 4717 GrowableArray<intptr_t> loops(flow_graph_->preorder().length()); | 4717 GrowableArray<intptr_t> loops(flow_graph_->preorder().length()); |
| 4718 for (intptr_t i = 0; i < flow_graph_->preorder().length(); i++) { | 4718 for (intptr_t i = 0; i < flow_graph_->preorder().length(); i++) { |
| 4719 loops.Add(-1); | 4719 loops.Add(-1); |
| 4720 } | 4720 } |
| 4721 | 4721 |
| 4722 for (intptr_t loop_id = 0; loop_id < loop_headers.length(); ++loop_id) { | 4722 for (intptr_t loop_id = 0; loop_id < loop_headers.length(); ++loop_id) { |
| 4723 for (BitVector::Iterator loop_it(loop_headers[loop_id]->loop_info()); | 4723 for (BitVector::Iterator loop_it(loop_headers[loop_id]->loop_info()); |
| 4724 !loop_it.Done(); | 4724 !loop_it.Done(); |
| 4725 loop_it.Advance()) { | 4725 loop_it.Advance()) { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5073 | 5073 |
| 5074 | 5074 |
| 5075 void LICM::OptimisticallySpecializeSmiPhis() { | 5075 void LICM::OptimisticallySpecializeSmiPhis() { |
| 5076 if (!flow_graph()->parsed_function().function(). | 5076 if (!flow_graph()->parsed_function().function(). |
| 5077 allows_hoisting_check_class()) { | 5077 allows_hoisting_check_class()) { |
| 5078 // Do not hoist any. | 5078 // Do not hoist any. |
| 5079 return; | 5079 return; |
| 5080 } | 5080 } |
| 5081 | 5081 |
| 5082 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = | 5082 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = |
| 5083 flow_graph()->loop_headers(); | 5083 flow_graph()->LoopHeaders(); |
| 5084 | 5084 |
| 5085 for (intptr_t i = 0; i < loop_headers.length(); ++i) { | 5085 for (intptr_t i = 0; i < loop_headers.length(); ++i) { |
| 5086 JoinEntryInstr* header = loop_headers[i]->AsJoinEntry(); | 5086 JoinEntryInstr* header = loop_headers[i]->AsJoinEntry(); |
| 5087 // Skip loop that don't have a pre-header block. | 5087 // Skip loop that don't have a pre-header block. |
| 5088 BlockEntryInstr* pre_header = FindPreHeader(header); | 5088 BlockEntryInstr* pre_header = FindPreHeader(header); |
| 5089 if (pre_header == NULL) continue; | 5089 if (pre_header == NULL) continue; |
| 5090 | 5090 |
| 5091 for (PhiIterator it(header); !it.Done(); it.Advance()) { | 5091 for (PhiIterator it(header); !it.Done(); it.Advance()) { |
| 5092 TrySpecializeSmiPhi(it.Current(), header, pre_header); | 5092 TrySpecializeSmiPhi(it.Current(), header, pre_header); |
| 5093 } | 5093 } |
| 5094 } | 5094 } |
| 5095 } | 5095 } |
| 5096 | 5096 |
| 5097 | 5097 |
| 5098 void LICM::Optimize() { | 5098 void LICM::Optimize() { |
| 5099 if (!flow_graph()->parsed_function().function(). | 5099 if (!flow_graph()->parsed_function().function(). |
| 5100 allows_hoisting_check_class()) { | 5100 allows_hoisting_check_class()) { |
| 5101 // Do not hoist any. | 5101 // Do not hoist any. |
| 5102 return; | 5102 return; |
| 5103 } | 5103 } |
| 5104 | 5104 |
| 5105 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = | 5105 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = |
| 5106 flow_graph()->loop_headers(); | 5106 flow_graph()->LoopHeaders(); |
| 5107 | 5107 |
| 5108 ZoneGrowableArray<BitVector*>* loop_invariant_loads = | 5108 ZoneGrowableArray<BitVector*>* loop_invariant_loads = |
| 5109 flow_graph()->loop_invariant_loads(); | 5109 flow_graph()->loop_invariant_loads(); |
| 5110 | 5110 |
| 5111 BlockEffects* block_effects = flow_graph()->block_effects(); | 5111 BlockEffects* block_effects = flow_graph()->block_effects(); |
| 5112 | 5112 |
| 5113 for (intptr_t i = 0; i < loop_headers.length(); ++i) { | 5113 for (intptr_t i = 0; i < loop_headers.length(); ++i) { |
| 5114 BlockEntryInstr* header = loop_headers[i]; | 5114 BlockEntryInstr* header = loop_headers[i]; |
| 5115 // Skip loop that don't have a pre-header block. | 5115 // Skip loop that don't have a pre-header block. |
| 5116 BlockEntryInstr* pre_header = FindPreHeader(header); | 5116 BlockEntryInstr* pre_header = FindPreHeader(header); |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6623 BlockEntryInstr* pred = block->PredecessorAt(i); | 6623 BlockEntryInstr* pred = block->PredecessorAt(i); |
| 6624 if (pred->postorder_number() < block->postorder_number()) { | 6624 if (pred->postorder_number() < block->postorder_number()) { |
| 6625 return false; | 6625 return false; |
| 6626 } | 6626 } |
| 6627 } | 6627 } |
| 6628 return true; | 6628 return true; |
| 6629 } | 6629 } |
| 6630 | 6630 |
| 6631 void MarkLoopInvariantLoads() { | 6631 void MarkLoopInvariantLoads() { |
| 6632 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = | 6632 const ZoneGrowableArray<BlockEntryInstr*>& loop_headers = |
| 6633 graph_->loop_headers(); | 6633 graph_->LoopHeaders(); |
| 6634 | 6634 |
| 6635 ZoneGrowableArray<BitVector*>* invariant_loads = | 6635 ZoneGrowableArray<BitVector*>* invariant_loads = |
| 6636 new(I) ZoneGrowableArray<BitVector*>(loop_headers.length()); | 6636 new(I) ZoneGrowableArray<BitVector*>(loop_headers.length()); |
| 6637 | 6637 |
| 6638 for (intptr_t i = 0; i < loop_headers.length(); i++) { | 6638 for (intptr_t i = 0; i < loop_headers.length(); i++) { |
| 6639 BlockEntryInstr* header = loop_headers[i]; | 6639 BlockEntryInstr* header = loop_headers[i]; |
| 6640 BlockEntryInstr* pre_header = FindPreHeader(header); | 6640 BlockEntryInstr* pre_header = FindPreHeader(header); |
| 6641 if (pre_header == NULL) { | 6641 if (pre_header == NULL) { |
| 6642 invariant_loads->Add(NULL); | 6642 invariant_loads->Add(NULL); |
| 6643 continue; | 6643 continue; |
| (...skipping 3315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9959 | 9959 |
| 9960 // Insert materializations at environment uses. | 9960 // Insert materializations at environment uses. |
| 9961 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { | 9961 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { |
| 9962 CreateMaterializationAt( | 9962 CreateMaterializationAt( |
| 9963 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); | 9963 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); |
| 9964 } | 9964 } |
| 9965 } | 9965 } |
| 9966 | 9966 |
| 9967 | 9967 |
| 9968 } // namespace dart | 9968 } // namespace dart |
| OLD | NEW |