Allow inlining of functions containing object literals.
R=fschneider@chromium.org BUG=v8:1322 TEST=mjsunit/compiler/inline-literals Review URL: https://chromiumcodereview.appspot.com/9388007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10689 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
ed54dd2042
commit
0db91d40e9
@ -4431,11 +4431,12 @@ void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) {
|
||||
|
||||
|
||||
void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
Handle<FixedArray> literals(instr->environment()->closure()->literals());
|
||||
Handle<FixedArray> constant_properties =
|
||||
instr->hydrogen()->constant_properties();
|
||||
|
||||
__ ldr(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
|
||||
__ ldr(r4, FieldMemOperand(r4, JSFunction::kLiteralsOffset));
|
||||
// Set up the parameters to the stub/runtime call.
|
||||
__ LoadHeapObject(r4, literals);
|
||||
__ mov(r3, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
|
||||
__ mov(r2, Operand(constant_properties));
|
||||
int flags = instr->hydrogen()->fast_elements()
|
||||
@ -4444,7 +4445,7 @@ void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
__ mov(r1, Operand(Smi::FromInt(flags)));
|
||||
__ Push(r4, r3, r2, r1);
|
||||
|
||||
// Pick the right runtime function to call.
|
||||
// Pick the right runtime function or stub to call.
|
||||
int properties_count = constant_properties->length() / 2;
|
||||
if (instr->hydrogen()->depth() > 1) {
|
||||
CallRuntime(Runtime::kCreateObjectLiteral, 4, instr);
|
||||
|
@ -1009,6 +1009,7 @@ INCREASE_NODE_COUNT(BreakStatement)
|
||||
INCREASE_NODE_COUNT(ReturnStatement)
|
||||
INCREASE_NODE_COUNT(Conditional)
|
||||
INCREASE_NODE_COUNT(Literal)
|
||||
INCREASE_NODE_COUNT(ObjectLiteral)
|
||||
INCREASE_NODE_COUNT(Assignment)
|
||||
INCREASE_NODE_COUNT(Throw)
|
||||
INCREASE_NODE_COUNT(Property)
|
||||
@ -1112,12 +1113,6 @@ void AstConstructionVisitor::VisitRegExpLiteral(RegExpLiteral* node) {
|
||||
}
|
||||
|
||||
|
||||
void AstConstructionVisitor::VisitObjectLiteral(ObjectLiteral* node) {
|
||||
increase_node_count();
|
||||
add_flag(kDontInline); // TODO(1322): Allow materialized literals.
|
||||
}
|
||||
|
||||
|
||||
void AstConstructionVisitor::VisitArrayLiteral(ArrayLiteral* node) {
|
||||
increase_node_count();
|
||||
add_flag(kDontInline); // TODO(1322): Allow materialized literals.
|
||||
|
@ -4312,12 +4312,12 @@ void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) {
|
||||
|
||||
void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
ASSERT(ToRegister(instr->context()).is(esi));
|
||||
Handle<FixedArray> literals(instr->environment()->closure()->literals());
|
||||
Handle<FixedArray> constant_properties =
|
||||
instr->hydrogen()->constant_properties();
|
||||
|
||||
// Set up the parameters to the stub/runtime call.
|
||||
__ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
|
||||
__ push(FieldOperand(eax, JSFunction::kLiteralsOffset));
|
||||
__ PushHeapObject(literals);
|
||||
__ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index())));
|
||||
__ push(Immediate(constant_properties));
|
||||
int flags = instr->hydrogen()->fast_elements()
|
||||
|
@ -4334,12 +4334,12 @@ void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) {
|
||||
|
||||
void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
ASSERT(ToRegister(instr->result()).is(v0));
|
||||
|
||||
Handle<FixedArray> literals(instr->environment()->closure()->literals());
|
||||
Handle<FixedArray> constant_properties =
|
||||
instr->hydrogen()->constant_properties();
|
||||
|
||||
__ lw(t0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
|
||||
__ lw(t0, FieldMemOperand(t0, JSFunction::kLiteralsOffset));
|
||||
// Set up the parameters to the stub/runtime call.
|
||||
__ LoadHeapObject(t0, literals);
|
||||
__ li(a3, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
|
||||
__ li(a2, Operand(constant_properties));
|
||||
int flags = instr->hydrogen()->fast_elements()
|
||||
@ -4348,7 +4348,7 @@ void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
__ li(a1, Operand(Smi::FromInt(flags)));
|
||||
__ Push(t0, a3, a2, a1);
|
||||
|
||||
// Pick the right runtime function to call.
|
||||
// Pick the right runtime function or stub to call.
|
||||
int properties_count = constant_properties->length() / 2;
|
||||
if (instr->hydrogen()->depth() > 1) {
|
||||
CallRuntime(Runtime::kCreateObjectLiteral, 4, instr);
|
||||
|
@ -4028,12 +4028,12 @@ void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) {
|
||||
|
||||
|
||||
void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
Handle<FixedArray> literals(instr->environment()->closure()->literals());
|
||||
Handle<FixedArray> constant_properties =
|
||||
instr->hydrogen()->constant_properties();
|
||||
|
||||
// Set up the parameters to the stub/runtime call.
|
||||
__ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
|
||||
__ push(FieldOperand(rax, JSFunction::kLiteralsOffset));
|
||||
__ PushHeapObject(literals);
|
||||
__ Push(Smi::FromInt(instr->hydrogen()->literal_index()));
|
||||
__ Push(constant_properties);
|
||||
int flags = instr->hydrogen()->fast_elements()
|
||||
@ -4044,7 +4044,7 @@ void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) {
|
||||
: ObjectLiteral::kNoFlags;
|
||||
__ Push(Smi::FromInt(flags));
|
||||
|
||||
// Pick the right runtime function to call.
|
||||
// Pick the right runtime function or stub to call.
|
||||
int properties_count = constant_properties->length() / 2;
|
||||
if (instr->hydrogen()->depth() > 1) {
|
||||
CallRuntime(Runtime::kCreateObjectLiteral, 4, instr);
|
||||
|
50
test/mjsunit/compiler/inline-literals.js
Normal file
50
test/mjsunit/compiler/inline-literals.js
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
// Test that we can inline functions containing materialized literals.
|
||||
|
||||
function o2(b, c) {
|
||||
return { 'b':b, 'c':c, 'y':b + c };
|
||||
}
|
||||
|
||||
function o1(a, b, c) {
|
||||
return { 'a':a, 'x':o2(b, c) };
|
||||
}
|
||||
|
||||
function TestObjectLiteral(a, b, c) {
|
||||
var expected = { 'a':a, 'x':{ 'b':b, 'c':c, 'y':b + c } };
|
||||
var result = o1(a, b, c);
|
||||
assertEquals(expected, result, "TestObjectLiteral");
|
||||
}
|
||||
|
||||
TestObjectLiteral(1, 2, 3);
|
||||
TestObjectLiteral(1, 2, 3);
|
||||
%OptimizeFunctionOnNextCall(TestObjectLiteral);
|
||||
TestObjectLiteral(1, 2, 3);
|
||||
TestObjectLiteral('a', 'b', 'c');
|
Loading…
Reference in New Issue
Block a user