diff --git a/src/ast-numbering.cc b/src/ast-numbering.cc index 8676eeb995e..1f3268ca29f 100644 --- a/src/ast-numbering.cc +++ b/src/ast-numbering.cc @@ -15,7 +15,7 @@ class AstNumberingVisitor final : public AstVisitor { : AstVisitor(), next_id_(BailoutId::FirstUsable().ToInt()), properties_(zone), - ic_slot_cache_(4), + ic_slot_cache_(zone), dont_optimize_reason_(kNoReason) { InitializeAstVisitor(isolate, zone); } diff --git a/src/ast.cc b/src/ast.cc index 9dd825a6f96..624d462323a 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -102,7 +102,7 @@ void VariableProxy::SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, ICSlotCache* cache) { variable_feedback_slot_ = slot; if (var()->IsUnallocated()) { - cache->Add(VariableICSlotPair(var(), slot)); + cache->Put(var(), slot); } } @@ -113,12 +113,11 @@ FeedbackVectorRequirements VariableProxy::ComputeFeedbackRequirements( // VariableProxies that point to the same Variable within a function can // make their loads from the same IC slot. if (var()->IsUnallocated()) { - for (int i = 0; i < cache->length(); i++) { - VariableICSlotPair& pair = cache->at(i); - if (pair.variable() == var()) { - variable_feedback_slot_ = pair.slot(); - return FeedbackVectorRequirements(0, 0); - } + ZoneHashMap::Entry* entry = cache->Get(var()); + if (entry != NULL) { + variable_feedback_slot_ = FeedbackVectorICSlot( + static_cast(reinterpret_cast(entry->value))); + return FeedbackVectorRequirements(0, 0); } } return FeedbackVectorRequirements(0, 1); diff --git a/src/ast.h b/src/ast.h index f9d7af1e0d7..b9e79270da1 100644 --- a/src/ast.h +++ b/src/ast.h @@ -152,25 +152,29 @@ class FeedbackVectorRequirements { }; -class VariableICSlotPair final { +class ICSlotCache { public: - VariableICSlotPair(Variable* variable, FeedbackVectorICSlot slot) - : variable_(variable), slot_(slot) {} - VariableICSlotPair() - : variable_(NULL), slot_(FeedbackVectorICSlot::Invalid()) {} + explicit ICSlotCache(Zone* zone) + : zone_(zone), + hash_map_(HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity, + ZoneAllocationPolicy(zone)) {} - Variable* variable() const { return variable_; } - FeedbackVectorICSlot slot() const { return slot_; } + void Put(Variable* variable, FeedbackVectorICSlot slot) { + ZoneHashMap::Entry* entry = hash_map_.LookupOrInsert( + variable, ComputePointerHash(variable), ZoneAllocationPolicy(zone_)); + entry->value = reinterpret_cast(slot.ToInt()); + } + + ZoneHashMap::Entry* Get(Variable* variable) const { + return hash_map_.Lookup(variable, ComputePointerHash(variable)); + } private: - Variable* variable_; - FeedbackVectorICSlot slot_; + Zone* zone_; + ZoneHashMap hash_map_; }; -typedef List ICSlotCache; - - class AstProperties final BASE_EMBEDDED { public: enum Flag { diff --git a/src/hashmap.h b/src/hashmap.h index 688fc2cf369..ee3797fe594 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -43,7 +43,7 @@ class TemplateHashMapImpl { // If an entry with matching key is found, returns that entry. // Otherwise, NULL is returned. - Entry* Lookup(void* key, uint32_t hash); + Entry* Lookup(void* key, uint32_t hash) const; // If an entry with matching key is found, returns that entry. // If no matching entry is found, a new entry is inserted with @@ -90,7 +90,7 @@ class TemplateHashMapImpl { uint32_t occupancy_; Entry* map_end() const { return map_ + capacity_; } - Entry* Probe(void* key, uint32_t hash); + Entry* Probe(void* key, uint32_t hash) const; void Initialize(uint32_t capacity, AllocationPolicy allocator); void Resize(AllocationPolicy allocator); }; @@ -113,7 +113,7 @@ TemplateHashMapImpl::~TemplateHashMapImpl() { template typename TemplateHashMapImpl::Entry* -TemplateHashMapImpl::Lookup(void* key, uint32_t hash) { +TemplateHashMapImpl::Lookup(void* key, uint32_t hash) const { Entry* p = Probe(key, hash); return p->key != NULL ? p : NULL; } @@ -242,7 +242,7 @@ typename TemplateHashMapImpl::Entry* template typename TemplateHashMapImpl::Entry* -TemplateHashMapImpl::Probe(void* key, uint32_t hash) { +TemplateHashMapImpl::Probe(void* key, uint32_t hash) const { DCHECK(key != NULL); DCHECK(base::bits::IsPowerOfTwo32(capacity_));