X87: Optimize the typeof operator.
authorchunyang.dai <chunyang.dai@intel.com>
Thu, 7 May 2015 04:01:39 +0000 (21:01 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 7 May 2015 04:01:45 +0000 (04:01 +0000)
port 7798548a8f2ef14e8320cc42effa86f0eb8e4294 (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}

src/x87/code-stubs-x87.cc
src/x87/full-codegen-x87.cc
src/x87/interface-descriptors-x87.cc
src/x87/lithium-codegen-x87.cc
src/x87/lithium-x87.cc

index 27eb2fc..f3d31ce 100644 (file)
@@ -2144,6 +2144,7 @@ void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
   BinaryOpICStub::GenerateAheadOfTime(isolate);
   BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
   StoreFastElementStub::GenerateAheadOfTime(isolate);
+  TypeofStub::GenerateAheadOfTime(isolate);
 }
 
 
index 4f980a7..877f91c 100644 (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;
     }
index 8a6b55e..515d56c 100644 (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};
index f2eb67c..86beee0 100644 (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);
 }
 
 
index 83aa33c..1b4aa1a 100644 (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);
 }