Commit 697aa6f5 authored by danno's avatar danno Committed by Commit bot

[stubs]: Generalize loop handling in CodeStubAssembler and improve common loop performance

Specifically an attempt to address a 3.5% regression on the total load
time on cnn introduced by https://codereview.chromium.org/2113673002.

Non-refactoring effect of this CL is to reduce the number of branches in
CodeStubAssembler-generated loops iterating over FixedArrays from
two to one.

LOG=N
BUG=v8:5423

Review-Url: https://codereview.chromium.org/2380953002
Cr-Commit-Position: refs/heads/master@{#40020}
parent a3d0c2e0
This diff is collapsed.
......@@ -832,6 +832,27 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* CreateAllocationSiteInFeedbackVector(
compiler::Node* feedback_vector, compiler::Node* slot);
enum class IndexAdvanceMode { kPre, kPost };
void BuildFastLoop(
MachineRepresentation index_rep, compiler::Node* start_index,
compiler::Node* end_index,
std::function<void(CodeStubAssembler* assembler, compiler::Node* index)>
body,
int increment, IndexAdvanceMode mode = IndexAdvanceMode::kPre);
enum class ForEachDirection { kForward, kReverse };
void BuildFastFixedArrayForEach(
compiler::Node* fixed_array, ElementsKind kind,
compiler::Node* first_element_inclusive,
compiler::Node* last_element_exclusive,
std::function<void(CodeStubAssembler* assembler,
compiler::Node* fixed_array, compiler::Node* offset)>
body,
ParameterMode mode = INTPTR_PARAMETERS,
ForEachDirection direction = ForEachDirection::kReverse);
compiler::Node* GetFixedArrayAllocationSize(compiler::Node* element_count,
ElementsKind kind,
ParameterMode mode) {
......
......@@ -5167,9 +5167,7 @@ void FastNewClosureStub::GenerateAssembly(CodeStubAssembler* assembler) const {
compiler::Node* FastNewFunctionContextStub::Generate(
CodeStubAssembler* assembler, compiler::Node* function,
compiler::Node* slots, compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
Node* min_context_slots =
assembler->Int32Constant(Context::MIN_CONTEXT_SLOTS);
......@@ -5208,24 +5206,12 @@ compiler::Node* FastNewFunctionContextStub::Generate(
// Initialize the rest of the slots to undefined.
Node* undefined = assembler->UndefinedConstant();
Variable var_slot_index(assembler, MachineRepresentation::kWord32);
var_slot_index.Bind(min_context_slots);
Label loop(assembler, &var_slot_index), after_loop(assembler);
assembler->Goto(&loop);
assembler->Bind(&loop);
{
Node* slot_index = var_slot_index.value();
assembler->GotoUnless(assembler->Int32LessThan(slot_index, length),
&after_loop);
assembler->StoreFixedArrayElement(function_context, slot_index, undefined,
SKIP_WRITE_BARRIER);
Node* one = assembler->Int32Constant(1);
Node* next_index = assembler->Int32Add(slot_index, one);
var_slot_index.Bind(next_index);
assembler->Goto(&loop);
}
assembler->Bind(&after_loop);
assembler->BuildFastFixedArrayForEach(
function_context, FAST_ELEMENTS, min_context_slots, length,
[undefined](CodeStubAssembler* assembler, Node* context, Node* offset) {
assembler->StoreNoWriteBarrier(MachineType::PointerRepresentation(),
context, offset, undefined);
});
return function_context;
}
......
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