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