Commit a72380f8 authored by jgruber's avatar jgruber Committed by Commit bot

[stubs] Add LoadFixedArrayElements with int index

The overload simply wraps creation of an IntPtrConstant and makes things more
readable.

Review-Url: https://codereview.chromium.org/2541843006
Cr-Commit-Position: refs/heads/master@{#41430}
parent 4e55cbf7
......@@ -233,8 +233,7 @@ void Builtins::Generate_FastArrayPush(compiler::CodeAssemblerState* state) {
// guaranteed to stay the first property.
Node* descriptors = assembler.LoadMapDescriptors(map);
Node* details = assembler.LoadFixedArrayElement(
descriptors,
assembler.Int32Constant(DescriptorArray::ToDetailsIndex(0)));
descriptors, DescriptorArray::ToDetailsIndex(0));
mask = READ_ONLY << PropertyDetails::AttributesField::kShift;
Node* mask_node = assembler.SmiConstant(mask);
test = assembler.WordAnd(details, mask_node);
......
......@@ -226,26 +226,18 @@ void StoreLastIndex(CodeStubAssembler* a, Node* context, Node* regexp,
}
}
Node* LoadMatchInfoField(CodeStubAssembler* a, Node* const match_info,
const int index) {
const ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS;
Node* const result =
a->LoadFixedArrayElement(match_info, a->IntPtrConstant(index), 0, mode);
return result;
}
Node* ConstructNewResultFromMatchInfo(Isolate* isolate, CodeStubAssembler* a,
Node* context, Node* match_info,
Node* string) {
CLabel out(a);
Node* const num_indices = a->SmiUntag(LoadMatchInfoField(
a, match_info, RegExpMatchInfo::kNumberOfCapturesIndex));
Node* const num_indices = a->SmiUntag(a->LoadFixedArrayElement(
match_info, RegExpMatchInfo::kNumberOfCapturesIndex));
Node* const num_results = a->SmiTag(a->WordShr(num_indices, 1));
Node* const start =
LoadMatchInfoField(a, match_info, RegExpMatchInfo::kFirstCaptureIndex);
Node* const end = LoadMatchInfoField(a, match_info,
RegExpMatchInfo::kFirstCaptureIndex + 1);
a->LoadFixedArrayElement(match_info, RegExpMatchInfo::kFirstCaptureIndex);
Node* const end = a->LoadFixedArrayElement(
match_info, RegExpMatchInfo::kFirstCaptureIndex + 1);
// Calculate the substring of the first match before creating the result array
// to avoid an unnecessary write barrier storing the first result.
......@@ -420,8 +412,8 @@ Node* RegExpPrototypeExecBodyWithoutResult(
a->GotoUnless(should_update_last_index, &out);
// Update the new last index from {match_indices}.
Node* const new_lastindex = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* const new_lastindex = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
StoreLastIndex(a, context, regexp, new_lastindex, is_fastpath);
a->Goto(&out);
......@@ -1389,10 +1381,10 @@ void RegExpPrototypeMatchBody(CodeStubAssembler* a, Node* const receiver,
Node* const match_indices = RegExpPrototypeExecBodyWithoutResult(
a, context, regexp, string, &if_didnotmatch, true);
Node* const match_from = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex);
Node* const match_to = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* const match_from = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex);
Node* const match_to = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* match = a->SubString(context, string, match_from, match_to);
var_match.Bind(match);
......@@ -1414,9 +1406,7 @@ void RegExpPrototypeMatchBody(CodeStubAssembler* a, Node* const receiver,
a->Bind(&fast_result);
{
Node* const result_fixed_array = a->LoadElements(result);
const ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS;
Node* const match =
a->LoadFixedArrayElement(result_fixed_array, int_zero, 0, mode);
Node* const match = a->LoadFixedArrayElement(result_fixed_array, 0);
// The match is guaranteed to be a string on the fast path.
CSA_ASSERT(a, a->IsStringInstanceType(a->LoadInstanceType(match)));
......@@ -1534,8 +1524,8 @@ void RegExpPrototypeSearchBodyFast(CodeStubAssembler* a, Node* const receiver,
FastStoreLastIndex(a, receiver, previous_last_index);
// Return the index of the match.
Node* const index = LoadMatchInfoField(a, match_indices,
RegExpMatchInfo::kFirstCaptureIndex);
Node* const index = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex);
a->Return(index);
}
......@@ -1763,8 +1753,8 @@ void Generate_RegExpPrototypeSplitBody(CodeStubAssembler* a, Node* const regexp,
a->Bind(&next);
}
Node* const match_from = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex);
Node* const match_from = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex);
// We're done if the match starts beyond the string.
{
......@@ -1774,8 +1764,8 @@ void Generate_RegExpPrototypeSplitBody(CodeStubAssembler* a, Node* const regexp,
a->Bind(&next);
}
Node* const match_to = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* const match_to = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
// Advance index and continue if the match is empty.
{
......@@ -1806,8 +1796,8 @@ void Generate_RegExpPrototypeSplitBody(CodeStubAssembler* a, Node* const regexp,
// Add all captures to the array.
{
Node* const num_registers = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kNumberOfCapturesIndex);
Node* const num_registers = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kNumberOfCapturesIndex);
Node* const int_num_registers = a->SmiUntag(num_registers);
CVariable var_reg(a, MachineType::PointerRepresentation());
......@@ -2025,8 +2015,8 @@ Node* ReplaceGlobalCallableFastPath(CodeStubAssembler* a, Node* context,
Node* const res_elems = a->LoadElements(res);
CSA_ASSERT(a, a->HasInstanceType(res_elems, FIXED_ARRAY_TYPE));
Node* const num_capture_registers = LoadMatchInfoField(
a, last_match_info, RegExpMatchInfo::kNumberOfCapturesIndex);
Node* const num_capture_registers = a->LoadFixedArrayElement(
last_match_info, RegExpMatchInfo::kNumberOfCapturesIndex);
CLabel if_hasexplicitcaptures(a), if_noexplicitcaptures(a), create_result(a);
a->Branch(a->SmiEqual(num_capture_registers, a->SmiConstant(Smi::FromInt(2))),
......@@ -2241,10 +2231,10 @@ Node* ReplaceSimpleStringFastPath(CodeStubAssembler* a, Node* context,
a->Bind(&if_matched);
{
Node* const subject_start = smi_zero;
Node* const match_start = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex);
Node* const match_end = LoadMatchInfoField(
a, match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* const match_start = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex);
Node* const match_end = a->LoadFixedArrayElement(
match_indices, RegExpMatchInfo::kFirstCaptureIndex + 1);
Node* const subject_end = a->LoadStringLength(subject_string);
CLabel if_replaceisempty(a), if_replaceisnotempty(a);
......
......@@ -1281,10 +1281,8 @@ void Builtins::Generate_StringPrototypeIterator(
"String.prototype[Symbol.iterator]");
Node* native_context = assembler.LoadNativeContext(context);
Node* map = assembler.LoadFixedArrayElement(
native_context,
assembler.IntPtrConstant(Context::STRING_ITERATOR_MAP_INDEX), 0,
CodeStubAssembler::INTPTR_PARAMETERS);
Node* map = assembler.LoadContextElement(native_context,
Context::STRING_ITERATOR_MAP_INDEX);
Node* iterator = assembler.Allocate(JSStringIterator::kSize);
assembler.StoreMapNoWriteBarrier(iterator, map);
assembler.StoreObjectFieldRoot(iterator, JSValue::kPropertiesOffset,
......@@ -1440,10 +1438,8 @@ void Builtins::Generate_StringIteratorPrototypeNext(
assembler.Bind(&return_result);
{
Node* native_context = assembler.LoadNativeContext(context);
Node* map = assembler.LoadFixedArrayElement(
native_context,
assembler.IntPtrConstant(Context::ITERATOR_RESULT_MAP_INDEX), 0,
CodeStubAssembler::INTPTR_PARAMETERS);
Node* map = assembler.LoadContextElement(
native_context, Context::ITERATOR_RESULT_MAP_INDEX);
Node* result = assembler.Allocate(JSIteratorResult::kSize);
assembler.StoreMapNoWriteBarrier(result, map);
assembler.StoreObjectFieldRoot(result, JSIteratorResult::kPropertiesOffset,
......
......@@ -1314,8 +1314,7 @@ Node* CodeStubAssembler::LoadNativeContext(Node* context) {
Node* CodeStubAssembler::LoadJSArrayElementsMap(ElementsKind kind,
Node* native_context) {
CSA_ASSERT(this, IsNativeContext(native_context));
return LoadFixedArrayElement(native_context,
IntPtrConstant(Context::ArrayMapIndex(kind)));
return LoadContextElement(native_context, Context::ArrayMapIndex(kind));
}
Node* CodeStubAssembler::StoreHeapNumberValue(Node* object, Node* value) {
......@@ -4273,9 +4272,7 @@ Node* CodeStubAssembler::IntPtrMax(Node* left, Node* right) {
template <class Dictionary>
Node* CodeStubAssembler::GetNumberOfElements(Node* dictionary) {
return LoadFixedArrayElement(
dictionary, IntPtrConstant(Dictionary::kNumberOfElementsIndex), 0,
INTPTR_PARAMETERS);
return LoadFixedArrayElement(dictionary, Dictionary::kNumberOfElementsIndex);
}
template <class Dictionary>
......@@ -4287,23 +4284,19 @@ void CodeStubAssembler::SetNumberOfElements(Node* dictionary,
template <class Dictionary>
Node* CodeStubAssembler::GetNumberOfDeletedElements(Node* dictionary) {
return LoadFixedArrayElement(
dictionary, IntPtrConstant(Dictionary::kNumberOfDeletedElementsIndex), 0,
INTPTR_PARAMETERS);
return LoadFixedArrayElement(dictionary,
Dictionary::kNumberOfDeletedElementsIndex);
}
template <class Dictionary>
Node* CodeStubAssembler::GetCapacity(Node* dictionary) {
return LoadFixedArrayElement(dictionary,
IntPtrConstant(Dictionary::kCapacityIndex), 0,
INTPTR_PARAMETERS);
return LoadFixedArrayElement(dictionary, Dictionary::kCapacityIndex);
}
template <class Dictionary>
Node* CodeStubAssembler::GetNextEnumerationIndex(Node* dictionary) {
return LoadFixedArrayElement(
dictionary, IntPtrConstant(Dictionary::kNextEnumerationIndexIndex), 0,
INTPTR_PARAMETERS);
return LoadFixedArrayElement(dictionary,
Dictionary::kNextEnumerationIndexIndex);
}
template <class Dictionary>
......@@ -5576,8 +5569,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
{
CSA_ASSERT(this, TaggedIsSmi(mapped_index));
mapped_index = SmiUntag(mapped_index);
Node* the_context = LoadFixedArrayElement(elements, IntPtrConstant(0), 0,
INTPTR_PARAMETERS);
Node* the_context = LoadFixedArrayElement(elements, 0);
// Assert that we can use LoadFixedArrayElement/StoreFixedArrayElement
// methods for accessing Context.
STATIC_ASSERT(Context::kHeaderSize == FixedArray::kHeaderSize);
......@@ -5597,8 +5589,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
Bind(&if_unmapped);
{
Node* backing_store = LoadFixedArrayElement(elements, IntPtrConstant(1), 0,
INTPTR_PARAMETERS);
Node* backing_store = LoadFixedArrayElement(elements, 1);
GotoIf(WordNotEqual(LoadMap(backing_store), FixedArrayMapConstant()),
bailout);
......
......@@ -300,6 +300,11 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* LoadFixedArrayElement(
Node* object, Node* index, int additional_offset = 0,
ParameterMode parameter_mode = INTEGER_PARAMETERS);
Node* LoadFixedArrayElement(Node* object, int index,
int additional_offset = 0) {
return LoadFixedArrayElement(object, IntPtrConstant(index),
additional_offset, INTPTR_PARAMETERS);
}
// Load an array element from a FixedArray, untag it and return it as Word32.
Node* LoadAndUntagToWord32FixedArrayElement(
Node* object, Node* index, int additional_offset = 0,
......
......@@ -1887,10 +1887,8 @@ void LoadApiGetterStub::GenerateAssembly(
Node* holder = receiver;
Node* map = assembler.LoadMap(receiver);
Node* descriptors = assembler.LoadMapDescriptors(map);
Node* value_index =
assembler.IntPtrConstant(DescriptorArray::ToValueIndex(index()));
Node* callback = assembler.LoadFixedArrayElement(
descriptors, value_index, 0, CodeStubAssembler::INTPTR_PARAMETERS);
descriptors, DescriptorArray::ToValueIndex(index()));
assembler.TailCallStub(CodeFactory::ApiGetter(isolate()), context, receiver,
holder, callback);
}
......@@ -2091,9 +2089,7 @@ void LoadScriptContextFieldStub::GenerateAssembly(
Node* context = assembler.Parameter(Descriptor::kContext);
Node* script_context = assembler.LoadScriptContext(context, context_index());
Node* result = assembler.LoadFixedArrayElement(
script_context, assembler.IntPtrConstant(slot_index()), 0,
CodeStubAssembler::INTPTR_PARAMETERS);
Node* result = assembler.LoadFixedArrayElement(script_context, slot_index());
assembler.Return(result);
}
......
......@@ -62,13 +62,12 @@ void AccessorAssemblerImpl::HandlePolymorphicCase(
for (int i = 0; i < unroll_count; i++) {
Label next_entry(this);
Node* cached_map = LoadWeakCellValue(LoadFixedArrayElement(
feedback, IntPtrConstant(i * kEntrySize), 0, INTPTR_PARAMETERS));
Node* cached_map =
LoadWeakCellValue(LoadFixedArrayElement(feedback, i * kEntrySize));
GotoIf(WordNotEqual(receiver_map, cached_map), &next_entry);
// Found, now call handler.
Node* handler = LoadFixedArrayElement(
feedback, IntPtrConstant(i * kEntrySize + 1), 0, INTPTR_PARAMETERS);
Node* handler = LoadFixedArrayElement(feedback, i * kEntrySize + 1);
var_handler->Bind(handler);
Goto(if_handler);
......@@ -432,9 +431,8 @@ Node* AccessorAssemblerImpl::EmitLoadICProtoArrayCheck(
},
1, IndexAdvanceMode::kPost);
Node* maybe_holder_cell = LoadFixedArrayElement(
handler, IntPtrConstant(LoadHandler::kHolderCellIndex), 0,
INTPTR_PARAMETERS);
Node* maybe_holder_cell =
LoadFixedArrayElement(handler, LoadHandler::kHolderCellIndex);
Label load_existent(this);
GotoIf(WordNotEqual(maybe_holder_cell, NullConstant()), &load_existent);
// This is a handler for a load of a non-existent value.
......@@ -558,9 +556,8 @@ void AccessorAssemblerImpl::HandleStoreICProtoHandler(
},
1, IndexAdvanceMode::kPost);
Node* maybe_transition_cell = LoadFixedArrayElement(
handler, IntPtrConstant(StoreHandler::kTransitionCellIndex), 0,
INTPTR_PARAMETERS);
Node* maybe_transition_cell =
LoadFixedArrayElement(handler, StoreHandler::kTransitionCellIndex);
Node* transition = LoadWeakCellValue(maybe_transition_cell, miss);
var_transition.Bind(transition);
Goto(&if_transition);
......
......@@ -591,9 +591,8 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context,
GotoUnless(is_allocation_site, &check_initialized);
// If it is not the Array() function, mark megamorphic.
Node* context_slot =
LoadFixedArrayElement(LoadNativeContext(context),
Int32Constant(Context::ARRAY_FUNCTION_INDEX));
Node* context_slot = LoadContextElement(LoadNativeContext(context),
Context::ARRAY_FUNCTION_INDEX);
Node* is_array_function = WordEqual(context_slot, function);
GotoUnless(is_array_function, &mark_megamorphic);
......@@ -631,9 +630,8 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context,
GotoUnless(is_js_function, &mark_megamorphic);
// Check if it is the Array() function.
Node* context_slot =
LoadFixedArrayElement(LoadNativeContext(context),
Int32Constant(Context::ARRAY_FUNCTION_INDEX));
Node* context_slot = LoadContextElement(LoadNativeContext(context),
Context::ARRAY_FUNCTION_INDEX);
Node* is_array_function = WordEqual(context_slot, function);
GotoIf(is_array_function, &create_allocation_site);
......@@ -782,9 +780,8 @@ Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context,
GotoUnless(is_allocation_site, &check_initialized);
// Make sure the function is the Array() function.
Node* context_slot =
LoadFixedArrayElement(LoadNativeContext(context),
Int32Constant(Context::ARRAY_FUNCTION_INDEX));
Node* context_slot = LoadContextElement(LoadNativeContext(context),
Context::ARRAY_FUNCTION_INDEX);
Node* is_array_function = WordEqual(context_slot, constructor);
GotoUnless(is_array_function, &mark_megamorphic);
......@@ -807,9 +804,8 @@ Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context,
Comment("initialize the feedback element");
// Create an allocation site if the function is an array function,
// otherwise create a weak cell.
Node* context_slot =
LoadFixedArrayElement(LoadNativeContext(context),
Int32Constant(Context::ARRAY_FUNCTION_INDEX));
Node* context_slot = LoadContextElement(LoadNativeContext(context),
Context::ARRAY_FUNCTION_INDEX);
Node* is_array_function = WordEqual(context_slot, constructor);
Branch(is_array_function, &create_allocation_site, &create_weak_cell);
......
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