| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/redundancy_elimination.h" | 5 #include "vm/redundancy_elimination.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph.h" | 8 #include "vm/flow_graph.h" |
| 9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 dependent_(other.dependent_) { | 38 dependent_(other.dependent_) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void RemoveAffected(EffectSet effects) { | 41 void RemoveAffected(EffectSet effects) { |
| 42 if (!effects.IsNone()) { | 42 if (!effects.IsNone()) { |
| 43 dependent_.Clear(); | 43 dependent_.Clear(); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 Instruction* Lookup(Instruction* other) const { | 47 Instruction* Lookup(Instruction* other) const { |
| 48 return GetMapFor(other)->Lookup(other); | 48 return GetMapFor(other)->LookupValue(other); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void Insert(Instruction* instr) { | 51 void Insert(Instruction* instr) { |
| 52 return GetMapFor(instr)->Insert(instr); | 52 return GetMapFor(instr)->Insert(instr); |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 typedef DirectChainedHashMap<PointerKeyValueTrait<Instruction> > Map; | 56 typedef DirectChainedHashMap<PointerKeyValueTrait<Instruction> > Map; |
| 57 | 57 |
| 58 Map* GetMapFor(Instruction* instr) { | 58 Map* GetMapFor(Instruction* instr) { |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 aliased_by_effects_(new(zone) BitVector(zone, places->length())) { | 700 aliased_by_effects_(new(zone) BitVector(zone, places->length())) { |
| 701 InsertAlias(Place::CreateAnyInstanceAnyIndexAlias(zone_, | 701 InsertAlias(Place::CreateAnyInstanceAnyIndexAlias(zone_, |
| 702 kAnyInstanceAnyIndexAlias)); | 702 kAnyInstanceAnyIndexAlias)); |
| 703 for (intptr_t i = 0; i < places_.length(); i++) { | 703 for (intptr_t i = 0; i < places_.length(); i++) { |
| 704 AddRepresentative(places_[i]); | 704 AddRepresentative(places_[i]); |
| 705 } | 705 } |
| 706 ComputeKillSets(); | 706 ComputeKillSets(); |
| 707 } | 707 } |
| 708 | 708 |
| 709 intptr_t LookupAliasId(const Place& alias) { | 709 intptr_t LookupAliasId(const Place& alias) { |
| 710 const Place* result = aliases_map_.Lookup(&alias); | 710 const Place* result = aliases_map_.LookupValue(&alias); |
| 711 return (result != NULL) ? result->id() : static_cast<intptr_t>(kNoAlias); | 711 return (result != NULL) ? result->id() : static_cast<intptr_t>(kNoAlias); |
| 712 } | 712 } |
| 713 | 713 |
| 714 BitVector* GetKilledSet(intptr_t alias) { | 714 BitVector* GetKilledSet(intptr_t alias) { |
| 715 return (alias < killed_.length()) ? killed_[alias] : NULL; | 715 return (alias < killed_.length()) ? killed_[alias] : NULL; |
| 716 } | 716 } |
| 717 | 717 |
| 718 intptr_t max_place_id() const { return places().length(); } | 718 intptr_t max_place_id() const { return places().length(); } |
| 719 bool IsEmpty() const { return max_place_id() == 0; } | 719 bool IsEmpty() const { return max_place_id() == 0; } |
| 720 | 720 |
| 721 BitVector* aliased_by_effects() const { return aliased_by_effects_; } | 721 BitVector* aliased_by_effects() const { return aliased_by_effects_; } |
| 722 | 722 |
| 723 const ZoneGrowableArray<Place*>& places() const { | 723 const ZoneGrowableArray<Place*>& places() const { |
| 724 return places_; | 724 return places_; |
| 725 } | 725 } |
| 726 | 726 |
| 727 Place* LookupCanonical(Place* place) const { | 727 Place* LookupCanonical(Place* place) const { |
| 728 return places_map_->Lookup(place); | 728 return places_map_->LookupValue(place); |
| 729 } | 729 } |
| 730 | 730 |
| 731 void PrintSet(BitVector* set) { | 731 void PrintSet(BitVector* set) { |
| 732 bool comma = false; | 732 bool comma = false; |
| 733 for (BitVector::Iterator it(set); | 733 for (BitVector::Iterator it(set); |
| 734 !it.Done(); | 734 !it.Done(); |
| 735 it.Advance()) { | 735 it.Advance()) { |
| 736 if (comma) { | 736 if (comma) { |
| 737 THR_Print(", "); | 737 THR_Print(", "); |
| 738 } | 738 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 } | 846 } |
| 847 | 847 |
| 848 void InsertAlias(const Place* alias) { | 848 void InsertAlias(const Place* alias) { |
| 849 aliases_map_.Insert(alias); | 849 aliases_map_.Insert(alias); |
| 850 aliases_.Add(alias); | 850 aliases_.Add(alias); |
| 851 } | 851 } |
| 852 | 852 |
| 853 const Place* CanonicalizeAlias(const Place& alias) { | 853 const Place* CanonicalizeAlias(const Place& alias) { |
| 854 const Place* canonical = aliases_map_.Lookup(&alias); | 854 const Place* canonical = aliases_map_.LookupValue(&alias); |
| 855 if (canonical == NULL) { | 855 if (canonical == NULL) { |
| 856 canonical = Place::Wrap(zone_, | 856 canonical = Place::Wrap(zone_, |
| 857 alias, | 857 alias, |
| 858 kAnyInstanceAnyIndexAlias + aliases_.length()); | 858 kAnyInstanceAnyIndexAlias + aliases_.length()); |
| 859 InsertAlias(canonical); | 859 InsertAlias(canonical); |
| 860 } | 860 } |
| 861 ASSERT(aliases_map_.Lookup(&alias) == canonical); | 861 ASSERT(aliases_map_.LookupValue(&alias) == canonical); |
| 862 return canonical; | 862 return canonical; |
| 863 } | 863 } |
| 864 | 864 |
| 865 BitVector* GetRepresentativesSet(intptr_t alias) { | 865 BitVector* GetRepresentativesSet(intptr_t alias) { |
| 866 return (alias < representatives_.length()) ? representatives_[alias] : NULL; | 866 return (alias < representatives_.length()) ? representatives_[alias] : NULL; |
| 867 } | 867 } |
| 868 | 868 |
| 869 BitVector* EnsureSet(GrowableArray<BitVector*>* sets, | 869 BitVector* EnsureSet(GrowableArray<BitVector*>* sets, |
| 870 intptr_t alias) { | 870 intptr_t alias) { |
| 871 while (sets->length() <= alias) { | 871 while (sets->length() <= alias) { |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 BlockEntryInstr* block = phi->GetBlock(); | 1227 BlockEntryInstr* block = phi->GetBlock(); |
| 1228 | 1228 |
| 1229 if (FLAG_trace_optimization) { | 1229 if (FLAG_trace_optimization) { |
| 1230 THR_Print("phi dependent place %s\n", place->ToCString()); | 1230 THR_Print("phi dependent place %s\n", place->ToCString()); |
| 1231 } | 1231 } |
| 1232 | 1232 |
| 1233 Place input_place(*place); | 1233 Place input_place(*place); |
| 1234 for (intptr_t j = 0; j < phi->InputCount(); j++) { | 1234 for (intptr_t j = 0; j < phi->InputCount(); j++) { |
| 1235 input_place.set_instance(phi->InputAt(j)->definition()); | 1235 input_place.set_instance(phi->InputAt(j)->definition()); |
| 1236 | 1236 |
| 1237 Place* result = map->Lookup(&input_place); | 1237 Place* result = map->LookupValue(&input_place); |
| 1238 if (result == NULL) { | 1238 if (result == NULL) { |
| 1239 result = Place::Wrap(zone, input_place, places->length()); | 1239 result = Place::Wrap(zone, input_place, places->length()); |
| 1240 map->Insert(result); | 1240 map->Insert(result); |
| 1241 places->Add(result); | 1241 places->Add(result); |
| 1242 if (FLAG_trace_optimization) { | 1242 if (FLAG_trace_optimization) { |
| 1243 THR_Print(" adding place %s as %" Pd "\n", | 1243 THR_Print(" adding place %s as %" Pd "\n", |
| 1244 result->ToCString(), | 1244 result->ToCString(), |
| 1245 result->id()); | 1245 result->id()); |
| 1246 } | 1246 } |
| 1247 } | 1247 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 | 1282 |
| 1283 for (ForwardInstructionIterator instr_it(block); | 1283 for (ForwardInstructionIterator instr_it(block); |
| 1284 !instr_it.Done(); | 1284 !instr_it.Done(); |
| 1285 instr_it.Advance()) { | 1285 instr_it.Advance()) { |
| 1286 Instruction* instr = instr_it.Current(); | 1286 Instruction* instr = instr_it.Current(); |
| 1287 Place place(instr, &has_loads, &has_stores); | 1287 Place place(instr, &has_loads, &has_stores); |
| 1288 if (place.kind() == Place::kNone) { | 1288 if (place.kind() == Place::kNone) { |
| 1289 continue; | 1289 continue; |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 Place* result = map->Lookup(&place); | 1292 Place* result = map->LookupValue(&place); |
| 1293 if (result == NULL) { | 1293 if (result == NULL) { |
| 1294 result = Place::Wrap(zone, place, places->length()); | 1294 result = Place::Wrap(zone, place, places->length()); |
| 1295 map->Insert(result); | 1295 map->Insert(result); |
| 1296 places->Add(result); | 1296 places->Add(result); |
| 1297 | 1297 |
| 1298 if (FLAG_trace_optimization) { | 1298 if (FLAG_trace_optimization) { |
| 1299 THR_Print("numbering %s as %" Pd "\n", | 1299 THR_Print("numbering %s as %" Pd "\n", |
| 1300 result->ToCString(), | 1300 result->ToCString(), |
| 1301 result->id()); | 1301 result->id()); |
| 1302 } | 1302 } |
| (...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3465 join->phis_ = NULL; | 3465 join->phis_ = NULL; |
| 3466 } else { | 3466 } else { |
| 3467 join->phis_->TruncateTo(to_index); | 3467 join->phis_->TruncateTo(to_index); |
| 3468 } | 3468 } |
| 3469 } | 3469 } |
| 3470 } | 3470 } |
| 3471 } | 3471 } |
| 3472 | 3472 |
| 3473 | 3473 |
| 3474 } // namespace dart | 3474 } // namespace dart |
| OLD | NEW |