X87: Optimize the typeof operator.

port 7798548a8f (r28260)

original commit message:

    typeof was implemented as a runtime function. Calling it in
    optimized code with a non-constant input becomes burdensome.

BUG=

Review URL: https://codereview.chromium.org/1124263005

Cr-Commit-Position: refs/heads/master@{#28279}
This commit is contained in:
chunyang.dai 2015-05-06 21:01:39 -07:00 committed by Commit bot
parent c3529ce501
commit 4b0565262a
5 changed files with 23 additions and 6 deletions

View File

@ -2144,6 +2144,7 @@ void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
BinaryOpICStub::GenerateAheadOfTime(isolate);
BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
StoreFastElementStub::GenerateAheadOfTime(isolate);
TypeofStub::GenerateAheadOfTime(isolate);
}

View File

@ -4716,10 +4716,13 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
case Token::TYPEOF: {
Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
{ StackValueContext context(this);
{
AccumulatorValueContext context(this);
VisitForTypeofValue(expr->expression());
}
__ CallRuntime(Runtime::kTypeof, 1);
__ mov(ebx, eax);
TypeofStub typeof_stub(isolate());
__ CallStub(&typeof_stub);
context()->Plug(eax);
break;
}

View File

@ -86,6 +86,12 @@ void NumberToStringDescriptor::Initialize(CallInterfaceDescriptorData* data) {
}
void TypeofDescriptor::Initialize(CallInterfaceDescriptorData* data) {
Register registers[] = {esi, ebx};
data->Initialize(arraysize(registers), registers, NULL);
}
void FastCloneShallowArrayDescriptor::Initialize(
CallInterfaceDescriptorData* data) {
Register registers[] = {esi, eax, ebx, ecx};

View File

@ -5992,9 +5992,16 @@ void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) {
void LCodeGen::DoTypeof(LTypeof* instr) {
DCHECK(ToRegister(instr->context()).is(esi));
LOperand* input = instr->value();
EmitPushTaggedOperand(input);
CallRuntime(Runtime::kTypeof, 1, instr);
DCHECK(ToRegister(instr->value()).is(ebx));
Label end, do_call;
Register value_register = ToRegister(instr->value());
__ JumpIfNotSmi(value_register, &do_call);
__ mov(eax, Immediate(isolate()->factory()->number_string()));
__ jmp(&end);
__ bind(&do_call);
TypeofStub stub(isolate());
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
__ bind(&end);
}

View File

@ -2615,7 +2615,7 @@ LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
LOperand* context = UseFixed(instr->context(), esi);
LOperand* value = UseAtStart(instr->value());
LOperand* value = UseFixed(instr->value(), ebx);
LTypeof* result = new(zone()) LTypeof(context, value);
return MarkAsCall(DefineFixed(result, eax), instr);
}