From 1244225ba8a2c69aed0a4c4cdf5fb88479244931 Mon Sep 17 00:00:00 2001 From: "sgjesse@chromium.org" Date: Mon, 4 Apr 2011 15:03:34 +0000 Subject: [PATCH] Extend crankshaft support for global stores All global stores are now supported in crankshaft by using the normal store IC when other optimizations are not possible due to the state of the global object. R=fschneider@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org//6693066 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7495 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.cc | 15 ++++++++--- src/arm/lithium-arm.h | 28 +++++++++++++++---- src/arm/lithium-codegen-arm.cc | 12 ++++++++- src/hydrogen-instructions.cc | 8 +++++- src/hydrogen-instructions.h | 45 ++++++++++++++++++++++++++----- src/hydrogen.cc | 16 +++++++++-- src/ia32/lithium-codegen-ia32.cc | 13 ++++++++- src/ia32/lithium-ia32.cc | 15 +++++++++-- src/ia32/lithium-ia32.h | 31 +++++++++++++++++---- src/x64/lithium-codegen-x64.cc | 13 +++++++-- src/x64/lithium-x64.cc | 14 +++++++--- src/x64/lithium-x64.h | 28 +++++++++++++++---- test/cctest/test-log-stack-tracer.cc | 3 +++ test/mjsunit/global-accessors.js | 52 ++++++++++++++++++++++++++++++++++++ 14 files changed, 257 insertions(+), 36 deletions(-) create mode 100644 test/mjsunit/global-accessors.js diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index d69f0d5..1a3267b 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -1738,18 +1738,27 @@ LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { } -LInstruction* LChunkBuilder::DoStoreGlobal(HStoreGlobal* instr) { +LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { if (instr->check_hole_value()) { LOperand* temp = TempRegister(); LOperand* value = UseRegister(instr->value()); - return AssignEnvironment(new LStoreGlobal(value, temp)); + return AssignEnvironment(new LStoreGlobalCell(value, temp)); } else { LOperand* value = UseRegisterAtStart(instr->value()); - return new LStoreGlobal(value, NULL); + return new LStoreGlobalCell(value, NULL); } } +LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) { + LOperand* global_object = UseFixed(instr->global_object(), r1); + LOperand* value = UseFixed(instr->value(), r0); + LStoreGlobalGeneric* result = + new LStoreGlobalGeneric(global_object, value); + return MarkAsCall(result, instr); +} + + LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { LOperand* context = UseRegisterAtStart(instr->value()); return DefineAsRegister(new LLoadContextSlot(context)); diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 32ec0f8..f406f95 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -145,7 +145,8 @@ class LCodeGen; V(SmiUntag) \ V(StackCheck) \ V(StoreContextSlot) \ - V(StoreGlobal) \ + V(StoreGlobalCell) \ + V(StoreGlobalGeneric) \ V(StoreKeyedFastElement) \ V(StoreKeyedGeneric) \ V(StoreKeyedSpecializedArrayElement) \ @@ -1282,15 +1283,32 @@ class LLoadGlobalGeneric: public LTemplateInstruction<1, 1, 0> { }; -class LStoreGlobal: public LTemplateInstruction<0, 1, 1> { +class LStoreGlobalCell: public LTemplateInstruction<0, 1, 1> { public: - LStoreGlobal(LOperand* value, LOperand* temp) { + LStoreGlobalCell(LOperand* value, LOperand* temp) { inputs_[0] = value; temps_[0] = temp; } - DECLARE_CONCRETE_INSTRUCTION(StoreGlobal, "store-global") - DECLARE_HYDROGEN_ACCESSOR(StoreGlobal) + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalCell, "store-global-cell") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalCell) +}; + + +class LStoreGlobalGeneric: public LTemplateInstruction<0, 2, 0> { + public: + explicit LStoreGlobalGeneric(LOperand* global_object, + LOperand* value) { + inputs_[0] = global_object; + inputs_[1] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalGeneric, "store-global-generic") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalGeneric) + + LOperand* global_object() { return InputAt(0); } + Handle name() const { return hydrogen()->name(); } + LOperand* value() { return InputAt(1); } }; diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 7a3ab38..b214169 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -2187,7 +2187,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { } -void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { +void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { Register value = ToRegister(instr->InputAt(0)); Register scratch = scratch0(); @@ -2212,6 +2212,16 @@ void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { } +void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { + ASSERT(ToRegister(instr->global_object()).is(r1)); + ASSERT(ToRegister(instr->value()).is(r0)); + + __ mov(r2, Operand(instr->name())); + Handle ic = isolate()->builtins()->StoreIC_Initialize(); + CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); +} + + void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { Register context = ToRegister(instr->context()); Register result = ToRegister(instr->result()); diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index eec1237..f7adea6 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -1353,12 +1353,18 @@ void HLoadGlobalGeneric::PrintDataTo(StringStream* stream) { } -void HStoreGlobal::PrintDataTo(StringStream* stream) { +void HStoreGlobalCell::PrintDataTo(StringStream* stream) { stream->Add("[%p] = ", *cell()); value()->PrintNameTo(stream); } +void HStoreGlobalGeneric::PrintDataTo(StringStream* stream) { + stream->Add("%o = ", *name()); + value()->PrintNameTo(stream); +} + + void HLoadContextSlot::PrintDataTo(StringStream* stream) { value()->PrintNameTo(stream); stream->Add("[%d]", slot_index()); diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index fb45ee9..b2bdeb0 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -148,7 +148,8 @@ class LChunkBuilder; V(Simulate) \ V(StackCheck) \ V(StoreContextSlot) \ - V(StoreGlobal) \ + V(StoreGlobalCell) \ + V(StoreGlobalGeneric) \ V(StoreKeyedFastElement) \ V(StoreKeyedSpecializedArrayElement) \ V(StoreKeyedGeneric) \ @@ -2878,11 +2879,11 @@ class HLoadGlobalGeneric: public HBinaryOperation { }; -class HStoreGlobal: public HUnaryOperation { +class HStoreGlobalCell: public HUnaryOperation { public: - HStoreGlobal(HValue* value, - Handle cell, - bool check_hole_value) + HStoreGlobalCell(HValue* value, + Handle cell, + bool check_hole_value) : HUnaryOperation(value), cell_(cell), check_hole_value_(check_hole_value) { @@ -2897,7 +2898,7 @@ class HStoreGlobal: public HUnaryOperation { } virtual void PrintDataTo(StringStream* stream); - DECLARE_CONCRETE_INSTRUCTION(StoreGlobal, "store_global") + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalCell, "store_global_cell") private: Handle cell_; @@ -2905,6 +2906,38 @@ class HStoreGlobal: public HUnaryOperation { }; +class HStoreGlobalGeneric: public HTemplateInstruction<3> { + public: + HStoreGlobalGeneric(HValue* context, + HValue* global_object, + Handle name, + HValue* value) + : name_(name) { + SetOperandAt(0, context); + SetOperandAt(1, global_object); + SetOperandAt(2, value); + set_representation(Representation::Tagged()); + SetAllSideEffects(); + } + + HValue* context() { return OperandAt(0); } + HValue* global_object() { return OperandAt(1); } + Handle name() const { return name_; } + HValue* value() { return OperandAt(2); } + + virtual void PrintDataTo(StringStream* stream); + + virtual Representation RequiredInputRepresentation(int index) const { + return Representation::Tagged(); + } + + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalGeneric, "store_global_generic") + + private: + Handle name_; +}; + + class HLoadContextSlot: public HUnaryOperation { public: HLoadContextSlot(HValue* context , int slot_index) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 433618f..1748258 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3296,12 +3296,24 @@ void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var, bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly(); Handle global(info()->global_object()); Handle cell(global->GetPropertyCell(&lookup)); - HInstruction* instr = new HStoreGlobal(value, cell, check_hole); + HInstruction* instr = new HStoreGlobalCell(value, cell, check_hole); instr->set_position(position); AddInstruction(instr); if (instr->HasSideEffects()) AddSimulate(ast_id); } else { - BAILOUT("global store only supported for cells"); + HContext* context = new HContext; + AddInstruction(context); + HGlobalObject* global_object = new HGlobalObject(context); + AddInstruction(global_object); + HStoreGlobalGeneric* instr = + new HStoreGlobalGeneric(context, + global_object, + var->name(), + value); + instr->set_position(position); + AddInstruction(instr); + ASSERT(instr->HasSideEffects()); + if (instr->HasSideEffects()) AddSimulate(ast_id); } } diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index eb31d5a..88f413a 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -2055,7 +2055,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { } -void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { +void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { Register value = ToRegister(instr->InputAt(0)); Operand cell_operand = Operand::Cell(instr->hydrogen()->cell()); @@ -2073,6 +2073,17 @@ void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { } +void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { + ASSERT(ToRegister(instr->context()).is(esi)); + ASSERT(ToRegister(instr->global_object()).is(edx)); + ASSERT(ToRegister(instr->value()).is(eax)); + + __ mov(ecx, instr->name()); + Handle ic = isolate()->builtins()->StoreIC_Initialize(); + CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); +} + + void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { Register context = ToRegister(instr->context()); Register result = ToRegister(instr->result()); diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index d9192d4..ed126ba 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -1761,12 +1761,23 @@ LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { } -LInstruction* LChunkBuilder::DoStoreGlobal(HStoreGlobal* instr) { - LStoreGlobal* result = new LStoreGlobal(UseRegisterAtStart(instr->value())); +LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { + LStoreGlobalCell* result = + new LStoreGlobalCell(UseRegisterAtStart(instr->value())); return instr->check_hole_value() ? AssignEnvironment(result) : result; } +LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) { + LOperand* context = UseFixed(instr->context(), esi); + LOperand* global_object = UseFixed(instr->global_object(), edx); + LOperand* value = UseFixed(instr->value(), eax); + LStoreGlobalGeneric* result = + new LStoreGlobalGeneric(context, global_object, value); + return MarkAsCall(result, instr); +} + + LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { LOperand* context = UseRegisterAtStart(instr->value()); return DefineAsRegister(new LLoadContextSlot(context)); diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index e5792e8..fe7681b 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -147,7 +147,8 @@ class LCodeGen; V(SmiUntag) \ V(StackCheck) \ V(StoreContextSlot) \ - V(StoreGlobal) \ + V(StoreGlobalCell) \ + V(StoreGlobalGeneric) \ V(StoreKeyedFastElement) \ V(StoreKeyedGeneric) \ V(StoreKeyedSpecializedArrayElement) \ @@ -1317,14 +1318,34 @@ class LLoadGlobalGeneric: public LTemplateInstruction<1, 2, 0> { }; -class LStoreGlobal: public LTemplateInstruction<0, 1, 0> { +class LStoreGlobalCell: public LTemplateInstruction<0, 1, 0> { public: - explicit LStoreGlobal(LOperand* value) { + explicit LStoreGlobalCell(LOperand* value) { inputs_[0] = value; } - DECLARE_CONCRETE_INSTRUCTION(StoreGlobal, "store-global") - DECLARE_HYDROGEN_ACCESSOR(StoreGlobal) + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalCell, "store-global-cell") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalCell) +}; + + +class LStoreGlobalGeneric: public LTemplateInstruction<0, 3, 0> { + public: + explicit LStoreGlobalGeneric(LOperand* context, + LOperand* global_object, + LOperand* value) { + inputs_[0] = context; + inputs_[1] = global_object; + inputs_[2] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalGeneric, "store-global-generic") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalGeneric) + + LOperand* context() { return InputAt(0); } + LOperand* global_object() { return InputAt(1); } + Handle name() const { return hydrogen()->name(); } + LOperand* value() { return InputAt(2); } }; diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 8e54f20..7ceff76 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -2047,7 +2047,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { } -void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { +void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { Register value = ToRegister(instr->InputAt(0)); Register temp = ToRegister(instr->TempAt(0)); ASSERT(!value.is(temp)); @@ -2070,6 +2070,16 @@ void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { } +void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { + ASSERT(ToRegister(instr->global_object()).is(rdx)); + ASSERT(ToRegister(instr->value()).is(rax)); + + __ Move(rcx, instr->name()); + Handle ic = isolate()->builtins()->StoreIC_Initialize(); + CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); +} + + void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { Register context = ToRegister(instr->context()); Register result = ToRegister(instr->result()); @@ -2744,7 +2754,6 @@ void LCodeGen::DoPower(LPower* instr) { ExternalReference::power_double_int_function(isolate()), 2); } else { ASSERT(exponent_type.IsTagged()); - CpuFeatures::Scope scope(SSE2); Register right_reg = ToRegister(right); Label non_smi, call; diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 3d28b66..6987d45 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -1732,13 +1732,21 @@ LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { } -LInstruction* LChunkBuilder::DoStoreGlobal(HStoreGlobal* instr) { - LStoreGlobal* result = new LStoreGlobal(UseRegister(instr->value()), - TempRegister()); +LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { + LStoreGlobalCell* result = + new LStoreGlobalCell(UseRegister(instr->value()), TempRegister()); return instr->check_hole_value() ? AssignEnvironment(result) : result; } +LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) { + LOperand* global_object = UseFixed(instr->global_object(), rdx); + LOperand* value = UseFixed(instr->value(), rax); + LStoreGlobalGeneric* result = new LStoreGlobalGeneric(global_object, value); + return MarkAsCall(result, instr); +} + + LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { LOperand* context = UseRegisterAtStart(instr->value()); return DefineAsRegister(new LLoadContextSlot(context)); diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index 57ef30b..512abbb 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -145,7 +145,8 @@ class LCodeGen; V(SmiUntag) \ V(StackCheck) \ V(StoreContextSlot) \ - V(StoreGlobal) \ + V(StoreGlobalCell) \ + V(StoreGlobalGeneric) \ V(StoreKeyedFastElement) \ V(StoreKeyedGeneric) \ V(StoreKeyedSpecializedArrayElement) \ @@ -1268,15 +1269,32 @@ class LLoadGlobalGeneric: public LTemplateInstruction<1, 1, 0> { }; -class LStoreGlobal: public LTemplateInstruction<0, 1, 1> { +class LStoreGlobalCell: public LTemplateInstruction<0, 1, 1> { public: - explicit LStoreGlobal(LOperand* value, LOperand* temp) { + explicit LStoreGlobalCell(LOperand* value, LOperand* temp) { inputs_[0] = value; temps_[0] = temp; } - DECLARE_CONCRETE_INSTRUCTION(StoreGlobal, "store-global") - DECLARE_HYDROGEN_ACCESSOR(StoreGlobal) + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalCell, "store-global-cell") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalCell) +}; + + +class LStoreGlobalGeneric: public LTemplateInstruction<0, 2, 0> { + public: + explicit LStoreGlobalGeneric(LOperand* global_object, + LOperand* value) { + inputs_[0] = global_object; + inputs_[1] = value; + } + + DECLARE_CONCRETE_INSTRUCTION(StoreGlobalGeneric, "store-global-generic") + DECLARE_HYDROGEN_ACCESSOR(StoreGlobalGeneric) + + LOperand* global_object() { return InputAt(0); } + Handle name() const { return hydrogen()->name(); } + LOperand* value() { return InputAt(1); } }; diff --git a/test/cctest/test-log-stack-tracer.cc b/test/cctest/test-log-stack-tracer.cc index df0806f..f713957 100644 --- a/test/cctest/test-log-stack-tracer.cc +++ b/test/cctest/test-log-stack-tracer.cc @@ -280,6 +280,9 @@ static void CreateTraceCallerFunction(const char* func_name, // StackTracer uses Isolate::c_entry_fp as a starting point for stack // walking. TEST(CFromJSStackTrace) { + // BUG(1303) Inlining of JSFuncDoTrace() in JSTrace below breaks this test. + i::FLAG_use_inlining = false; + TickSample sample; InitTraceEnv(&sample); diff --git a/test/mjsunit/global-accessors.js b/test/mjsunit/global-accessors.js new file mode 100644 index 0000000..47f4328 --- /dev/null +++ b/test/mjsunit/global-accessors.js @@ -0,0 +1,52 @@ +// Copyright 2010 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 accessors on the global object. + +var x_ = 0; + +__defineSetter__('x', function(x) { x_ = x; }); +__defineGetter__('x', function() { return x_; }); + +__defineSetter__('y', function(x) { }); +__defineGetter__('y', function() { return 7; }); + +function f(a) { + x = x + a; + return x; +} + +function g(a) { + y = y + a; + return y; +} + +assertEquals(1, f(1)); +assertEquals(3, f(2)); + +assertEquals(7, g(1)); +assertEquals(7, g(2)); -- 2.7.4