Chromium Code Reviews| 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 7187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7198 | 7198 |
| 7199 // At this point worklist contains pairs of equal phis. Replace the first | 7199 // At this point worklist contains pairs of equal phis. Replace the first |
| 7200 // phi in the pair with the second. | 7200 // phi in the pair with the second. |
| 7201 for (intptr_t i = 0; i < worklist_.length(); i += 2) { | 7201 for (intptr_t i = 0; i < worklist_.length(); i += 2) { |
| 7202 PhiInstr* a = worklist_[i]; | 7202 PhiInstr* a = worklist_[i]; |
| 7203 PhiInstr* b = worklist_[i + 1]; | 7203 PhiInstr* b = worklist_[i + 1]; |
| 7204 a->ReplaceUsesWith(b); | 7204 a->ReplaceUsesWith(b); |
| 7205 if (a->is_alive()) { | 7205 if (a->is_alive()) { |
| 7206 a->mark_dead(); | 7206 a->mark_dead(); |
| 7207 a->block()->RemovePhi(a); | 7207 a->block()->RemovePhi(a); |
| 7208 a->UnuseAllInputs(); | |
| 7208 } | 7209 } |
| 7209 } | 7210 } |
| 7210 | |
| 7211 return true; | 7211 return true; |
| 7212 } | 7212 } |
| 7213 | 7213 |
| 7214 // Insert the given phi into the graph. Attempt to find an equal one in the | 7214 // Insert the given phi into the graph. Attempt to find an equal one in the |
| 7215 // target block first. | 7215 // target block first. |
| 7216 // Returns true if the phi was inserted and false if it was replaced. | 7216 // Returns true if the phi was inserted and false if it was replaced. |
| 7217 bool EmitPhi(PhiInstr* phi) { | 7217 bool EmitPhi(PhiInstr* phi) { |
| 7218 for (PhiIterator it(phi->block()); !it.Done(); it.Advance()) { | 7218 for (PhiIterator it(phi->block()); !it.Done(); it.Advance()) { |
| 7219 if (ReplacePhiWith(phi, it.Current())) { | 7219 if (ReplacePhiWith(phi, it.Current())) { |
| 7220 return false; | 7220 return false; |
| 7221 } | 7221 } |
| 7222 } | 7222 } |
| 7223 | 7223 |
| 7224 phi->mark_alive(); | 7224 phi->mark_alive(); |
| 7225 phi->block()->InsertPhi(phi); | 7225 phi->block()->InsertPhi(phi); |
| 7226 return true; | 7226 return true; |
| 7227 } | 7227 } |
| 7228 | 7228 |
| 7229 // Phis have not yet been inserted into the graph but they have uses of | 7229 // Phis have not yet been inserted into the graph but they have uses of |
| 7230 // their inputs. Insert the non-redundant ones and clear the input uses | 7230 // their inputs. Insert the non-redundant ones and clear the input uses |
| 7231 // of the redundant ones. | 7231 // of the redundant ones. |
| 7232 void EmitPhis() { | 7232 void EmitPhis() { |
| 7233 // First eliminate all redundant phis. | 7233 // First eliminate all redundant phis. |
| 7234 for (intptr_t i = 0; i < phis_.length(); i++) { | 7234 for (intptr_t i = 0; i < phis_.length(); i++) { |
| 7235 PhiInstr* phi = phis_[i]; | 7235 PhiInstr* phi = phis_[i]; |
| 7236 if (!phi->HasUses() || EliminateRedundantPhi(phi)) { | 7236 if (!phi->HasUses() || EliminateRedundantPhi(phi)) { |
| 7237 for (intptr_t j = phi->InputCount() - 1; j >= 0; --j) { | 7237 for (intptr_t j = phi->InputCount() - 1; j >= 0; --j) { |
|
Vyacheslav Egorov (Google)
2014/06/10 17:22:28
Maybe here UnuseAllInputs() too instead of manual
Florian Schneider
2014/06/11 10:23:33
Done.
| |
| 7238 phi->InputAt(j)->RemoveFromUseList(); | 7238 phi->InputAt(j)->RemoveFromUseList(); |
| 7239 } | 7239 } |
| 7240 phis_[i] = NULL; | 7240 phis_[i] = NULL; |
| 7241 } | 7241 } |
| 7242 } | 7242 } |
| 7243 | 7243 |
| 7244 // Now emit phis or replace them with equal phis already present in the | 7244 // Now emit phis or replace them with equal phis already present in the |
| 7245 // graph. | 7245 // graph. |
| 7246 for (intptr_t i = 0; i < phis_.length(); i++) { | 7246 for (intptr_t i = 0; i < phis_.length(); i++) { |
| 7247 PhiInstr* phi = phis_[i]; | 7247 PhiInstr* phi = phis_[i]; |
| 7248 if ((phi != NULL) && (!phi->HasUses() || !EmitPhi(phi))) { | 7248 if ((phi != NULL) && (!phi->HasUses() || !EmitPhi(phi))) { |
| 7249 for (intptr_t j = phi->InputCount() - 1; j >= 0; --j) { | 7249 for (intptr_t j = phi->InputCount() - 1; j >= 0; --j) { |
|
Vyacheslav Egorov (Google)
2014/06/10 17:22:28
ditto
Florian Schneider
2014/06/11 10:23:33
Done.
| |
| 7250 phi->InputAt(j)->RemoveFromUseList(); | 7250 phi->InputAt(j)->RemoveFromUseList(); |
| 7251 } | 7251 } |
| 7252 } | 7252 } |
| 7253 } | 7253 } |
| 7254 } | 7254 } |
| 7255 | 7255 |
| 7256 ZoneGrowableArray<Definition*>* CreateBlockOutValues() { | 7256 ZoneGrowableArray<Definition*>* CreateBlockOutValues() { |
| 7257 ZoneGrowableArray<Definition*>* out = | 7257 ZoneGrowableArray<Definition*>* out = |
| 7258 new(isolate()) ZoneGrowableArray<Definition*>( | 7258 new(isolate()) ZoneGrowableArray<Definition*>( |
| 7259 aliased_set_->max_place_id()); | 7259 aliased_set_->max_place_id()); |
| (...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9857 } | 9857 } |
| 9858 | 9858 |
| 9859 // Insert materializations at environment uses. | 9859 // Insert materializations at environment uses. |
| 9860 for (intptr_t i = 0; i < exits.length(); i++) { | 9860 for (intptr_t i = 0; i < exits.length(); i++) { |
| 9861 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *slots); | 9861 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *slots); |
| 9862 } | 9862 } |
| 9863 } | 9863 } |
| 9864 | 9864 |
| 9865 | 9865 |
| 9866 } // namespace dart | 9866 } // namespace dart |
| OLD | NEW |