Commit 0a373f8a authored by jgruber's avatar jgruber Committed by Commit Bot

[stubs] Route all ArrayConstructor stub accesses through CodeFactory

This is the initial step towards moving all array constructor stubs to
builtins.

Bug: v8:6666
Change-Id: I49b86e43ab4ee3d0889853a2624e189ff7d2e705
Reviewed-on: https://chromium-review.googlesource.com/1073417Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53396}
parent 307ebc35
......@@ -2914,20 +2914,23 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmp(r3, Operand(kind));
T stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq);
__ Jump(
CodeFactory::ArrayNoArgumentConstructor(masm->isolate(), kind, mode)
.code(),
RelocInfo::CODE_TARGET, eq);
}
// If we reached this point there is a problem.
......@@ -2955,9 +2958,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence;
......@@ -2990,8 +2994,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmp(r3, Operand(kind));
ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(masm->isolate(), kind,
DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET, eq);
}
// If we reached this point there is a problem.
......@@ -3006,7 +3012,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
Label not_zero_case, not_one_case;
__ tst(r0, r0);
__ b(ne, &not_zero_case);
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ bind(&not_zero_case);
__ cmp(r0, Operand(1));
......@@ -3081,8 +3087,9 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
ElementsKind kind) {
__ cmp(r0, Operand(1));
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0, lo);
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET, lo);
Handle<Code> code = BUILTIN_CODE(masm->isolate(), ArrayNArgumentsConstructor);
__ Jump(code, RelocInfo::CODE_TARGET, hi);
......@@ -3093,13 +3100,16 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ ldr(r3, MemOperand(sp, 0));
__ cmp(r3, Operand::Zero());
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey, ne);
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET, ne);
}
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
}
} // namespace
......
......@@ -3443,8 +3443,39 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
// TODO(jbramley): If this needs to be a special case, make it a proper template
// specialization, and not a separate function.
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
ASM_LOCATION("CreateArrayDispatch");
if (mode == DISABLE_ALLOCATION_SITES) {
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
Register kind = x3;
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
Label next;
ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
// TODO(jbramley): Is this the best way to handle this? Can we make the
// tail calls conditional, rather than hopping over each one?
__ CompareAndBranch(kind, candidate_kind, ne, &next);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(masm->isolate(),
candidate_kind, mode)
.code(),
RelocInfo::CODE_TARGET);
__ Bind(&next);
}
// If we reached this point there is a problem.
__ Abort(AbortReason::kUnexpectedElementsKindInArrayConstructor);
} else {
UNREACHABLE();
}
}
void CreateArrayDispatchOneArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
ASM_LOCATION("CreateArrayDispatchOneArgument");
......@@ -3468,9 +3499,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// Is the low bit set? If so, the array is holey.
Label normal_sequence;
......@@ -3506,44 +3538,15 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
Label next;
ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
__ CompareAndBranch(kind, candidate_kind, ne, &next);
ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
__ TailCallStub(&stub);
__ Bind(&next);
}
// If we reached this point there is a problem.
__ Abort(AbortReason::kUnexpectedElementsKindInArrayConstructor);
} else {
UNREACHABLE();
}
}
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
ASM_LOCATION("CreateArrayDispatch");
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
} else if (mode == DONT_OVERRIDE) {
Register kind = x3;
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
Label next;
ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
// TODO(jbramley): Is this the best way to handle this? Can we make the
// tail calls conditional, rather than hopping over each one?
__ CompareAndBranch(kind, candidate_kind, ne, &next);
T stub(masm->isolate(), candidate_kind);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), candidate_kind, DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET);
__ Bind(&next);
}
// If we reached this point there is a problem.
__ Abort(AbortReason::kUnexpectedElementsKindInArrayConstructor);
} else {
UNREACHABLE();
}
......@@ -3562,7 +3565,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
__ Bind(&zero_case);
// No arguments.
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ Bind(&n_case);
// N arguments.
......@@ -3652,19 +3655,24 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ Peek(x10, 0);
__ Cbz(x10, &packed_case);
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey);
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET);
__ Bind(&packed_case);
}
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ Bind(&zero_case);
// No arguments.
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0);
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ Bind(&n_case);
// N arguments.
......
......@@ -3150,12 +3150,13 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
......@@ -3164,8 +3165,10 @@ void CreateArrayDispatch(MacroAssembler* masm,
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmp(edx, kind);
__ j(not_equal, &next);
T stub(masm->isolate(), kind);
__ TailCallStub(&stub);
__ Jump(
CodeFactory::ArrayNoArgumentConstructor(masm->isolate(), kind, mode)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&next);
}
......@@ -3195,9 +3198,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence;
......@@ -3231,8 +3235,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmp(edx, kind);
__ j(not_equal, &next);
ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(masm->isolate(), kind,
DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&next);
}
......@@ -3248,7 +3254,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
Label not_zero_case, not_one_case;
__ test(eax, eax);
__ j(not_zero, &not_zero_case);
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ bind(&not_zero_case);
__ cmp(eax, 1);
......@@ -3332,8 +3338,9 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ test(eax, eax);
__ j(not_zero, &not_zero_case);
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0);
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&not_zero_case);
__ cmp(eax, 1);
......@@ -3346,14 +3353,17 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ test(ecx, ecx);
__ j(zero, &normal_sequence);
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey);
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET);
}
__ bind(&normal_sequence);
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&not_one_case);
Handle<Code> code = BUILTIN_CODE(masm->isolate(), ArrayNArgumentsConstructor);
......
......@@ -3038,19 +3038,22 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
T stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq, a3, Operand(kind));
__ Jump(
CodeFactory::ArrayNoArgumentConstructor(masm->isolate(), kind, mode)
.code(),
RelocInfo::CODE_TARGET, eq, a3, Operand(kind));
}
// If we reached this point there is a problem.
......@@ -3078,9 +3081,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence;
......@@ -3113,8 +3117,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq, a3, Operand(kind));
__ Jump(CodeFactory::ArraySingleArgumentConstructor(masm->isolate(), kind,
DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET, eq, a3, Operand(kind));
}
// If we reached this point there is a problem.
......@@ -3129,7 +3135,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
Label not_zero_case, not_one_case;
__ And(kScratchReg, a0, a0);
__ Branch(&not_zero_case, ne, kScratchReg, Operand(zero_reg));
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ bind(&not_zero_case);
__ Branch(&not_one_case, gt, a0, Operand(1));
......@@ -3204,8 +3210,9 @@ namespace {
void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
ElementsKind kind) {
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0, lo, a0, Operand(1));
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET, lo, a0, Operand(1));
__ Jump(BUILTIN_CODE(masm->isolate(), ArrayNArgumentsConstructor),
RelocInfo::CODE_TARGET, hi, a0, Operand(1));
......@@ -3215,13 +3222,16 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
// look at the first argument.
__ lw(kScratchReg, MemOperand(sp, 0));
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey, ne, kScratchReg, Operand(zero_reg));
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET, ne, kScratchReg, Operand(zero_reg));
}
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
}
} // namespace
......
......@@ -3056,19 +3056,22 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
T stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq, a3, Operand(kind));
__ Jump(
CodeFactory::ArrayNoArgumentConstructor(masm->isolate(), kind, mode)
.code(),
RelocInfo::CODE_TARGET, eq, a3, Operand(kind));
}
// If we reached this point there is a problem.
......@@ -3096,9 +3099,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence;
......@@ -3131,8 +3135,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= last_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
__ TailCallStub(&stub, eq, a3, Operand(kind));
__ Jump(CodeFactory::ArraySingleArgumentConstructor(masm->isolate(), kind,
DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET, eq, a3, Operand(kind));
}
// If we reached this point there is a problem.
......@@ -3147,7 +3153,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
Label not_zero_case, not_one_case;
__ And(kScratchReg, a0, a0);
__ Branch(&not_zero_case, ne, kScratchReg, Operand(zero_reg));
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ bind(&not_zero_case);
__ Branch(&not_one_case, gt, a0, Operand(1));
......@@ -3222,8 +3228,9 @@ namespace {
void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
ElementsKind kind) {
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0, lo, a0, Operand(1));
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET, lo, a0, Operand(1));
__ Jump(BUILTIN_CODE(masm->isolate(), ArrayNArgumentsConstructor),
RelocInfo::CODE_TARGET, hi, a0, Operand(1));
......@@ -3233,13 +3240,16 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
// look at the first argument.
__ Ld(kScratchReg, MemOperand(sp, 0));
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey, ne, kScratchReg, Operand(zero_reg));
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET, ne, kScratchReg, Operand(zero_reg));
}
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
}
} // namespace
......
......@@ -3095,12 +3095,13 @@ void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
namespace {
template <class T>
void CreateArrayDispatch(MacroAssembler* masm,
void CreateArrayDispatchNoArgument(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArrayNoArgumentConstructor(
masm->isolate(), GetInitialFastElementsKind(), mode)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
int last_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
......@@ -3109,8 +3110,10 @@ void CreateArrayDispatch(MacroAssembler* masm,
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmpl(rdx, Immediate(kind));
__ j(not_equal, &next);
T stub(masm->isolate(), kind);
__ TailCallStub(&stub);
__ Jump(
CodeFactory::ArrayNoArgumentConstructor(masm->isolate(), kind, mode)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&next);
}
......@@ -3141,9 +3144,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(
masm->isolate(), holey_initial, DISABLE_ALLOCATION_SITES)
.code(),
RelocInfo::CODE_TARGET);
} else if (mode == DONT_OVERRIDE) {
// is the low bit set? If so, we are holey and that is good.
Label normal_sequence;
......@@ -3177,8 +3181,10 @@ void CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
__ cmpl(rdx, Immediate(kind));
__ j(not_equal, &next);
ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
__ TailCallStub(&stub);
__ Jump(CodeFactory::ArraySingleArgumentConstructor(masm->isolate(), kind,
DONT_OVERRIDE)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&next);
}
......@@ -3194,7 +3200,7 @@ void GenerateDispatchToArrayStub(MacroAssembler* masm,
Label not_zero_case, not_one_case;
__ testp(rax, rax);
__ j(not_zero, &not_zero_case);
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
CreateArrayDispatchNoArgument(masm, mode);
__ bind(&not_zero_case);
__ cmpl(rax, Immediate(1));
......@@ -3279,8 +3285,9 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ testp(rax, rax);
__ j(not_zero, &not_zero_case);
InternalArrayNoArgumentConstructorStub stub0(masm->isolate(), kind);
__ TailCallStub(&stub0);
__ Jump(CodeFactory::InternalArrayNoArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&not_zero_case);
__ cmpl(rax, Immediate(1));
......@@ -3294,14 +3301,17 @@ void GenerateInternalArrayConstructorCase(MacroAssembler* masm,
__ testp(rcx, rcx);
__ j(zero, &normal_sequence);
InternalArraySingleArgumentConstructorStub stub1_holey(
masm->isolate(), GetHoleyElementsKind(kind));
__ TailCallStub(&stub1_holey);
__ Jump(CodeFactory::InternalArraySingleArgumentConstructor(
masm->isolate(), GetHoleyElementsKind(kind))
.code(),
RelocInfo::CODE_TARGET);
}
__ bind(&normal_sequence);
InternalArraySingleArgumentConstructorStub stub1(masm->isolate(), kind);
__ TailCallStub(&stub1);
__ Jump(
CodeFactory::InternalArraySingleArgumentConstructor(masm->isolate(), kind)
.code(),
RelocInfo::CODE_TARGET);
__ bind(&not_one_case);
Handle<Code> code = BUILTIN_CODE(masm->isolate(), ArrayNArgumentsConstructor);
......
......@@ -333,6 +333,36 @@ Callable CodeFactory::InterpreterOnStackReplacement(Isolate* isolate) {
ContextOnlyDescriptor(isolate));
}
// static
Callable CodeFactory::ArrayNoArgumentConstructor(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode) {
ArrayNoArgumentConstructorStub stub(isolate, kind, override_mode);
return make_callable(stub);
}
// static
Callable CodeFactory::ArraySingleArgumentConstructor(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode) {
ArraySingleArgumentConstructorStub stub(isolate, kind, override_mode);
return make_callable(stub);
}
// static
Callable CodeFactory::InternalArrayNoArgumentConstructor(Isolate* isolate,
ElementsKind kind) {
InternalArrayNoArgumentConstructorStub stub(isolate, kind);
return make_callable(stub);
}
// static
Callable CodeFactory::InternalArraySingleArgumentConstructor(
Isolate* isolate, ElementsKind kind) {
InternalArraySingleArgumentConstructorStub stub(isolate, kind);
return make_callable(stub);
}
// static
Callable CodeFactory::ArrayPop(Isolate* isolate) {
return Callable(BUILTIN_CODE(isolate, ArrayPop), BuiltinDescriptor(isolate));
......
......@@ -85,6 +85,18 @@ class V8_EXPORT_PRIVATE CodeFactory final {
static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1);
static Callable InterpreterOnStackReplacement(Isolate* isolate);
static Callable ArrayNoArgumentConstructor(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode);
static Callable ArraySingleArgumentConstructor(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode);
static Callable InternalArrayNoArgumentConstructor(Isolate* isolate,
ElementsKind kind);
static Callable InternalArraySingleArgumentConstructor(Isolate* isolate,
ElementsKind kind);
static Callable ArrayPop(Isolate* isolate);
static Callable ArrayPush(Isolate* isolate);
static Callable ArrayShift(Isolate* isolate);
......
......@@ -465,17 +465,18 @@ void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
namespace {
template <class T>
void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
int to_index =
GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
for (int i = 0; i <= to_index; ++i) {
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
T stub(isolate, kind);
stub.GetCode();
CodeFactory::ArrayNoArgumentConstructor(isolate, kind, DONT_OVERRIDE);
CodeFactory::ArraySingleArgumentConstructor(isolate, kind, DONT_OVERRIDE);
if (AllocationSite::ShouldTrack(kind)) {
T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
stub1.GetCode();
CodeFactory::ArrayNoArgumentConstructor(isolate, kind,
DISABLE_ALLOCATION_SITES);
CodeFactory::ArraySingleArgumentConstructor(isolate, kind,
DISABLE_ALLOCATION_SITES);
}
}
}
......@@ -483,18 +484,12 @@ void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
} // namespace
void CommonArrayConstructorStub::GenerateStubsAheadOfTime(Isolate* isolate) {
ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
isolate);
ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
isolate);
ArrayConstructorStubAheadOfTimeHelper(isolate);
ElementsKind kinds[2] = {PACKED_ELEMENTS, HOLEY_ELEMENTS};
for (int i = 0; i < 2; i++) {
// For internal arrays we only need a few things
InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
stubh1.GetCode();
InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
stubh2.GetCode();
CodeFactory::InternalArrayNoArgumentConstructor(isolate, kinds[i]);
CodeFactory::InternalArraySingleArgumentConstructor(isolate, kinds[i]);
}
}
......
......@@ -626,13 +626,14 @@ class CommonArrayConstructorStub : public TurboFanCodeStub {
};
class ArrayNoArgumentConstructorStub : public CommonArrayConstructorStub {
public:
private:
ArrayNoArgumentConstructorStub(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
: CommonArrayConstructorStub(isolate, kind, override_mode) {}
private:
friend class CodeFactory;
void PrintName(std::ostream& os) const override { // NOLINT
os << "ArrayNoArgumentConstructorStub";
}
......@@ -644,11 +645,12 @@ class ArrayNoArgumentConstructorStub : public CommonArrayConstructorStub {
class InternalArrayNoArgumentConstructorStub
: public CommonArrayConstructorStub {
public:
private:
InternalArrayNoArgumentConstructorStub(Isolate* isolate, ElementsKind kind)
: CommonArrayConstructorStub(isolate, kind, DONT_OVERRIDE) {}
private:
friend class CodeFactory;
void PrintName(std::ostream& os) const override { // NOLINT
os << "InternalArrayNoArgumentConstructorStub";
}
......@@ -659,13 +661,14 @@ class InternalArrayNoArgumentConstructorStub
};
class ArraySingleArgumentConstructorStub : public CommonArrayConstructorStub {
public:
private:
ArraySingleArgumentConstructorStub(
Isolate* isolate, ElementsKind kind,
AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
: CommonArrayConstructorStub(isolate, kind, override_mode) {}
private:
friend class CodeFactory;
void PrintName(std::ostream& os) const override { // NOLINT
os << "ArraySingleArgumentConstructorStub";
}
......@@ -677,12 +680,13 @@ class ArraySingleArgumentConstructorStub : public CommonArrayConstructorStub {
class InternalArraySingleArgumentConstructorStub
: public CommonArrayConstructorStub {
public:
private:
InternalArraySingleArgumentConstructorStub(Isolate* isolate,
ElementsKind kind)
: CommonArrayConstructorStub(isolate, kind, DONT_OVERRIDE) {}
private:
friend class CodeFactory;
void PrintName(std::ostream& os) const override { // NOLINT
os << "InternalArraySingleArgumentConstructorStub";
}
......
......@@ -727,24 +727,24 @@ Reduction JSCreateLowering::ReduceNewArrayToStubCall(
: Operator::kNoDeopt | Operator::kNoWrite;
if (arity == 0) {
ArrayNoArgumentConstructorStub stub(isolate(), elements_kind,
override_mode);
Callable callable = CodeFactory::ArrayNoArgumentConstructor(
isolate(), elements_kind, override_mode);
auto call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(),
arity + 1, CallDescriptor::kNeedsFrameState, properties);
node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode()));
isolate(), graph()->zone(), callable.descriptor(), arity + 1,
CallDescriptor::kNeedsFrameState, properties);
node->ReplaceInput(0, jsgraph()->HeapConstant(callable.code()));
node->InsertInput(graph()->zone(), 2, type_info);
node->InsertInput(graph()->zone(), 3, jsgraph()->Constant(arity));
node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant());
NodeProperties::ChangeOp(node, common()->Call(call_descriptor));
} else if (arity == 1) {
// Require elements kind to "go holey".
ArraySingleArgumentConstructorStub stub(
Callable callable = CodeFactory::ArraySingleArgumentConstructor(
isolate(), GetHoleyElementsKind(elements_kind), override_mode);
auto call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(),
arity + 1, CallDescriptor::kNeedsFrameState, properties);
node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode()));
isolate(), graph()->zone(), callable.descriptor(), arity + 1,
CallDescriptor::kNeedsFrameState, properties);
node->ReplaceInput(0, jsgraph()->HeapConstant(callable.code()));
node->InsertInput(graph()->zone(), 2, type_info);
node->InsertInput(graph()->zone(), 3, jsgraph()->Constant(arity));
node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant());
......
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