From a90c023d5e191ff722626b80e847fea52b053131 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Wed, 27 Jun 2012 14:46:01 +0000 Subject: [PATCH] Allow inlining of functions containing array literals. R=yangguo@chromium.org BUG=v8:1322 TEST=mjsunit/compiler/inline-literals Review URL: https://chromiumcodereview.appspot.com/10689005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11942 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-codegen-arm.cc | 8 ++++---- src/ast.cc | 2 +- src/ia32/lithium-codegen-ia32.cc | 7 +++---- src/mips/lithium-codegen-mips.cc | 9 +++++---- src/x64/lithium-codegen-x64.cc | 7 +++---- test/mjsunit/compiler/inline-literals.js | 20 ++++++++++++++++++++ 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index a61e4c0..e0633d5 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -4754,7 +4754,7 @@ void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { - Heap* heap = isolate()->heap(); + Handle literals(instr->environment()->closure()->literals()); ElementsKind boilerplate_elements_kind = instr->hydrogen()->boilerplate_elements_kind(); @@ -4774,12 +4774,12 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { DeoptimizeIf(ne, instr->environment()); } - __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); - __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); + // Set up the parameters to the stub/runtime call. + __ LoadHeapObject(r3, literals); __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); // Boilerplate already exists, constant elements are never accessed. // Pass an empty fixed array. - __ mov(r1, Operand(Handle(heap->empty_fixed_array()))); + __ mov(r1, Operand(isolate()->factory()->empty_fixed_array())); __ Push(r3, r2, r1); // Pick the right runtime function or stub to call. diff --git a/src/ast.cc b/src/ast.cc index 013c633..8ac139f 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -1048,6 +1048,7 @@ REGULAR_NODE(Conditional) REGULAR_NODE(Literal) REGULAR_NODE(ObjectLiteral) REGULAR_NODE(RegExpLiteral) +REGULAR_NODE(ArrayLiteral) REGULAR_NODE(Assignment) REGULAR_NODE(Throw) REGULAR_NODE(Property) @@ -1078,7 +1079,6 @@ DONT_OPTIMIZE_NODE(DebuggerStatement) DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) DONT_INLINE_NODE(FunctionLiteral) -DONT_INLINE_NODE(ArrayLiteral) // TODO(1322): Allow materialized literals. DONT_SELFOPTIMIZE_NODE(DoWhileStatement) DONT_SELFOPTIMIZE_NODE(WhileStatement) diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 9cc67a3..48cd780 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -4685,7 +4685,7 @@ void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { ASSERT(ToRegister(instr->context()).is(esi)); - Heap* heap = isolate()->heap(); + Handle literals(instr->environment()->closure()->literals()); ElementsKind boilerplate_elements_kind = instr->hydrogen()->boilerplate_elements_kind(); @@ -4706,12 +4706,11 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { } // 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()))); // Boilerplate already exists, constant elements are never accessed. // Pass an empty fixed array. - __ push(Immediate(Handle(heap->empty_fixed_array()))); + __ push(Immediate(isolate()->factory()->empty_fixed_array())); // Pick the right runtime function or stub to call. int length = instr->hydrogen()->length(); diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index 60df710..a992799 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -4522,7 +4522,7 @@ void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { - Heap* heap = isolate()->heap(); + Handle literals(instr->environment()->closure()->literals()); ElementsKind boilerplate_elements_kind = instr->hydrogen()->boilerplate_elements_kind(); @@ -4543,12 +4543,13 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { a2, Operand(boilerplate_elements_kind)); } - __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); - __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset)); + + // Set up the parameters to the stub/runtime call. + __ LoadHeapObject(a3, literals); __ li(a2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); // Boilerplate already exists, constant elements are never accessed. // Pass an empty fixed array. - __ li(a1, Operand(Handle(heap->empty_fixed_array()))); + __ li(a1, Operand(isolate()->factory()->empty_fixed_array())); __ Push(a3, a2, a1); // Pick the right runtime function or stub to call. diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 77cb75d..a19fcec 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -4401,7 +4401,7 @@ void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { - Heap* heap = isolate()->heap(); + Handle literals(instr->environment()->closure()->literals()); ElementsKind boilerplate_elements_kind = instr->hydrogen()->boilerplate_elements_kind(); @@ -4422,12 +4422,11 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { } // 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())); // Boilerplate already exists, constant elements are never accessed. // Pass an empty fixed array. - __ Push(Handle(heap->empty_fixed_array())); + __ Push(isolate()->factory()->empty_fixed_array()); // Pick the right runtime function or stub to call. int length = instr->hydrogen()->length(); diff --git a/test/mjsunit/compiler/inline-literals.js b/test/mjsunit/compiler/inline-literals.js index ece1ad7..1422586 100644 --- a/test/mjsunit/compiler/inline-literals.js +++ b/test/mjsunit/compiler/inline-literals.js @@ -29,6 +29,26 @@ // Test that we can inline functions containing materialized literals. +function a2(b, c) { + return [b, c, b + c]; +} + +function a1(a, b, c) { + return [a, a2(b, c)]; +} + +function TestArrayLiteral(a, b, c) { + var expected = [a, [b, c, b + c]]; + var result = a1(a, b, c); + assertEquals(expected, result, "TestArrayLiteral"); +} + +TestArrayLiteral(1, 2, 3); +TestArrayLiteral(1, 2, 3); +%OptimizeFunctionOnNextCall(TestArrayLiteral); +TestArrayLiteral(1, 2, 3); +TestArrayLiteral('a', 'b', 'c'); + function o2(b, c) { return { 'b':b, 'c':c, 'y':b + c }; } -- 2.7.4