From: fschneider@chromium.org Date: Tue, 27 Oct 2009 16:11:12 +0000 (+0000) Subject: Support for property access (named, keyed) in the fast compiler. X-Git-Tag: upstream/4.7.83~23066 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=64e1d3205f09d4f713e01ef91aa390982876c65b;p=platform%2Fupstream%2Fv8.git Support for property access (named, keyed) in the fast compiler. The generated code is similar to the existing code, but we never inline any IC code in the fast compiler. Review URL: http://codereview.chromium.org/337045 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3152 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm/fast-codegen-arm.cc b/src/arm/fast-codegen-arm.cc index bb5edc63d..e1a4ba51d 100644 --- a/src/arm/fast-codegen-arm.cc +++ b/src/arm/fast-codegen-arm.cc @@ -497,6 +497,45 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { } +void FastCodeGenerator::VisitProperty(Property* expr) { + Comment cmnt(masm_, "[ Property"); + Expression* key = expr->key(); + uint32_t dummy; + + // Evaluate receiver. + Visit(expr->obj()); + + if (key->AsLiteral() != NULL && key->AsLiteral()->handle()->IsSymbol() && + !String::cast(*(key->AsLiteral()->handle()))->AsArrayIndex(&dummy)) { + // Do a NAMED property load. + // The IC expects the property name in ecx and the receiver on the stack. + __ mov(r2, Operand(key->AsLiteral()->handle())); + Handle ic(Builtins::builtin(Builtins::LoadIC_Initialize)); + __ Call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a "test eax,..." + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + } else { + // Do a KEYED property load. + Visit(expr->key()); + Handle ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); + __ Call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a "test eax,..." + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + // Drop key and receiver left on the stack by IC. + __ pop(); + } + switch (expr->location().type()) { + case Location::TEMP: + __ str(r0, MemOperand(sp)); + break; + case Location::NOWHERE: + __ pop(); + } +} + + void FastCodeGenerator::VisitCall(Call* expr) { Comment cmnt(masm_, "[ Call"); Expression* fun = expr->expression(); diff --git a/src/compiler.cc b/src/compiler.cc index 23fb46ebb..4975cf376 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -697,7 +697,9 @@ void CodeGenSelector::VisitThrow(Throw* expr) { void CodeGenSelector::VisitProperty(Property* expr) { - BAILOUT("Property"); + Visit(expr->obj()); + CHECK_BAILOUT; + Visit(expr->key()); } diff --git a/src/fast-codegen.cc b/src/fast-codegen.cc index bb53f4197..8655e97a8 100644 --- a/src/fast-codegen.cc +++ b/src/fast-codegen.cc @@ -351,11 +351,6 @@ void FastCodeGenerator::VisitThrow(Throw* expr) { } -void FastCodeGenerator::VisitProperty(Property* expr) { - UNREACHABLE(); -} - - void FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { UNREACHABLE(); } diff --git a/src/ia32/fast-codegen-ia32.cc b/src/ia32/fast-codegen-ia32.cc index c24f41ad7..5dd1332c3 100644 --- a/src/ia32/fast-codegen-ia32.cc +++ b/src/ia32/fast-codegen-ia32.cc @@ -205,11 +205,12 @@ void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { __ mov(ecx, expr->name()); Handle ic(Builtins::builtin(Builtins::LoadIC_Initialize)); __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); + // By emitting a nop we make sure that we do not have a test eax + // instruction after the call it is treated specially by the LoadIC code + // Remember that the assembler may choose to do peephole optimization + // (eg, push/pop elimination). + __ nop(); - // A test eax instruction following the call is used by the IC to - // indicate that the inobject property case was inlined. Ensure there - // is no test eax instruction here. Remember that the assembler may - // choose to do peephole optimization (eg, push/pop elimination). switch (expr->location().type()) { case Location::NOWHERE: __ add(Operand(esp), Immediate(kPointerSize)); @@ -492,6 +493,46 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { } +void FastCodeGenerator::VisitProperty(Property* expr) { + Comment cmnt(masm_, "[ Property"); + Expression* key = expr->key(); + uint32_t dummy; + + // Evaluate receiver. + Visit(expr->obj()); + + if (key->AsLiteral() != NULL && key->AsLiteral()->handle()->IsSymbol() && + !String::cast(*(key->AsLiteral()->handle()))->AsArrayIndex(&dummy)) { + // Do a NAMED property load. + // The IC expects the property name in ecx and the receiver on the stack. + __ mov(ecx, Immediate(key->AsLiteral()->handle())); + Handle ic(Builtins::builtin(Builtins::LoadIC_Initialize)); + __ call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a test eax + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + } else { + // Do a KEYED property load. + Visit(expr->key()); + Handle ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); + __ call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a "test eax,..." + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + // Drop key left on the stack by IC. + __ add(Operand(esp), Immediate(kPointerSize)); + } + switch (expr->location().type()) { + case Location::TEMP: + __ mov(Operand(esp, 0), eax); + break; + case Location::NOWHERE: + __ add(Operand(esp), Immediate(kPointerSize)); + break; + } +} + + void FastCodeGenerator::VisitCall(Call* expr) { Expression* fun = expr->expression(); ZoneList* args = expr->arguments(); diff --git a/src/x64/fast-codegen-x64.cc b/src/x64/fast-codegen-x64.cc index 315d7f1d8..dc87ef327 100644 --- a/src/x64/fast-codegen-x64.cc +++ b/src/x64/fast-codegen-x64.cc @@ -506,6 +506,46 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { } +void FastCodeGenerator::VisitProperty(Property* expr) { + Comment cmnt(masm_, "[ Property"); + Expression* key = expr->key(); + uint32_t dummy; + + // Evaluate receiver. + Visit(expr->obj()); + + if (key->AsLiteral() != NULL && key->AsLiteral()->handle()->IsSymbol() && + !String::cast(*(key->AsLiteral()->handle()))->AsArrayIndex(&dummy)) { + // Do a NAMED property load. + // The IC expects the property name in rcx and the receiver on the stack. + __ Move(rcx, key->AsLiteral()->handle()); + Handle ic(Builtins::builtin(Builtins::LoadIC_Initialize)); + __ call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a "test eax,..." + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + } else { + // Do a KEYED property load. + Visit(expr->key()); + Handle ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); + __ call(ic, RelocInfo::CODE_TARGET); + // By emitting a nop we make sure that we do not have a "test ..." + // instruction after the call it is treated specially by the LoadIC code. + __ nop(); + // Drop key left on the stack by IC. + __ addq(rsp, Immediate(kPointerSize)); + } + switch (expr->location().type()) { + case Location::TEMP: + __ movq(Operand(rsp, 0), rax); + break; + case Location::NOWHERE: + __ addq(rsp, Immediate(kPointerSize)); + break; + } +} + + void FastCodeGenerator::VisitCall(Call* expr) { Expression* fun = expr->expression(); ZoneList* args = expr->arguments(); diff --git a/test/mjsunit/compiler/property-simple.js b/test/mjsunit/compiler/property-simple.js new file mode 100644 index 000000000..b0f0ffa6e --- /dev/null +++ b/test/mjsunit/compiler/property-simple.js @@ -0,0 +1,39 @@ +// Copyright 2009 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Test for property access + +var a; +var b; + +code = "a = {x:8, y:9}; a.x"; + +assertEquals(8, eval(code)); + +code = "b = {z:a}; b.z.y"; + +assertEquals(9, eval(code));