Commit 3d618949 authored by ishell's avatar ishell Committed by Commit bot

[stubs] Cleanup usages of lambdas in CodeStubAssembler and friends.

The changes are:
1) Pass lambdas as const references to avoid unnecessary copying.
2) Remove CodeStubAssembler* parameter from loop bodies and let the lambdas
   capture the right assembler instead. It makes the loop body code look
   uniform with the surrounding code and unblocks splitting of a CSA
   into different classes.

BUG=

Review-Url: https://codereview.chromium.org/2535753012
Cr-Commit-Position: refs/heads/master@{#41482}
parent 8590e8d4
...@@ -314,11 +314,10 @@ void Builtins::Generate_FastArrayPush(compiler::CodeAssemblerState* state) { ...@@ -314,11 +314,10 @@ void Builtins::Generate_FastArrayPush(compiler::CodeAssemblerState* state) {
assembler.Bind(&default_label); assembler.Bind(&default_label);
{ {
args.ForEach( args.ForEach(
[receiver, context, &arg_index](CodeStubAssembler* assembler, [&assembler, receiver, context, &arg_index](Node* arg) {
Node* arg) { Node* length = assembler.LoadJSArrayLength(receiver);
Node* length = assembler->LoadJSArrayLength(receiver); assembler.CallRuntime(Runtime::kSetProperty, context, receiver,
assembler->CallRuntime(Runtime::kSetProperty, context, receiver, length, arg, assembler.SmiConstant(STRICT));
length, arg, assembler->SmiConstant(STRICT));
}, },
arg_index.value()); arg_index.value());
args.PopAndReturn(assembler.LoadJSArrayLength(receiver)); args.PopAndReturn(assembler.LoadJSArrayLength(receiver));
......
...@@ -376,13 +376,12 @@ void Builtins::Generate_FastFunctionPrototypeBind( ...@@ -376,13 +376,12 @@ void Builtins::Generate_FastFunctionPrototypeBind(
Variable index(&assembler, MachineType::PointerRepresentation()); Variable index(&assembler, MachineType::PointerRepresentation());
index.Bind(assembler.IntPtrConstant(0)); index.Bind(assembler.IntPtrConstant(0));
CodeStubAssembler::VariableList foreach_vars({&index}, assembler.zone()); CodeStubAssembler::VariableList foreach_vars({&index}, assembler.zone());
args.ForEach( args.ForEach(foreach_vars,
foreach_vars, [&assembler, elements, &index](compiler::Node* arg) {
[elements, &index](CodeStubAssembler* assembler, compiler::Node* arg) { assembler.StoreFixedArrayElement(
assembler->StoreFixedArrayElement(elements, index.value(), arg, elements, index.value(), arg, UPDATE_WRITE_BARRIER, 0,
UPDATE_WRITE_BARRIER, 0,
CodeStubAssembler::INTPTR_PARAMETERS); CodeStubAssembler::INTPTR_PARAMETERS);
assembler->Increment(index); assembler.Increment(index);
}, },
assembler.IntPtrConstant(1)); assembler.IntPtrConstant(1));
argument_array.Bind(elements); argument_array.Bind(elements);
......
...@@ -2159,8 +2159,8 @@ Node* ReplaceGlobalCallableFastPath(CodeStubAssembler* a, Node* context, ...@@ -2159,8 +2159,8 @@ Node* ReplaceGlobalCallableFastPath(CodeStubAssembler* a, Node* context,
a->BuildFastLoop( a->BuildFastLoop(
MachineType::PointerRepresentation(), from, to, MachineType::PointerRepresentation(), from, to,
[res_elems, isolate, native_context, context, undefined, [a, res_elems, isolate, native_context, context, undefined,
replace_callable, mode](CodeStubAssembler* a, Node* index) { replace_callable, mode](Node* index) {
Node* const elem = Node* const elem =
a->LoadFixedArrayElement(res_elems, index, 0, mode); a->LoadFixedArrayElement(res_elems, index, 0, mode);
......
...@@ -473,27 +473,26 @@ void Builtins::Generate_StringFromCharCode( ...@@ -473,27 +473,26 @@ void Builtins::Generate_StringFromCharCode(
// codes. Stop if any of the conversions generates a code that doesn't fit // codes. Stop if any of the conversions generates a code that doesn't fit
// in 8 bits. // in 8 bits.
CodeStubAssembler::VariableList vars({&max_index}, assembler.zone()); CodeStubAssembler::VariableList vars({&max_index}, assembler.zone());
arguments.ForEach(vars, [context, &two_byte, &max_index, &code16, arguments.ForEach(vars, [&assembler, context, &two_byte, &max_index,
one_byte_result](CodeStubAssembler* assembler, &code16, one_byte_result](Node* arg) {
Node* arg) { Node* code32 = assembler.TruncateTaggedToWord32(context, arg);
Node* code32 = assembler->TruncateTaggedToWord32(context, arg); code16 = assembler.Word32And(
code16 = assembler->Word32And( code32, assembler.Int32Constant(String::kMaxUtf16CodeUnit));
code32, assembler->Int32Constant(String::kMaxUtf16CodeUnit));
assembler.GotoIf(
assembler->GotoIf( assembler.Int32GreaterThan(
assembler->Int32GreaterThan( code16, assembler.Int32Constant(String::kMaxOneByteCharCode)),
code16, assembler->Int32Constant(String::kMaxOneByteCharCode)),
&two_byte); &two_byte);
// The {code16} fits into the SeqOneByteString {one_byte_result}. // The {code16} fits into the SeqOneByteString {one_byte_result}.
Node* offset = assembler->ElementOffsetFromIndex( Node* offset = assembler.ElementOffsetFromIndex(
max_index.value(), UINT8_ELEMENTS, max_index.value(), UINT8_ELEMENTS,
CodeStubAssembler::INTPTR_PARAMETERS, CodeStubAssembler::INTPTR_PARAMETERS,
SeqOneByteString::kHeaderSize - kHeapObjectTag); SeqOneByteString::kHeaderSize - kHeapObjectTag);
assembler->StoreNoWriteBarrier(MachineRepresentation::kWord8, assembler.StoreNoWriteBarrier(MachineRepresentation::kWord8,
one_byte_result, offset, code16); one_byte_result, offset, code16);
max_index.Bind(assembler->IntPtrAdd(max_index.value(), max_index.Bind(
assembler->IntPtrConstant(1))); assembler.IntPtrAdd(max_index.value(), assembler.IntPtrConstant(1)));
}); });
arguments.PopAndReturn(one_byte_result); arguments.PopAndReturn(one_byte_result);
...@@ -527,20 +526,19 @@ void Builtins::Generate_StringFromCharCode( ...@@ -527,20 +526,19 @@ void Builtins::Generate_StringFromCharCode(
// using a 16-bit representation. // using a 16-bit representation.
arguments.ForEach( arguments.ForEach(
vars, vars,
[context, two_byte_result, &max_index](CodeStubAssembler* assembler, [&assembler, context, two_byte_result, &max_index](Node* arg) {
Node* arg) { Node* code32 = assembler.TruncateTaggedToWord32(context, arg);
Node* code32 = assembler->TruncateTaggedToWord32(context, arg); Node* code16 = assembler.Word32And(
Node* code16 = assembler->Word32And( code32, assembler.Int32Constant(String::kMaxUtf16CodeUnit));
code32, assembler->Int32Constant(String::kMaxUtf16CodeUnit));
Node* offset = assembler->ElementOffsetFromIndex( Node* offset = assembler.ElementOffsetFromIndex(
max_index.value(), UINT16_ELEMENTS, max_index.value(), UINT16_ELEMENTS,
CodeStubAssembler::INTPTR_PARAMETERS, CodeStubAssembler::INTPTR_PARAMETERS,
SeqTwoByteString::kHeaderSize - kHeapObjectTag); SeqTwoByteString::kHeaderSize - kHeapObjectTag);
assembler->StoreNoWriteBarrier(MachineRepresentation::kWord16, assembler.StoreNoWriteBarrier(MachineRepresentation::kWord16,
two_byte_result, offset, code16); two_byte_result, offset, code16);
max_index.Bind(assembler->IntPtrAdd(max_index.value(), max_index.Bind(assembler.IntPtrAdd(max_index.value(),
assembler->IntPtrConstant(1))); assembler.IntPtrConstant(1)));
}, },
max_index.value()); max_index.value());
......
...@@ -11,8 +11,9 @@ namespace internal { ...@@ -11,8 +11,9 @@ namespace internal {
using compiler::Node; using compiler::Node;
void CodeStubAssembler::Assert(ConditionBody codition_body, const char* message, void CodeStubAssembler::Assert(const NodeGenerator& codition_body,
const char* file, int line) { const char* message, const char* file,
int line) {
#if defined(DEBUG) #if defined(DEBUG)
Label ok(this); Label ok(this);
Label not_ok(this, Label::kDeferred); Label not_ok(this, Label::kDeferred);
...@@ -1446,26 +1447,24 @@ Node* CodeStubAssembler::BuildAppendJSArray(ElementsKind kind, Node* context, ...@@ -1446,26 +1447,24 @@ Node* CodeStubAssembler::BuildAppendJSArray(ElementsKind kind, Node* context,
CodeStubAssembler::VariableList push_vars({&length, &elements}, zone()); CodeStubAssembler::VariableList push_vars({&length, &elements}, zone());
args.ForEach( args.ForEach(
push_vars, push_vars,
[kind, mode, &length, &elements, &pre_bailout]( [this, kind, mode, &length, &elements, &pre_bailout](Node* arg) {
CodeStubAssembler* assembler, Node* arg) {
if (IsFastSmiElementsKind(kind)) { if (IsFastSmiElementsKind(kind)) {
assembler->GotoIf(assembler->TaggedIsNotSmi(arg), &pre_bailout); GotoIf(TaggedIsNotSmi(arg), &pre_bailout);
} else if (IsFastDoubleElementsKind(kind)) { } else if (IsFastDoubleElementsKind(kind)) {
assembler->GotoIfNotNumber(arg, &pre_bailout); GotoIfNotNumber(arg, &pre_bailout);
} }
if (IsFastDoubleElementsKind(kind)) { if (IsFastDoubleElementsKind(kind)) {
Node* double_value = assembler->ChangeNumberToFloat64(arg); Node* double_value = ChangeNumberToFloat64(arg);
assembler->StoreFixedDoubleArrayElement( StoreFixedDoubleArrayElement(elements.value(), length.value(),
elements.value(), length.value(), Float64SilenceNaN(double_value), mode);
assembler->Float64SilenceNaN(double_value), mode);
} else { } else {
WriteBarrierMode barrier_mode = IsFastSmiElementsKind(kind) WriteBarrierMode barrier_mode = IsFastSmiElementsKind(kind)
? SKIP_WRITE_BARRIER ? SKIP_WRITE_BARRIER
: UPDATE_WRITE_BARRIER; : UPDATE_WRITE_BARRIER;
assembler->StoreFixedArrayElement(elements.value(), length.value(), StoreFixedArrayElement(elements.value(), length.value(), arg,
arg, barrier_mode, 0, mode); barrier_mode, 0, mode);
} }
assembler->Increment(length, 1, mode); Increment(length, 1, mode);
}, },
first, nullptr); first, nullptr);
length.Bind(TagParameter(length.value(), mode)); length.Bind(TagParameter(length.value(), mode));
...@@ -1896,8 +1895,8 @@ void CodeStubAssembler::StoreFieldsNoWriteBarrier(Node* start_address, ...@@ -1896,8 +1895,8 @@ void CodeStubAssembler::StoreFieldsNoWriteBarrier(Node* start_address,
CSA_ASSERT(this, WordIsWordAligned(end_address)); CSA_ASSERT(this, WordIsWordAligned(end_address));
BuildFastLoop( BuildFastLoop(
MachineType::PointerRepresentation(), start_address, end_address, MachineType::PointerRepresentation(), start_address, end_address,
[value](CodeStubAssembler* a, Node* current) { [this, value](Node* current) {
a->StoreNoWriteBarrier(MachineRepresentation::kTagged, current, value); StoreNoWriteBarrier(MachineRepresentation::kTagged, current, value);
}, },
kPointerSize, IndexAdvanceMode::kPost); kPointerSize, IndexAdvanceMode::kPost);
} }
...@@ -2024,8 +2023,7 @@ void CodeStubAssembler::FillFixedArrayWithValue( ...@@ -2024,8 +2023,7 @@ void CodeStubAssembler::FillFixedArrayWithValue(
BuildFastFixedArrayForEach( BuildFastFixedArrayForEach(
array, kind, from_node, to_node, array, kind, from_node, to_node,
[value, is_double, double_hole](CodeStubAssembler* assembler, Node* array, [this, value, is_double, double_hole](Node* array, Node* offset) {
Node* offset) {
if (is_double) { if (is_double) {
// Don't use doubles to store the hole double, since manipulating the // Don't use doubles to store the hole double, since manipulating the
// signaling NaN used for the hole in C++, e.g. with bit_cast, will // signaling NaN used for the hole in C++, e.g. with bit_cast, will
...@@ -2035,21 +2033,19 @@ void CodeStubAssembler::FillFixedArrayWithValue( ...@@ -2035,21 +2033,19 @@ void CodeStubAssembler::FillFixedArrayWithValue(
// TODO(danno): When we have a Float32/Float64 wrapper class that // TODO(danno): When we have a Float32/Float64 wrapper class that
// preserves double bits during manipulation, remove this code/change // preserves double bits during manipulation, remove this code/change
// this to an indexed Float64 store. // this to an indexed Float64 store.
if (assembler->Is64()) { if (Is64()) {
assembler->StoreNoWriteBarrier(MachineRepresentation::kWord64, StoreNoWriteBarrier(MachineRepresentation::kWord64, array, offset,
array, offset, double_hole); double_hole);
} else { } else {
assembler->StoreNoWriteBarrier(MachineRepresentation::kWord32, StoreNoWriteBarrier(MachineRepresentation::kWord32, array, offset,
array, offset, double_hole); double_hole);
assembler->StoreNoWriteBarrier( StoreNoWriteBarrier(MachineRepresentation::kWord32, array,
MachineRepresentation::kWord32, array, IntPtrAdd(offset, IntPtrConstant(kPointerSize)),
assembler->IntPtrAdd(offset,
assembler->IntPtrConstant(kPointerSize)),
double_hole); double_hole);
} }
} else { } else {
assembler->StoreNoWriteBarrier(MachineRepresentation::kTagged, array, StoreNoWriteBarrier(MachineRepresentation::kTagged, array, offset,
offset, value); value);
} }
}, },
mode); mode);
...@@ -2237,14 +2233,14 @@ void CodeStubAssembler::CopyStringCharacters(Node* from_string, Node* to_string, ...@@ -2237,14 +2233,14 @@ void CodeStubAssembler::CopyStringCharacters(Node* from_string, Node* to_string,
to_index_smi == from_index_smi)); to_index_smi == from_index_smi));
BuildFastLoop(vars, MachineType::PointerRepresentation(), from_offset, BuildFastLoop(vars, MachineType::PointerRepresentation(), from_offset,
limit_offset, limit_offset,
[from_string, to_string, &current_to_offset, to_increment, type, [this, from_string, to_string, &current_to_offset, to_increment,
rep, index_same](CodeStubAssembler* assembler, Node* offset) { type, rep, index_same](Node* offset) {
Node* value = assembler->Load(type, from_string, offset); Node* value = Load(type, from_string, offset);
assembler->StoreNoWriteBarrier( StoreNoWriteBarrier(
rep, to_string, rep, to_string,
index_same ? offset : current_to_offset.value(), value); index_same ? offset : current_to_offset.value(), value);
if (!index_same) { if (!index_same) {
assembler->Increment(current_to_offset, to_increment); Increment(current_to_offset, to_increment);
} }
}, },
from_increment, IndexAdvanceMode::kPost); from_increment, IndexAdvanceMode::kPost);
...@@ -3543,19 +3539,19 @@ Node* CodeStubAssembler::StringIndexOfChar(Node* context, Node* string, ...@@ -3543,19 +3539,19 @@ Node* CodeStubAssembler::StringIndexOfChar(Node* context, Node* string,
var_result.Bind(SmiConstant(Smi::FromInt(-1))); var_result.Bind(SmiConstant(Smi::FromInt(-1)));
BuildFastLoop(MachineType::PointerRepresentation(), cursor, end, BuildFastLoop(
[string, needle_char, begin, &var_result, &out]( MachineType::PointerRepresentation(), cursor, end,
CodeStubAssembler* csa, Node* cursor) { [this, string, needle_char, begin, &var_result, &out](Node* cursor) {
Label next(csa); Label next(this);
Node* value = csa->Load(MachineType::Uint8(), string, cursor); Node* value = Load(MachineType::Uint8(), string, cursor);
csa->GotoUnless(csa->WordEqual(value, needle_char), &next); GotoUnless(WordEqual(value, needle_char), &next);
// Found a match. // Found a match.
Node* index = csa->SmiTag(csa->IntPtrSub(cursor, begin)); Node* index = SmiTag(IntPtrSub(cursor, begin));
var_result.Bind(index); var_result.Bind(index);
csa->Goto(&out); Goto(&out);
csa->Bind(&next); Bind(&next);
}, },
1, IndexAdvanceMode::kPost); 1, IndexAdvanceMode::kPost);
Goto(&out); Goto(&out);
...@@ -4601,15 +4597,14 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name, ...@@ -4601,15 +4597,14 @@ void CodeStubAssembler::DescriptorLookupLinear(Node* unique_name,
Node* factor = IntPtrConstant(DescriptorArray::kDescriptorSize); Node* factor = IntPtrConstant(DescriptorArray::kDescriptorSize);
Node* last_exclusive = IntPtrAdd(first_inclusive, IntPtrMul(nof, factor)); Node* last_exclusive = IntPtrAdd(first_inclusive, IntPtrMul(nof, factor));
BuildFastLoop( BuildFastLoop(MachineType::PointerRepresentation(), last_exclusive,
MachineType::PointerRepresentation(), last_exclusive, first_inclusive, first_inclusive,
[descriptors, unique_name, if_found, var_name_index]( [this, descriptors, unique_name, if_found,
CodeStubAssembler* assembler, Node* name_index) { var_name_index](Node* name_index) {
Node* candidate_name = assembler->LoadFixedArrayElement( Node* candidate_name = LoadFixedArrayElement(
descriptors, name_index, 0, INTPTR_PARAMETERS); descriptors, name_index, 0, INTPTR_PARAMETERS);
var_name_index->Bind(name_index); var_name_index->Bind(name_index);
assembler->GotoIf(assembler->WordEqual(candidate_name, unique_name), GotoIf(WordEqual(candidate_name, unique_name), if_found);
if_found);
}, },
-DescriptorArray::kDescriptorSize, IndexAdvanceMode::kPre); -DescriptorArray::kDescriptorSize, IndexAdvanceMode::kPre);
Goto(if_not_found); Goto(if_not_found);
...@@ -5075,8 +5070,8 @@ template void CodeStubAssembler::NumberDictionaryLookup< ...@@ -5075,8 +5070,8 @@ template void CodeStubAssembler::NumberDictionaryLookup<
UnseededNumberDictionary>(Node*, Node*, Label*, Variable*, Label*); UnseededNumberDictionary>(Node*, Node*, Label*, Variable*, Label*);
void CodeStubAssembler::TryPrototypeChainLookup( void CodeStubAssembler::TryPrototypeChainLookup(
Node* receiver, Node* key, LookupInHolder& lookup_property_in_holder, Node* receiver, Node* key, const LookupInHolder& lookup_property_in_holder,
LookupInHolder& lookup_element_in_holder, Label* if_end, const LookupInHolder& lookup_element_in_holder, Label* if_end,
Label* if_bailout) { Label* if_bailout) {
// Ensure receiver is JSReceiver, otherwise bailout. // Ensure receiver is JSReceiver, otherwise bailout.
Label if_objectisnotsmi(this); Label if_objectisnotsmi(this);
...@@ -6188,8 +6183,7 @@ Node* CodeStubAssembler::CreateWeakCellInFeedbackVector(Node* feedback_vector, ...@@ -6188,8 +6183,7 @@ Node* CodeStubAssembler::CreateWeakCellInFeedbackVector(Node* feedback_vector,
void CodeStubAssembler::BuildFastLoop( void CodeStubAssembler::BuildFastLoop(
const CodeStubAssembler::VariableList& vars, const CodeStubAssembler::VariableList& vars,
MachineRepresentation index_rep, Node* start_index, Node* end_index, MachineRepresentation index_rep, Node* start_index, Node* end_index,
std::function<void(CodeStubAssembler* assembler, Node* index)> body, const FastLoopBody& body, int increment, IndexAdvanceMode mode) {
int increment, IndexAdvanceMode mode) {
Variable var(this, index_rep); Variable var(this, index_rep);
VariableList vars_copy(vars, zone()); VariableList vars_copy(vars, zone());
vars_copy.Add(&var, zone()); vars_copy.Add(&var, zone());
...@@ -6209,7 +6203,7 @@ void CodeStubAssembler::BuildFastLoop( ...@@ -6209,7 +6203,7 @@ void CodeStubAssembler::BuildFastLoop(
if (mode == IndexAdvanceMode::kPre) { if (mode == IndexAdvanceMode::kPre) {
Increment(var, increment); Increment(var, increment);
} }
body(this, var.value()); body(var.value());
if (mode == IndexAdvanceMode::kPost) { if (mode == IndexAdvanceMode::kPost) {
Increment(var, increment); Increment(var, increment);
} }
...@@ -6220,10 +6214,7 @@ void CodeStubAssembler::BuildFastLoop( ...@@ -6220,10 +6214,7 @@ void CodeStubAssembler::BuildFastLoop(
void CodeStubAssembler::BuildFastFixedArrayForEach( void CodeStubAssembler::BuildFastFixedArrayForEach(
Node* fixed_array, ElementsKind kind, Node* first_element_inclusive, Node* fixed_array, ElementsKind kind, Node* first_element_inclusive,
Node* last_element_exclusive, Node* last_element_exclusive, const FastFixedArrayForEachBody& body,
std::function<void(CodeStubAssembler* assembler, Node* fixed_array,
Node* offset)>
body,
ParameterMode mode, ForEachDirection direction) { ParameterMode mode, ForEachDirection direction) {
STATIC_ASSERT(FixedArray::kHeaderSize == FixedDoubleArray::kHeaderSize); STATIC_ASSERT(FixedArray::kHeaderSize == FixedDoubleArray::kHeaderSize);
int32_t first_val; int32_t first_val;
...@@ -6240,7 +6231,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach( ...@@ -6240,7 +6231,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach(
Node* offset = Node* offset =
ElementOffsetFromIndex(index, kind, INTPTR_PARAMETERS, ElementOffsetFromIndex(index, kind, INTPTR_PARAMETERS,
FixedArray::kHeaderSize - kHeapObjectTag); FixedArray::kHeaderSize - kHeapObjectTag);
body(this, fixed_array, offset); body(fixed_array, offset);
} }
} else { } else {
for (int i = last_val - 1; i >= first_val; --i) { for (int i = last_val - 1; i >= first_val; --i) {
...@@ -6248,7 +6239,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach( ...@@ -6248,7 +6239,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach(
Node* offset = Node* offset =
ElementOffsetFromIndex(index, kind, INTPTR_PARAMETERS, ElementOffsetFromIndex(index, kind, INTPTR_PARAMETERS,
FixedArray::kHeaderSize - kHeapObjectTag); FixedArray::kHeaderSize - kHeapObjectTag);
body(this, fixed_array, offset); body(fixed_array, offset);
} }
} }
return; return;
...@@ -6266,9 +6257,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach( ...@@ -6266,9 +6257,7 @@ void CodeStubAssembler::BuildFastFixedArrayForEach(
int increment = IsFastDoubleElementsKind(kind) ? kDoubleSize : kPointerSize; int increment = IsFastDoubleElementsKind(kind) ? kDoubleSize : kPointerSize;
BuildFastLoop( BuildFastLoop(
MachineType::PointerRepresentation(), start, limit, MachineType::PointerRepresentation(), start, limit,
[fixed_array, body](CodeStubAssembler* assembler, Node* offset) { [fixed_array, &body](Node* offset) { body(fixed_array, offset); },
body(assembler, fixed_array, offset);
},
direction == ForEachDirection::kReverse ? -increment : increment, direction == ForEachDirection::kReverse ? -increment : increment,
direction == ForEachDirection::kReverse ? IndexAdvanceMode::kPre direction == ForEachDirection::kReverse ? IndexAdvanceMode::kPre
: IndexAdvanceMode::kPost); : IndexAdvanceMode::kPost);
...@@ -8107,9 +8096,9 @@ Node* CodeStubArguments::AtIndex(int index) const { ...@@ -8107,9 +8096,9 @@ Node* CodeStubArguments::AtIndex(int index) const {
return AtIndex(assembler_->IntPtrConstant(index)); return AtIndex(assembler_->IntPtrConstant(index));
} }
void CodeStubArguments::ForEach(const CodeStubAssembler::VariableList& vars, void CodeStubArguments::ForEach(
CodeStubArguments::ForEachBodyFunction body, const CodeStubAssembler::VariableList& vars,
Node* first, Node* last, const CodeStubArguments::ForEachBodyFunction& body, Node* first, Node* last,
CodeStubAssembler::ParameterMode mode) { CodeStubAssembler::ParameterMode mode) {
assembler_->Comment("CodeStubArguments::ForEach"); assembler_->Comment("CodeStubArguments::ForEach");
DCHECK_IMPLIES(first == nullptr || last == nullptr, DCHECK_IMPLIES(first == nullptr || last == nullptr,
...@@ -8128,9 +8117,9 @@ void CodeStubArguments::ForEach(const CodeStubAssembler::VariableList& vars, ...@@ -8128,9 +8117,9 @@ void CodeStubArguments::ForEach(const CodeStubAssembler::VariableList& vars,
assembler_->ElementOffsetFromIndex(last, FAST_ELEMENTS, mode)); assembler_->ElementOffsetFromIndex(last, FAST_ELEMENTS, mode));
assembler_->BuildFastLoop( assembler_->BuildFastLoop(
vars, MachineType::PointerRepresentation(), start, end, vars, MachineType::PointerRepresentation(), start, end,
[body](CodeStubAssembler* assembler, Node* current) { [this, &body](Node* current) {
Node* arg = assembler->Load(MachineType::AnyTagged(), current); Node* arg = assembler_->Load(MachineType::AnyTagged(), current);
body(assembler, arg); body(arg);
}, },
-kPointerSize, CodeStubAssembler::IndexAdvanceMode::kPost); -kPointerSize, CodeStubAssembler::IndexAdvanceMode::kPost);
} }
......
...@@ -164,8 +164,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -164,8 +164,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* InnerAllocate(Node* previous, Node* offset); Node* InnerAllocate(Node* previous, Node* offset);
Node* IsRegularHeapObjectSize(Node* size); Node* IsRegularHeapObjectSize(Node* size);
typedef std::function<Node*()> ConditionBody; typedef std::function<Node*()> NodeGenerator;
void Assert(ConditionBody condition_body, const char* string = nullptr,
void Assert(const NodeGenerator& condition_body, const char* string = nullptr,
const char* file = nullptr, int line = 0); const char* file = nullptr, int line = 0);
// Check a value for smi-ness // Check a value for smi-ness
...@@ -830,8 +831,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -830,8 +831,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
// If it can't handle the case {receiver}/{key} case then the control goes // If it can't handle the case {receiver}/{key} case then the control goes
// to {if_bailout}. // to {if_bailout}.
void TryPrototypeChainLookup(Node* receiver, Node* key, void TryPrototypeChainLookup(Node* receiver, Node* key,
LookupInHolder& lookup_property_in_holder, const LookupInHolder& lookup_property_in_holder,
LookupInHolder& lookup_element_in_holder, const LookupInHolder& lookup_element_in_holder,
Label* if_end, Label* if_bailout); Label* if_end, Label* if_bailout);
// Instanceof helpers. // Instanceof helpers.
...@@ -923,28 +924,28 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -923,28 +924,28 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
enum class IndexAdvanceMode { kPre, kPost }; enum class IndexAdvanceMode { kPre, kPost };
void BuildFastLoop( typedef std::function<void(Node* index)> FastLoopBody;
const VariableList& var_list, MachineRepresentation index_rep,
Node* start_index, Node* end_index, void BuildFastLoop(const VariableList& var_list,
std::function<void(CodeStubAssembler* assembler, Node* index)> body, MachineRepresentation index_rep, Node* start_index,
int increment, IndexAdvanceMode mode = IndexAdvanceMode::kPre); Node* end_index, const FastLoopBody& body, int increment,
IndexAdvanceMode mode = IndexAdvanceMode::kPre);
void BuildFastLoop( void BuildFastLoop(MachineRepresentation index_rep, Node* start_index,
MachineRepresentation index_rep, Node* start_index, Node* end_index, Node* end_index, const FastLoopBody& body, int increment,
std::function<void(CodeStubAssembler* assembler, Node* index)> body, IndexAdvanceMode mode = IndexAdvanceMode::kPre) {
int increment, IndexAdvanceMode mode = IndexAdvanceMode::kPre) {
BuildFastLoop(VariableList(0, zone()), index_rep, start_index, end_index, BuildFastLoop(VariableList(0, zone()), index_rep, start_index, end_index,
body, increment, mode); body, increment, mode);
} }
enum class ForEachDirection { kForward, kReverse }; enum class ForEachDirection { kForward, kReverse };
typedef std::function<void(Node* fixed_array, Node* offset)>
FastFixedArrayForEachBody;
void BuildFastFixedArrayForEach( void BuildFastFixedArrayForEach(
Node* fixed_array, ElementsKind kind, Node* first_element_inclusive, Node* fixed_array, ElementsKind kind, Node* first_element_inclusive,
Node* last_element_exclusive, Node* last_element_exclusive, const FastFixedArrayForEachBody& body,
std::function<void(CodeStubAssembler* assembler, Node* fixed_array,
Node* offset)>
body,
ParameterMode mode = INTPTR_PARAMETERS, ParameterMode mode = INTPTR_PARAMETERS,
ForEachDirection direction = ForEachDirection::kReverse); ForEachDirection direction = ForEachDirection::kReverse);
...@@ -1069,11 +1070,10 @@ class CodeStubArguments { ...@@ -1069,11 +1070,10 @@ class CodeStubArguments {
Node* GetLength() const { return argc_; } Node* GetLength() const { return argc_; }
typedef std::function<void(CodeStubAssembler* assembler, Node* arg)> typedef std::function<void(Node* arg)> ForEachBodyFunction;
ForEachBodyFunction;
// Iteration doesn't include the receiver. |first| and |last| are zero-based. // Iteration doesn't include the receiver. |first| and |last| are zero-based.
void ForEach(ForEachBodyFunction body, Node* first = nullptr, void ForEach(const ForEachBodyFunction& body, Node* first = nullptr,
Node* last = nullptr, CodeStubAssembler::ParameterMode mode = Node* last = nullptr, CodeStubAssembler::ParameterMode mode =
CodeStubAssembler::INTPTR_PARAMETERS) { CodeStubAssembler::INTPTR_PARAMETERS) {
CodeStubAssembler::VariableList list(0, assembler_->zone()); CodeStubAssembler::VariableList list(0, assembler_->zone());
...@@ -1082,7 +1082,7 @@ class CodeStubArguments { ...@@ -1082,7 +1082,7 @@ class CodeStubArguments {
// Iteration doesn't include the receiver. |first| and |last| are zero-based. // Iteration doesn't include the receiver. |first| and |last| are zero-based.
void ForEach(const CodeStubAssembler::VariableList& vars, void ForEach(const CodeStubAssembler::VariableList& vars,
ForEachBodyFunction body, Node* first = nullptr, const ForEachBodyFunction& body, Node* first = nullptr,
Node* last = nullptr, CodeStubAssembler::ParameterMode mode = Node* last = nullptr, CodeStubAssembler::ParameterMode mode =
CodeStubAssembler::INTPTR_PARAMETERS); CodeStubAssembler::INTPTR_PARAMETERS);
......
...@@ -2626,7 +2626,7 @@ compiler::Node* FastNewFunctionContextStub::Generate( ...@@ -2626,7 +2626,7 @@ compiler::Node* FastNewFunctionContextStub::Generate(
Node* undefined = assembler->UndefinedConstant(); Node* undefined = assembler->UndefinedConstant();
assembler->BuildFastFixedArrayForEach( assembler->BuildFastFixedArrayForEach(
function_context, FAST_ELEMENTS, min_context_slots, length, function_context, FAST_ELEMENTS, min_context_slots, length,
[undefined](CodeStubAssembler* assembler, Node* context, Node* offset) { [assembler, undefined](Node* context, Node* offset) {
assembler->StoreNoWriteBarrier(MachineType::PointerRepresentation(), assembler->StoreNoWriteBarrier(MachineType::PointerRepresentation(),
context, offset, undefined); context, offset, undefined);
}); });
......
...@@ -79,21 +79,20 @@ void AccessorAssemblerImpl::HandlePolymorphicCase( ...@@ -79,21 +79,20 @@ void AccessorAssemblerImpl::HandlePolymorphicCase(
Node* length = LoadAndUntagFixedArrayBaseLength(feedback); Node* length = LoadAndUntagFixedArrayBaseLength(feedback);
BuildFastLoop( BuildFastLoop(
MachineType::PointerRepresentation(), init, length, MachineType::PointerRepresentation(), init, length,
[receiver_map, feedback, if_handler, var_handler](CodeStubAssembler* csa, [this, receiver_map, feedback, if_handler, var_handler](Node* index) {
Node* index) { Node* cached_map = LoadWeakCellValue(
Node* cached_map = csa->LoadWeakCellValue( LoadFixedArrayElement(feedback, index, 0, INTPTR_PARAMETERS));
csa->LoadFixedArrayElement(feedback, index, 0, INTPTR_PARAMETERS));
Label next_entry(csa); Label next_entry(this);
csa->GotoIf(csa->WordNotEqual(receiver_map, cached_map), &next_entry); GotoIf(WordNotEqual(receiver_map, cached_map), &next_entry);
// Found, now call handler. // Found, now call handler.
Node* handler = csa->LoadFixedArrayElement( Node* handler = LoadFixedArrayElement(feedback, index, kPointerSize,
feedback, index, kPointerSize, INTPTR_PARAMETERS); INTPTR_PARAMETERS);
var_handler->Bind(handler); var_handler->Bind(handler);
csa->Goto(if_handler); Goto(if_handler);
csa->Bind(&next_entry); Bind(&next_entry);
}, },
kEntrySize, IndexAdvanceMode::kPost); kEntrySize, IndexAdvanceMode::kPost);
// The loop falls through if no handler was found. // The loop falls through if no handler was found.
...@@ -111,28 +110,26 @@ void AccessorAssemblerImpl::HandleKeyedStorePolymorphicCase( ...@@ -111,28 +110,26 @@ void AccessorAssemblerImpl::HandleKeyedStorePolymorphicCase(
Node* init = IntPtrConstant(0); Node* init = IntPtrConstant(0);
Node* length = LoadAndUntagFixedArrayBaseLength(feedback); Node* length = LoadAndUntagFixedArrayBaseLength(feedback);
BuildFastLoop( BuildFastLoop(MachineType::PointerRepresentation(), init, length,
MachineType::PointerRepresentation(), init, length, [this, receiver_map, feedback, if_handler, var_handler,
[receiver_map, feedback, if_handler, var_handler, if_transition_handler, if_transition_handler, var_transition_map_cell](Node* index) {
var_transition_map_cell](CodeStubAssembler* csa, Node* index) { Node* cached_map = LoadWeakCellValue(LoadFixedArrayElement(
Node* cached_map = csa->LoadWeakCellValue( feedback, index, 0, INTPTR_PARAMETERS));
csa->LoadFixedArrayElement(feedback, index, 0, INTPTR_PARAMETERS)); Label next_entry(this);
Label next_entry(csa); GotoIf(WordNotEqual(receiver_map, cached_map), &next_entry);
csa->GotoIf(csa->WordNotEqual(receiver_map, cached_map), &next_entry);
Node* maybe_transition_map_cell = LoadFixedArrayElement(
Node* maybe_transition_map_cell = csa->LoadFixedArrayElement(
feedback, index, kPointerSize, INTPTR_PARAMETERS); feedback, index, kPointerSize, INTPTR_PARAMETERS);
var_handler->Bind(csa->LoadFixedArrayElement( var_handler->Bind(LoadFixedArrayElement(
feedback, index, 2 * kPointerSize, INTPTR_PARAMETERS)); feedback, index, 2 * kPointerSize, INTPTR_PARAMETERS));
csa->GotoIf( GotoIf(WordEqual(maybe_transition_map_cell,
csa->WordEqual(maybe_transition_map_cell, LoadRoot(Heap::kUndefinedValueRootIndex)),
csa->LoadRoot(Heap::kUndefinedValueRootIndex)),
if_handler); if_handler);
var_transition_map_cell->Bind(maybe_transition_map_cell); var_transition_map_cell->Bind(maybe_transition_map_cell);
csa->Goto(if_transition_handler); Goto(if_transition_handler);
csa->Bind(&next_entry); Bind(&next_entry);
}, },
kEntrySize, IndexAdvanceMode::kPost); kEntrySize, IndexAdvanceMode::kPost);
// The loop falls through if no handler was found. // The loop falls through if no handler was found.
...@@ -424,7 +421,7 @@ Node* AccessorAssemblerImpl::EmitLoadICProtoArrayCheck( ...@@ -424,7 +421,7 @@ Node* AccessorAssemblerImpl::EmitLoadICProtoArrayCheck(
BuildFastLoop( BuildFastLoop(
MachineType::PointerRepresentation(), start_index.value(), handler_length, MachineType::PointerRepresentation(), start_index.value(), handler_length,
[this, p, handler, miss](CodeStubAssembler*, Node* current) { [this, p, handler, miss](Node* current) {
Node* prototype_cell = Node* prototype_cell =
LoadFixedArrayElement(handler, current, 0, INTPTR_PARAMETERS); LoadFixedArrayElement(handler, current, 0, INTPTR_PARAMETERS);
CheckPrototype(prototype_cell, p->name, miss); CheckPrototype(prototype_cell, p->name, miss);
...@@ -579,7 +576,7 @@ void AccessorAssemblerImpl::HandleStoreICProtoHandler( ...@@ -579,7 +576,7 @@ void AccessorAssemblerImpl::HandleStoreICProtoHandler(
Node* length = SmiUntag(maybe_transition_cell); Node* length = SmiUntag(maybe_transition_cell);
BuildFastLoop(MachineType::PointerRepresentation(), BuildFastLoop(MachineType::PointerRepresentation(),
IntPtrConstant(StoreHandler::kFirstPrototypeIndex), length, IntPtrConstant(StoreHandler::kFirstPrototypeIndex), length,
[this, p, handler, miss](CodeStubAssembler*, Node* current) { [this, p, handler, miss](Node* current) {
Node* prototype_cell = LoadFixedArrayElement( Node* prototype_cell = LoadFixedArrayElement(
handler, current, 0, INTPTR_PARAMETERS); handler, current, 0, INTPTR_PARAMETERS);
CheckPrototype(prototype_cell, p->name, miss); CheckPrototype(prototype_cell, p->name, miss);
......
...@@ -1742,9 +1742,8 @@ TEST(ArgumentsForEach) { ...@@ -1742,9 +1742,8 @@ TEST(ArgumentsForEach) {
sum.Bind(m.IntPtrConstant(0)); sum.Bind(m.IntPtrConstant(0));
arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) { arguments.ForEach(
sum.Bind(assembler->IntPtrAdd(sum.value(), arg)); list, [&m, &sum](Node* arg) { sum.Bind(m.IntPtrAdd(sum.value(), arg)); });
});
m.Return(sum.value()); m.Return(sum.value());
......
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