Commit ddda77ee authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Migrate NonNumberToNumber to TurboFan builtin.

Migrate the platform NonNumberToNumber builtin to TurboFan, and change
it to use the new NonPrimitiveToPrimitive builtin for the JSReceiver
case.

R=yangguo@chromium.org
BUG=v8:5049

Review-Url: https://codereview.chromium.org/2153053002
Cr-Commit-Position: refs/heads/master@{#37786}
parent eb372355
...@@ -2765,33 +2765,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2765,33 +2765,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in r0.
__ AssertNotNumber(r0);
__ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
// r0: receiver
// r1: receiver instance type
__ Jump(masm->isolate()->builtins()->StringToNumber(), RelocInfo::CODE_TARGET,
lo);
Label not_oddball;
__ cmp(r1, Operand(ODDBALL_TYPE));
__ b(ne, &not_oddball);
__ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
__ Ret();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(r0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- r0 : actual number of arguments // -- r0 : actual number of arguments
......
...@@ -2855,37 +2855,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2855,37 +2855,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in x0.
__ AssertNotNumber(x0);
Label not_string;
__ CompareObjectType(x0, x1, x1, FIRST_NONSTRING_TYPE);
// x0: receiver
// x1: receiver instance type
__ B(hs, &not_string);
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ Bind(&not_string);
Label not_oddball;
__ Cmp(x1, ODDBALL_TYPE);
__ B(ne, &not_oddball);
__ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
__ Ret();
__ Bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(x0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
ASM_LOCATION("Builtins::Generate_ArgumentsAdaptorTrampoline"); ASM_LOCATION("Builtins::Generate_ArgumentsAdaptorTrampoline");
// ----------- S t a t e ------------- // ----------- S t a t e -------------
......
...@@ -6272,6 +6272,104 @@ void Generate_NonPrimitiveToPrimitive_String(CodeStubAssembler* assembler) { ...@@ -6272,6 +6272,104 @@ void Generate_NonPrimitiveToPrimitive_String(CodeStubAssembler* assembler) {
Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kString); Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kString);
} }
// ES6 section 7.1.3 ToNumber ( argument )
void Generate_NonNumberToNumber(CodeStubAssembler* assembler) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
Node* input = assembler->Parameter(0);
Node* context = assembler->Parameter(1);
// We might need to loop once here due to ToPrimitive conversions.
Variable var_input(assembler, MachineRepresentation::kTagged);
Label loop(assembler, &var_input);
var_input.Bind(input);
assembler->Goto(&loop);
assembler->Bind(&loop);
{
// Load the current {input} value (known to be a HeapObject).
Node* input = var_input.value();
// Dispatch on the {input} instance type.
Node* input_instance_type = assembler->LoadInstanceType(input);
Label if_inputisstring(assembler), if_inputisoddball(assembler),
if_inputisreceiver(assembler, Label::kDeferred),
if_inputisother(assembler, Label::kDeferred);
assembler->GotoIf(assembler->Int32LessThan(
input_instance_type,
assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
&if_inputisstring);
assembler->GotoIf(
assembler->Word32Equal(input_instance_type,
assembler->Int32Constant(ODDBALL_TYPE)),
&if_inputisoddball);
STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
assembler->Branch(assembler->Int32GreaterThanOrEqual(
input_instance_type,
assembler->Int32Constant(FIRST_JS_RECEIVER_TYPE)),
&if_inputisreceiver, &if_inputisother);
assembler->Bind(&if_inputisstring);
{
// The {input} is a String, use the fast stub to convert it to a Number.
// TODO(bmeurer): Consider inlining the StringToNumber logic here.
Callable callable = CodeFactory::StringToNumber(assembler->isolate());
assembler->TailCallStub(callable, context, input);
}
assembler->Bind(&if_inputisoddball);
{
// The {input} is an Oddball, we just need to the Number value of it.
Node* result =
assembler->LoadObjectField(input, Oddball::kToNumberOffset);
assembler->Return(result);
}
assembler->Bind(&if_inputisreceiver);
{
// The {input} is a JSReceiver, we need to convert it to a Primitive first
// using the ToPrimitive type conversion, preferably yielding a Number.
Callable callable = CodeFactory::NonPrimitiveToPrimitive(
assembler->isolate(), ToPrimitiveHint::kNumber);
Node* result = assembler->CallStub(callable, context, input);
// Check if the {result} is already a Number.
Label if_resultisnumber(assembler), if_resultisnotnumber(assembler);
assembler->GotoIf(assembler->WordIsSmi(result), &if_resultisnumber);
Node* result_map = assembler->LoadMap(result);
assembler->Branch(
assembler->WordEqual(result_map, assembler->HeapNumberMapConstant()),
&if_resultisnumber, &if_resultisnotnumber);
assembler->Bind(&if_resultisnumber);
{
// The ToPrimitive conversion already gave us a Number, so we're done.
assembler->Return(result);
}
assembler->Bind(&if_resultisnotnumber);
{
// We now have a Primitive {result}, but it's not yet a Number.
var_input.Bind(result);
assembler->Goto(&loop);
}
}
assembler->Bind(&if_inputisother);
{
// The {input} is something else (i.e. Symbol or Simd128Value), let the
// runtime figure out the correct exception.
// Note: We cannot tail call to the runtime here, as js-to-wasm
// trampolines also use this code currently, and they declare all
// outgoing parameters as untagged, while we would push a tagged
// object here.
Node* result = assembler->CallRuntime(Runtime::kToNumber, context, input);
assembler->Return(result);
}
}
}
void Generate_KeyedStoreIC_Slow(MacroAssembler* masm) { void Generate_KeyedStoreIC_Slow(MacroAssembler* masm) {
ElementHandlerCompiler::GenerateStoreSlow(masm); ElementHandlerCompiler::GenerateStoreSlow(masm);
} }
......
...@@ -144,10 +144,7 @@ namespace internal { ...@@ -144,10 +144,7 @@ namespace internal {
DBG(Return_DebugBreak) \ DBG(Return_DebugBreak) \
DBG(Slot_DebugBreak) \ DBG(Slot_DebugBreak) \
DBG(FrameDropper_LiveEdit) \ DBG(FrameDropper_LiveEdit) \
/* Primitives */ \ /* Type conversions */ \
ASM(StringToNumber) \
ASM(NonNumberToNumber) \
ASM(ToNumber) \
TFS(OrdinaryToPrimitive_Number, BUILTIN, kNoExtraICState, TypeConversion) \ TFS(OrdinaryToPrimitive_Number, BUILTIN, kNoExtraICState, TypeConversion) \
TFS(OrdinaryToPrimitive_String, BUILTIN, kNoExtraICState, TypeConversion) \ TFS(OrdinaryToPrimitive_String, BUILTIN, kNoExtraICState, TypeConversion) \
TFS(NonPrimitiveToPrimitive_Default, BUILTIN, kNoExtraICState, \ TFS(NonPrimitiveToPrimitive_Default, BUILTIN, kNoExtraICState, \
...@@ -156,6 +153,9 @@ namespace internal { ...@@ -156,6 +153,9 @@ namespace internal {
TypeConversion) \ TypeConversion) \
TFS(NonPrimitiveToPrimitive_String, BUILTIN, kNoExtraICState, \ TFS(NonPrimitiveToPrimitive_String, BUILTIN, kNoExtraICState, \
TypeConversion) \ TypeConversion) \
ASM(StringToNumber) \
TFS(NonNumberToNumber, BUILTIN, kNoExtraICState, TypeConversion) \
ASM(ToNumber) \
\ \
/* Built-in functions for Javascript */ \ /* Built-in functions for Javascript */ \
/* Special internal builtins */ \ /* Special internal builtins */ \
...@@ -515,7 +515,6 @@ class Builtins { ...@@ -515,7 +515,6 @@ class Builtins {
static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm); static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm);
static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm); static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
static void Generate_StringToNumber(MacroAssembler* masm); static void Generate_StringToNumber(MacroAssembler* masm);
static void Generate_NonNumberToNumber(MacroAssembler* masm);
static void Generate_ToNumber(MacroAssembler* masm); static void Generate_ToNumber(MacroAssembler* masm);
static void Generate_Apply(MacroAssembler* masm); static void Generate_Apply(MacroAssembler* masm);
......
...@@ -2742,37 +2742,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2742,37 +2742,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in eax.
__ AssertNotNumber(eax);
Label not_string;
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
// eax: object
// edi: object map
__ j(above_equal, &not_string, Label::kNear);
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ bind(&not_string);
Label not_oddball;
__ CmpInstanceType(edi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset));
__ Ret();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(eax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : actual number of arguments // -- eax : actual number of arguments
......
...@@ -2840,36 +2840,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2840,36 +2840,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes on argument in a0.
__ AssertNotNumber(a0);
Label not_string;
__ GetObjectType(a0, a1, a1);
// a0: receiver
// a1: receiver instance type
__ Branch(&not_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ bind(&not_string);
Label not_oddball;
__ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
__ Ret(USE_DELAY_SLOT);
__ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset)); // In delay slot.
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(a0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// State setup as expected by MacroAssembler::InvokePrologue. // State setup as expected by MacroAssembler::InvokePrologue.
// ----------- S t a t e ------------- // ----------- S t a t e -------------
......
...@@ -2834,36 +2834,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2834,36 +2834,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes on argument in a0.
__ AssertNotNumber(a0);
Label not_string;
__ GetObjectType(a0, a1, a1);
// a0: receiver
// a1: receiver instance type
__ Branch(&not_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ bind(&not_string);
Label not_oddball;
__ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
__ Ret(USE_DELAY_SLOT);
__ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset)); // In delay slot.
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(a0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// State setup as expected by MacroAssembler::InvokePrologue. // State setup as expected by MacroAssembler::InvokePrologue.
// ----------- S t a t e ------------- // ----------- S t a t e -------------
......
...@@ -2840,35 +2840,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2840,35 +2840,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in r3.
__ AssertNotNumber(r3);
__ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE);
// r3: receiver
// r4: receiver instance type
__ Jump(masm->isolate()->builtins()->StringToNumber(), RelocInfo::CODE_TARGET,
lt);
Label not_oddball;
__ cmpi(r4, Operand(ODDBALL_TYPE));
__ bne(&not_oddball);
__ LoadP(r3, FieldMemOperand(r3, Oddball::kToNumberOffset));
__ blr();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(r3);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- r3 : actual number of arguments // -- r3 : actual number of arguments
......
...@@ -2856,35 +2856,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2856,35 +2856,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in r2.
__ AssertNotNumber(r2);
__ CompareObjectType(r2, r3, r3, FIRST_NONSTRING_TYPE);
// r2: receiver
// r3: receiver instance type
__ Jump(masm->isolate()->builtins()->StringToNumber(), RelocInfo::CODE_TARGET,
lt);
Label not_oddball;
__ CmpP(r3, Operand(ODDBALL_TYPE));
__ bne(&not_oddball);
__ LoadP(r2, FieldMemOperand(r2, Oddball::kToNumberOffset));
__ Ret();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(r2);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- r2 : actual number of arguments // -- r2 : actual number of arguments
......
...@@ -2159,37 +2159,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2159,37 +2159,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in rax.
__ AssertNotNumber(rax);
Label not_string;
__ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdi);
// rax: object
// rdi: object map
__ j(above_equal, &not_string, Label::kNear);
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ bind(&not_string);
Label not_oddball;
__ CmpInstanceType(rdi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ movp(rax, FieldOperand(rax, Oddball::kToNumberOffset));
__ Ret();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(rax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- rax : actual number of arguments // -- rax : actual number of arguments
......
...@@ -2766,37 +2766,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) { ...@@ -2766,37 +2766,6 @@ void Builtins::Generate_ToNumber(MacroAssembler* masm) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
// static
void Builtins::Generate_NonNumberToNumber(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in eax.
__ AssertNotNumber(eax);
Label not_string;
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
// eax: object
// edi: object map
__ j(above_equal, &not_string, Label::kNear);
__ Jump(masm->isolate()->builtins()->StringToNumber(),
RelocInfo::CODE_TARGET);
__ bind(&not_string);
Label not_oddball;
__ CmpInstanceType(edi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset));
__ Ret();
__ bind(&not_oddball);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(eax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kToNumber);
}
__ Ret();
}
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : actual number of arguments // -- eax : actual number of arguments
......
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