Commit f439fcab authored by Alexander.Gilday2's avatar Alexander.Gilday2 Committed by Commit bot

[stubs] Port ToName stub to TurboFan.

Migrate the platform ToName stub to TurboFan.

BUG=v8:5049

Review-Url: https://codereview.chromium.org/2302923002
Cr-Commit-Position: refs/heads/master@{#39315}
parent bb0b8b2d
......@@ -2385,37 +2385,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in r0.
Label is_number;
__ JumpIfSmi(r0, &is_number);
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CompareObjectType(r0, r1, r1, LAST_NAME_TYPE);
// r0: receiver
// r1: receiver instance type
__ Ret(ls);
Label not_heap_number;
__ cmp(r1, Operand(HEAP_NUMBER_TYPE));
__ b(ne, &not_heap_number);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ cmp(r1, Operand(ODDBALL_TYPE));
__ b(ne, &not_oddball);
__ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ push(r0); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(
MacroAssembler* masm, Register left, Register right, Register scratch1,
Register scratch2, Register scratch3) {
......
......@@ -2963,39 +2963,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in x0.
Label is_number;
__ JumpIfSmi(x0, &is_number);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ JumpIfObjectType(x0, x1, x1, LAST_NAME_TYPE, &not_name, hi);
// x0: receiver
// x1: receiver instance type
__ Ret();
__ Bind(&not_name);
Label not_heap_number;
__ Cmp(x1, HEAP_NUMBER_TYPE);
__ B(ne, &not_heap_number);
__ Bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ Bind(&not_heap_number);
Label not_oddball;
__ Cmp(x1, ODDBALL_TYPE);
__ B(ne, &not_oddball);
__ Ldr(x0, FieldMemOperand(x0, Oddball::kToStringOffset));
__ Ret();
__ Bind(&not_oddball);
__ Push(x0); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(
MacroAssembler* masm, Register left, Register right, Register scratch1,
Register scratch2, Register scratch3) {
......
......@@ -119,6 +119,16 @@ void Builtins::Generate_StringToNumber(CodeStubAssembler* assembler) {
assembler->Return(assembler->StringToNumber(context, input));
}
void Builtins::Generate_ToName(CodeStubAssembler* assembler) {
typedef compiler::Node Node;
typedef TypeConversionDescriptor Descriptor;
Node* input = assembler->Parameter(Descriptor::kArgument);
Node* context = assembler->Parameter(Descriptor::kContext);
assembler->Return(assembler->ToName(context, input));
}
// ES6 section 7.1.3 ToNumber ( argument )
void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) {
typedef CodeStubAssembler::Label Label;
......
......@@ -183,6 +183,7 @@ namespace internal {
TFS(NonPrimitiveToPrimitive_String, BUILTIN, kNoExtraICState, \
TypeConversion) \
TFS(StringToNumber, BUILTIN, kNoExtraICState, TypeConversion) \
TFS(ToName, BUILTIN, kNoExtraICState, TypeConversion) \
TFS(NonNumberToNumber, BUILTIN, kNoExtraICState, TypeConversion) \
ASM(ToNumber) \
\
......
......@@ -189,8 +189,8 @@ Callable CodeFactory::ToString(Isolate* isolate) {
// static
Callable CodeFactory::ToName(Isolate* isolate) {
ToNameStub stub(isolate);
return make_callable(stub);
return Callable(isolate->builtins()->ToName(),
TypeConversionDescriptor(isolate));
}
// static
......
......@@ -2381,6 +2381,55 @@ Node* CodeStubAssembler::StringToNumber(Node* context, Node* input) {
return var_result.value();
}
Node* CodeStubAssembler::ToName(Node* context, Node* value) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Label end(this);
Variable var_result(this, MachineRepresentation::kTagged);
Label is_number(this);
GotoIf(WordIsSmi(value), &is_number);
Label not_name(this);
Node* value_instance_type = LoadInstanceType(value);
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
GotoIf(Int32GreaterThan(value_instance_type, Int32Constant(LAST_NAME_TYPE)),
&not_name);
var_result.Bind(value);
Goto(&end);
Bind(&is_number);
{
Callable callable = CodeFactory::NumberToString(isolate());
var_result.Bind(CallStub(callable, context, value));
Goto(&end);
}
Bind(&not_name);
{
GotoIf(Word32Equal(value_instance_type, Int32Constant(HEAP_NUMBER_TYPE)),
&is_number);
Label not_oddball(this);
GotoIf(Word32NotEqual(value_instance_type, Int32Constant(ODDBALL_TYPE)),
&not_oddball);
var_result.Bind(LoadObjectField(value, Oddball::kToStringOffset));
Goto(&end);
Bind(&not_oddball);
{
var_result.Bind(CallRuntime(Runtime::kToName, context, value));
Goto(&end);
}
}
Bind(&end);
return var_result.value();
}
Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift,
uint32_t mask) {
return Word32Shr(Word32And(word32, Int32Constant(mask)),
......
......@@ -429,6 +429,8 @@ class CodeStubAssembler : public compiler::CodeAssembler {
// Convert a String to a Number.
compiler::Node* StringToNumber(compiler::Node* context,
compiler::Node* input);
// Convert an object to a name.
compiler::Node* ToName(compiler::Node* context, compiler::Node* input);
// Returns a node that contains a decoded (unsigned!) value of a bit
// field |T| in |word32|. Returns result as an uint32 node.
......
......@@ -5088,9 +5088,7 @@ compiler::Node* ForInFilterStub::Generate(CodeStubAssembler* assembler,
assembler->Bind(&return_to_name);
{
// TODO(cbruni): inline ToName here.
Callable callable = CodeFactory::ToName(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, key));
var_result.Bind(assembler->ToName(context, key));
assembler->Goto(&end);
}
......
......@@ -44,7 +44,6 @@ class ObjectLiteral;
V(StoreElement) \
V(SubString) \
V(ToString) \
V(ToName) \
V(StoreIC) \
V(KeyedStoreIC) \
V(KeyedLoadIC) \
......@@ -3203,14 +3202,6 @@ class ToStringStub final : public PlatformCodeStub {
DEFINE_PLATFORM_CODE_STUB(ToString, PlatformCodeStub);
};
class ToNameStub final : public PlatformCodeStub {
public:
explicit ToNameStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
DEFINE_PLATFORM_CODE_STUB(ToName, PlatformCodeStub);
};
class ToObjectStub final : public TurboFanCodeStub {
public:
explicit ToObjectStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
......
......@@ -2323,42 +2323,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in eax.
Label is_number;
__ JumpIfSmi(eax, &is_number, Label::kNear);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CmpObjectType(eax, LAST_NAME_TYPE, edi);
// eax: receiver
// edi: receiver map
__ j(above, &not_name, Label::kNear);
__ Ret();
__ bind(&not_name);
Label not_heap_number;
__ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
__ j(not_equal, &not_heap_number, Label::kNear);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ CmpInstanceType(edi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ pop(ecx); // Pop return address.
__ push(eax); // Push argument.
__ push(ecx); // Push return address.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
......
......@@ -1303,7 +1303,9 @@ void Interpreter::DoUnaryOpWithFeedback(InterpreterAssembler* assembler) {
//
// Convert the object referenced by the accumulator to a name.
void Interpreter::DoToName(InterpreterAssembler* assembler) {
Node* result = BuildUnaryOp(CodeFactory::ToName(isolate_), assembler);
Node* object = __ GetAccumulator();
Node* context = __ GetContext();
Node* result = __ ToName(context, object);
__ StoreRegister(result, __ BytecodeOperandReg(0));
__ Dispatch();
}
......
......@@ -2529,39 +2529,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes on argument in a0.
Label is_number;
__ JumpIfSmi(a0, &is_number);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ GetObjectType(a0, a1, a1);
// a0: receiver
// a1: receiver instance type
__ Branch(&not_name, gt, a1, Operand(LAST_NAME_TYPE));
__ Ret(USE_DELAY_SLOT);
__ mov(v0, a0);
__ bind(&not_name);
Label not_heap_number;
__ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
__ Ret(USE_DELAY_SLOT);
__ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
__ bind(&not_oddball);
__ push(a0); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(
MacroAssembler* masm, Register left, Register right, Register scratch1,
Register scratch2, Register scratch3) {
......
......@@ -2537,39 +2537,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes on argument in a0.
Label is_number;
__ JumpIfSmi(a0, &is_number);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ GetObjectType(a0, a1, a1);
// a0: receiver
// a1: receiver instance type
__ Branch(&not_name, gt, a1, Operand(LAST_NAME_TYPE));
__ Ret(USE_DELAY_SLOT);
__ mov(v0, a0);
__ bind(&not_name);
Label not_heap_number;
__ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
__ Ret(USE_DELAY_SLOT);
__ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
__ bind(&not_oddball);
__ push(a0); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(
MacroAssembler* masm, Register left, Register right, Register scratch1,
Register scratch2, Register scratch3) {
......
......@@ -2464,37 +2464,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in r3.
Label is_number;
__ JumpIfSmi(r3, &is_number);
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CompareObjectType(r3, r4, r4, LAST_NAME_TYPE);
// r3: receiver
// r4: receiver instance type
__ Ret(le);
Label not_heap_number;
__ cmpi(r4, Operand(HEAP_NUMBER_TYPE));
__ bne(&not_heap_number);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ cmpi(r4, Operand(ODDBALL_TYPE));
__ bne(&not_oddball);
__ LoadP(r3, FieldMemOperand(r3, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ push(r3); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
......
......@@ -2466,36 +2466,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
__ Ret();
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in r2.
Label is_number;
__ JumpIfSmi(r2, &is_number);
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CompareObjectType(r2, r3, r3, LAST_NAME_TYPE);
// r2: receiver
// r3: receiver instance type
__ Ret(le);
Label not_heap_number;
__ CmpP(r3, Operand(HEAP_NUMBER_TYPE));
__ bne(&not_heap_number);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ CmpP(r3, Operand(ODDBALL_TYPE));
__ bne(&not_oddball);
__ LoadP(r2, FieldMemOperand(r2, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ push(r2); // Push argument.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
......
......@@ -2274,41 +2274,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kToString);
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in rax.
Label is_number;
__ JumpIfSmi(rax, &is_number, Label::kNear);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CmpObjectType(rax, LAST_NAME_TYPE, rdi);
// rax: receiver
// rdi: receiver map
__ j(above, &not_name, Label::kNear);
__ Ret();
__ bind(&not_name);
Label not_heap_number;
__ CompareRoot(rdi, Heap::kHeapNumberMapRootIndex);
__ j(not_equal, &not_heap_number, Label::kNear);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ CmpInstanceType(rdi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ movp(rax, FieldOperand(rax, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ PopReturnAddressTo(rcx); // Pop return address.
__ Push(rax); // Push argument.
__ PushReturnAddressFrom(rcx); // Push return address.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
......
......@@ -2165,42 +2165,6 @@ void ToStringStub::Generate(MacroAssembler* masm) {
}
void ToNameStub::Generate(MacroAssembler* masm) {
// The ToName stub takes one argument in eax.
Label is_number;
__ JumpIfSmi(eax, &is_number, Label::kNear);
Label not_name;
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CmpObjectType(eax, LAST_NAME_TYPE, edi);
// eax: receiver
// edi: receiver map
__ j(above, &not_name, Label::kNear);
__ Ret();
__ bind(&not_name);
Label not_heap_number;
__ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
__ j(not_equal, &not_heap_number, Label::kNear);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ CmpInstanceType(edi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ pop(ecx); // Pop return address.
__ push(eax); // Push argument.
__ push(ecx); // Push return address.
__ TailCallRuntime(Runtime::kToName);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
......
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