Commit 1fae6c33 authored by jkummerow's avatar jkummerow Committed by Commit bot

[cleanup] CSA: add helpers for accessing details/value via key_index

TBR=hpayer@chromium.org

Review-Url: https://codereview.chromium.org/2688573003
Cr-Commit-Position: refs/heads/master@{#43075}
parent 81239354
...@@ -239,21 +239,15 @@ TF_BUILTIN(StoreIC_Normal, CodeStubAssembler) { ...@@ -239,21 +239,15 @@ TF_BUILTIN(StoreIC_Normal, CodeStubAssembler) {
&var_name_index, &slow); &var_name_index, &slow);
Bind(&found); Bind(&found);
{ {
const int kNameToDetailsOffset = (NameDictionary::kEntryDetailsIndex - Node* details = LoadDetailsByKeyIndex<NameDictionary>(
NameDictionary::kEntryKeyIndex) * properties, var_name_index.value());
kPointerSize;
Node* details = LoadFixedArrayElement(properties, var_name_index.value(),
kNameToDetailsOffset);
// Check that the property is a writable data property (no accessor). // Check that the property is a writable data property (no accessor).
const int kTypeAndReadOnlyMask = PropertyDetails::KindField::kMask | const int kTypeAndReadOnlyMask = PropertyDetails::KindField::kMask |
PropertyDetails::kAttributesReadOnlyMask; PropertyDetails::kAttributesReadOnlyMask;
STATIC_ASSERT(kData == 0); STATIC_ASSERT(kData == 0);
GotoIf(IsSetSmi(details, kTypeAndReadOnlyMask), &slow); GotoIf(IsSetWord32(details, kTypeAndReadOnlyMask), &slow);
const int kNameToValueOffset = StoreValueByKeyIndex<NameDictionary>(properties, var_name_index.value(),
(NameDictionary::kEntryValueIndex - NameDictionary::kEntryKeyIndex) * value);
kPointerSize;
StoreFixedArrayElement(properties, var_name_index.value(), value,
UPDATE_WRITE_BARRIER, kNameToValueOffset);
Return(value); Return(value);
} }
} }
......
...@@ -4638,11 +4638,7 @@ void CodeStubAssembler::InsertEntry<NameDictionary>(Node* dictionary, ...@@ -4638,11 +4638,7 @@ void CodeStubAssembler::InsertEntry<NameDictionary>(Node* dictionary,
Node* enum_index) { Node* enum_index) {
// Store name and value. // Store name and value.
StoreFixedArrayElement(dictionary, index, name); StoreFixedArrayElement(dictionary, index, name);
const int kNameToValueOffset = StoreValueByKeyIndex<NameDictionary>(dictionary, index, value);
(NameDictionary::kEntryValueIndex - NameDictionary::kEntryKeyIndex) *
kPointerSize;
StoreFixedArrayElement(dictionary, index, value, UPDATE_WRITE_BARRIER,
kNameToValueOffset);
// Prepare details of the new property. // Prepare details of the new property.
const int kInitialIndex = 0; const int kInitialIndex = 0;
...@@ -4666,11 +4662,8 @@ void CodeStubAssembler::InsertEntry<NameDictionary>(Node* dictionary, ...@@ -4666,11 +4662,8 @@ void CodeStubAssembler::InsertEntry<NameDictionary>(Node* dictionary,
Bind(&not_private); Bind(&not_private);
// Finally, store the details. // Finally, store the details.
const int kNameToDetailsOffset = StoreDetailsByKeyIndex<NameDictionary>(dictionary, index,
(NameDictionary::kEntryDetailsIndex - NameDictionary::kEntryKeyIndex) * var_details.value());
kPointerSize;
StoreFixedArrayElement(dictionary, index, var_details.value(),
SKIP_WRITE_BARRIER, kNameToDetailsOffset);
} }
template <> template <>
...@@ -4729,7 +4722,7 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name, ...@@ -4729,7 +4722,7 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name,
Variable* var_name_index, Variable* var_name_index,
Label* if_not_found) { Label* if_not_found) {
Node* first_inclusive = IntPtrConstant(DescriptorArray::ToKeyIndex(0)); Node* first_inclusive = IntPtrConstant(DescriptorArray::ToKeyIndex(0));
Node* factor = IntPtrConstant(DescriptorArray::kDescriptorSize); Node* factor = IntPtrConstant(DescriptorArray::kEntrySize);
Node* last_exclusive = IntPtrAdd(first_inclusive, IntPtrMul(nof, factor)); Node* last_exclusive = IntPtrAdd(first_inclusive, IntPtrMul(nof, factor));
BuildFastLoop(last_exclusive, first_inclusive, BuildFastLoop(last_exclusive, first_inclusive,
...@@ -4740,7 +4733,7 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name, ...@@ -4740,7 +4733,7 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name,
var_name_index->Bind(name_index); var_name_index->Bind(name_index);
GotoIf(WordEqual(candidate_name, unique_name), if_found); GotoIf(WordEqual(candidate_name, unique_name), if_found);
}, },
-DescriptorArray::kDescriptorSize, INTPTR_PARAMETERS, -DescriptorArray::kEntrySize, INTPTR_PARAMETERS,
IndexAdvanceMode::kPre); IndexAdvanceMode::kPre);
Goto(if_not_found); Goto(if_not_found);
} }
...@@ -4848,15 +4841,8 @@ void CodeStubAssembler::LoadPropertyFromFastObject(Node* object, Node* map, ...@@ -4848,15 +4841,8 @@ void CodeStubAssembler::LoadPropertyFromFastObject(Node* object, Node* map,
DCHECK_EQ(MachineRepresentation::kTagged, var_value->rep()); DCHECK_EQ(MachineRepresentation::kTagged, var_value->rep());
Comment("[ LoadPropertyFromFastObject"); Comment("[ LoadPropertyFromFastObject");
const int name_to_details_offset = Node* details =
(DescriptorArray::kDescriptorDetails - DescriptorArray::kDescriptorKey) * LoadDetailsByKeyIndex<DescriptorArray>(descriptors, name_index);
kPointerSize;
const int name_to_value_offset =
(DescriptorArray::kDescriptorValue - DescriptorArray::kDescriptorKey) *
kPointerSize;
Node* details = LoadAndUntagToWord32FixedArrayElement(descriptors, name_index,
name_to_details_offset);
var_details->Bind(details); var_details->Bind(details);
Node* location = DecodeWord32<PropertyDetails::LocationField>(details); Node* location = DecodeWord32<PropertyDetails::LocationField>(details);
...@@ -4939,9 +4925,8 @@ void CodeStubAssembler::LoadPropertyFromFastObject(Node* object, Node* map, ...@@ -4939,9 +4925,8 @@ void CodeStubAssembler::LoadPropertyFromFastObject(Node* object, Node* map,
} }
Bind(&if_in_descriptor); Bind(&if_in_descriptor);
{ {
Node* value = var_value->Bind(
LoadFixedArrayElement(descriptors, name_index, name_to_value_offset); LoadValueByKeyIndex<DescriptorArray>(descriptors, name_index));
var_value->Bind(value);
Goto(&done); Goto(&done);
} }
Bind(&done); Bind(&done);
...@@ -4955,19 +4940,10 @@ void CodeStubAssembler::LoadPropertyFromNameDictionary(Node* dictionary, ...@@ -4955,19 +4940,10 @@ void CodeStubAssembler::LoadPropertyFromNameDictionary(Node* dictionary,
Variable* var_value) { Variable* var_value) {
Comment("LoadPropertyFromNameDictionary"); Comment("LoadPropertyFromNameDictionary");
CSA_ASSERT(this, IsDictionary(dictionary)); CSA_ASSERT(this, IsDictionary(dictionary));
const int name_to_details_offset =
(NameDictionary::kEntryDetailsIndex - NameDictionary::kEntryKeyIndex) *
kPointerSize;
const int name_to_value_offset =
(NameDictionary::kEntryValueIndex - NameDictionary::kEntryKeyIndex) *
kPointerSize;
Node* details = LoadAndUntagToWord32FixedArrayElement(dictionary, name_index, var_details->Bind(
name_to_details_offset); LoadDetailsByKeyIndex<NameDictionary>(dictionary, name_index));
var_value->Bind(LoadValueByKeyIndex<NameDictionary>(dictionary, name_index));
var_details->Bind(details);
var_value->Bind(
LoadFixedArrayElement(dictionary, name_index, name_to_value_offset));
Comment("] LoadPropertyFromNameDictionary"); Comment("] LoadPropertyFromNameDictionary");
} }
...@@ -4980,12 +4956,8 @@ void CodeStubAssembler::LoadPropertyFromGlobalDictionary(Node* dictionary, ...@@ -4980,12 +4956,8 @@ void CodeStubAssembler::LoadPropertyFromGlobalDictionary(Node* dictionary,
Comment("[ LoadPropertyFromGlobalDictionary"); Comment("[ LoadPropertyFromGlobalDictionary");
CSA_ASSERT(this, IsDictionary(dictionary)); CSA_ASSERT(this, IsDictionary(dictionary));
const int name_to_value_offset =
(GlobalDictionary::kEntryValueIndex - GlobalDictionary::kEntryKeyIndex) *
kPointerSize;
Node* property_cell = Node* property_cell =
LoadFixedArrayElement(dictionary, name_index, name_to_value_offset); LoadValueByKeyIndex<GlobalDictionary>(dictionary, name_index);
Node* value = LoadObjectField(property_cell, PropertyCell::kValueOffset); Node* value = LoadObjectField(property_cell, PropertyCell::kValueOffset);
GotoIf(WordEqual(value, TheHoleConstant()), if_deleted); GotoIf(WordEqual(value, TheHoleConstant()), if_deleted);
......
...@@ -885,6 +885,49 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -885,6 +885,49 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* EntryToIndex(Node* entry) { Node* EntryToIndex(Node* entry) {
return EntryToIndex<Dictionary>(entry, Dictionary::kEntryKeyIndex); return EntryToIndex<Dictionary>(entry, Dictionary::kEntryKeyIndex);
} }
// Loads the details for the entry with the given key_index.
// Returns an untagged int32.
template <class ContainerType>
Node* LoadDetailsByKeyIndex(Node* container, Node* key_index) {
const int kKeyToDetailsOffset =
(ContainerType::kEntryDetailsIndex - ContainerType::kEntryKeyIndex) *
kPointerSize;
return LoadAndUntagToWord32FixedArrayElement(container, key_index,
kKeyToDetailsOffset);
}
// Loads the value for the entry with the given key_index.
// Returns a tagged value.
template <class ContainerType>
Node* LoadValueByKeyIndex(Node* container, Node* key_index) {
const int kKeyToValueOffset =
(ContainerType::kEntryValueIndex - ContainerType::kEntryKeyIndex) *
kPointerSize;
return LoadFixedArrayElement(container, key_index, kKeyToValueOffset);
}
// Stores the details for the entry with the given key_index.
// |details| must be a Smi.
template <class ContainerType>
void StoreDetailsByKeyIndex(Node* container, Node* key_index, Node* details) {
const int kKeyToDetailsOffset =
(ContainerType::kEntryDetailsIndex - ContainerType::kEntryKeyIndex) *
kPointerSize;
StoreFixedArrayElement(container, key_index, details, SKIP_WRITE_BARRIER,
kKeyToDetailsOffset);
}
// Stores the value for the entry with the given key_index.
template <class ContainerType>
void StoreValueByKeyIndex(Node* container, Node* key_index, Node* value) {
const int kKeyToValueOffset =
(ContainerType::kEntryValueIndex - ContainerType::kEntryKeyIndex) *
kPointerSize;
StoreFixedArrayElement(container, key_index, value, UPDATE_WRITE_BARRIER,
kKeyToValueOffset);
}
// Calculate a valid size for the a hash table. // Calculate a valid size for the a hash table.
Node* HashTableComputeCapacity(Node* at_least_space_for); Node* HashTableComputeCapacity(Node* at_least_space_for);
......
...@@ -2708,7 +2708,7 @@ void MarkCompactCollector::TrimDescriptorArray(Map* map, ...@@ -2708,7 +2708,7 @@ void MarkCompactCollector::TrimDescriptorArray(Map* map,
int to_trim = number_of_descriptors - number_of_own_descriptors; int to_trim = number_of_descriptors - number_of_own_descriptors;
if (to_trim > 0) { if (to_trim > 0) {
heap_->RightTrimFixedArray(descriptors, heap_->RightTrimFixedArray(descriptors,
to_trim * DescriptorArray::kDescriptorSize); to_trim * DescriptorArray::kEntrySize);
descriptors->SetNumberOfDescriptors(number_of_own_descriptors); descriptors->SetNumberOfDescriptors(number_of_own_descriptors);
if (descriptors->HasEnumCache()) TrimEnumCache(map, descriptors); if (descriptors->HasEnumCache()) TrimEnumCache(map, descriptors);
......
...@@ -948,16 +948,15 @@ void AccessorAssembler::EmitElementLoad( ...@@ -948,16 +948,15 @@ void AccessorAssembler::EmitElementLoad(
elements, intptr_index, &if_found, &var_entry, if_hole); elements, intptr_index, &if_found, &var_entry, if_hole);
Bind(&if_found); Bind(&if_found);
// Check that the value is a data property. // Check that the value is a data property.
Node* details_index = EntryToIndex<SeededNumberDictionary>( Node* index = EntryToIndex<SeededNumberDictionary>(var_entry.value());
var_entry.value(), SeededNumberDictionary::kEntryDetailsIndex); Node* details =
Node* details = SmiToWord32(LoadFixedArrayElement(elements, details_index)); LoadDetailsByKeyIndex<SeededNumberDictionary>(elements, index);
Node* kind = DecodeWord32<PropertyDetails::KindField>(details); Node* kind = DecodeWord32<PropertyDetails::KindField>(details);
// TODO(jkummerow): Support accessors without missing? // TODO(jkummerow): Support accessors without missing?
GotoUnless(Word32Equal(kind, Int32Constant(kData)), miss); GotoUnless(Word32Equal(kind, Int32Constant(kData)), miss);
// Finally, load the value. // Finally, load the value.
Node* value_index = EntryToIndex<SeededNumberDictionary>( exit_point->Return(
var_entry.value(), SeededNumberDictionary::kEntryValueIndex); LoadValueByKeyIndex<SeededNumberDictionary>(elements, index));
exit_point->Return(LoadFixedArrayElement(elements, value_index));
} }
Bind(&if_typed_array); Bind(&if_typed_array);
......
...@@ -539,13 +539,8 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain( ...@@ -539,13 +539,8 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain(
{ {
Node* descriptors = var_meta_storage.value(); Node* descriptors = var_meta_storage.value();
Node* name_index = var_entry.value(); Node* name_index = var_entry.value();
// TODO(jkummerow): Add helper functions for accessing value and Node* details =
// details by entry. LoadDetailsByKeyIndex<DescriptorArray>(descriptors, name_index);
const int kNameToDetailsOffset = (DescriptorArray::kDescriptorDetails -
DescriptorArray::kDescriptorKey) *
kPointerSize;
Node* details = LoadAndUntagToWord32FixedArrayElement(
descriptors, name_index, kNameToDetailsOffset);
JumpIfDataProperty(details, &ok_to_write, readonly); JumpIfDataProperty(details, &ok_to_write, readonly);
// Accessor case. // Accessor case.
...@@ -560,19 +555,13 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain( ...@@ -560,19 +555,13 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain(
{ {
Node* dictionary = var_meta_storage.value(); Node* dictionary = var_meta_storage.value();
Node* entry = var_entry.value(); Node* entry = var_entry.value();
const int kNameToDetailsOffset = (NameDictionary::kEntryDetailsIndex - Node* details =
NameDictionary::kEntryKeyIndex) * LoadDetailsByKeyIndex<NameDictionary>(dictionary, entry);
kPointerSize;
Node* details = LoadAndUntagToWord32FixedArrayElement(
dictionary, entry, kNameToDetailsOffset);
JumpIfDataProperty(details, &ok_to_write, readonly); JumpIfDataProperty(details, &ok_to_write, readonly);
// Accessor case. // Accessor case.
const int kNameToValueOffset = (NameDictionary::kEntryValueIndex -
NameDictionary::kEntryKeyIndex) *
kPointerSize;
var_accessor_pair->Bind( var_accessor_pair->Bind(
LoadFixedArrayElement(dictionary, entry, kNameToValueOffset)); LoadValueByKeyIndex<NameDictionary>(dictionary, entry));
var_accessor_holder->Bind(holder); var_accessor_holder->Bind(holder);
Goto(accessor); Goto(accessor);
} }
...@@ -581,13 +570,8 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain( ...@@ -581,13 +570,8 @@ void KeyedStoreGenericAssembler::LookupPropertyOnPrototypeChain(
{ {
Node* dictionary = var_meta_storage.value(); Node* dictionary = var_meta_storage.value();
Node* entry = var_entry.value(); Node* entry = var_entry.value();
const int kNameToValueOffset = (GlobalDictionary::kEntryValueIndex -
GlobalDictionary::kEntryKeyIndex) *
kPointerSize;
Node* property_cell = Node* property_cell =
LoadFixedArrayElement(dictionary, entry, kNameToValueOffset); LoadValueByKeyIndex<GlobalDictionary>(dictionary, entry);
Node* value = Node* value =
LoadObjectField(property_cell, PropertyCell::kValueOffset); LoadObjectField(property_cell, PropertyCell::kValueOffset);
GotoIf(WordEqual(value, TheHoleConstant()), &next_proto); GotoIf(WordEqual(value, TheHoleConstant()), &next_proto);
...@@ -648,26 +632,20 @@ void KeyedStoreGenericAssembler::EmitGenericPropertyStore( ...@@ -648,26 +632,20 @@ void KeyedStoreGenericAssembler::EmitGenericPropertyStore(
Bind(&dictionary_found); Bind(&dictionary_found);
{ {
Label overwrite(this); Label overwrite(this);
const int kNameToDetailsOffset = (NameDictionary::kEntryDetailsIndex - Node* details = LoadDetailsByKeyIndex<NameDictionary>(
NameDictionary::kEntryKeyIndex) * properties, var_name_index.value());
kPointerSize;
Node* details = LoadAndUntagToWord32FixedArrayElement(
properties, var_name_index.value(), kNameToDetailsOffset);
JumpIfDataProperty(details, &overwrite, &readonly); JumpIfDataProperty(details, &overwrite, &readonly);
// Accessor case. // Accessor case.
const int kNameToValueOffset = var_accessor_pair.Bind(LoadValueByKeyIndex<NameDictionary>(
(NameDictionary::kEntryValueIndex - NameDictionary::kEntryKeyIndex) * properties, var_name_index.value()));
kPointerSize;
var_accessor_pair.Bind(LoadFixedArrayElement(
properties, var_name_index.value(), kNameToValueOffset));
var_accessor_holder.Bind(receiver); var_accessor_holder.Bind(receiver);
Goto(&accessor); Goto(&accessor);
Bind(&overwrite); Bind(&overwrite);
{ {
StoreFixedArrayElement(properties, var_name_index.value(), p->value, StoreValueByKeyIndex<NameDictionary>(properties, var_name_index.value(),
UPDATE_WRITE_BARRIER, kNameToValueOffset); p->value);
Return(p->value); Return(p->value);
} }
} }
......
...@@ -2833,7 +2833,7 @@ int DescriptorArray::number_of_descriptors() { ...@@ -2833,7 +2833,7 @@ int DescriptorArray::number_of_descriptors() {
int DescriptorArray::number_of_descriptors_storage() { int DescriptorArray::number_of_descriptors_storage() {
int len = length(); int len = length();
return len == 0 ? 0 : (len - kFirstIndex) / kDescriptorSize; return len == 0 ? 0 : (len - kFirstIndex) / kEntrySize;
} }
......
...@@ -3133,7 +3133,7 @@ class FrameArray : public FixedArray { ...@@ -3133,7 +3133,7 @@ class FrameArray : public FixedArray {
// [0]: pointer to fixed array with enum cache // [0]: pointer to fixed array with enum cache
// [1]: either Smi(0) or pointer to fixed array with indices // [1]: either Smi(0) or pointer to fixed array with indices
// [2]: first key // [2]: first key
// [2 + number of descriptors * kDescriptorSize]: start of slack // [2 + number of descriptors * kEntrySize]: start of slack
class DescriptorArray: public FixedArray { class DescriptorArray: public FixedArray {
public: public:
// Returns true for both shared empty_descriptor_array and for smis, which the // Returns true for both shared empty_descriptor_array and for smis, which the
...@@ -3254,10 +3254,11 @@ class DescriptorArray: public FixedArray { ...@@ -3254,10 +3254,11 @@ class DescriptorArray: public FixedArray {
static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize; static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
// Layout of descriptor. // Layout of descriptor.
static const int kDescriptorKey = 0; // Naming is consistent with Dictionary classes for easy templating.
static const int kDescriptorDetails = 1; static const int kEntryKeyIndex = 0;
static const int kDescriptorValue = 2; static const int kEntryDetailsIndex = 1;
static const int kDescriptorSize = 3; static const int kEntryValueIndex = 2;
static const int kEntrySize = 3;
#if defined(DEBUG) || defined(OBJECT_PRINT) #if defined(DEBUG) || defined(OBJECT_PRINT)
// For our gdb macros, we should perhaps change these in the future. // For our gdb macros, we should perhaps change these in the future.
...@@ -3288,18 +3289,16 @@ class DescriptorArray: public FixedArray { ...@@ -3288,18 +3289,16 @@ class DescriptorArray: public FixedArray {
} }
static int ToDetailsIndex(int descriptor_number) { static int ToDetailsIndex(int descriptor_number) {
return kFirstIndex + (descriptor_number * kDescriptorSize) + return kFirstIndex + (descriptor_number * kEntrySize) + kEntryDetailsIndex;
kDescriptorDetails;
} }
// Conversion from descriptor number to array indices. // Conversion from descriptor number to array indices.
static int ToKeyIndex(int descriptor_number) { static int ToKeyIndex(int descriptor_number) {
return kFirstIndex + (descriptor_number * kDescriptorSize) + kDescriptorKey; return kFirstIndex + (descriptor_number * kEntrySize) + kEntryKeyIndex;
} }
static int ToValueIndex(int descriptor_number) { static int ToValueIndex(int descriptor_number) {
return kFirstIndex + (descriptor_number * kDescriptorSize) + return kFirstIndex + (descriptor_number * kEntrySize) + kEntryValueIndex;
kDescriptorValue;
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment