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
This commit is contained in:
sgjesse@chromium.org 2011-04-04 15:03:34 +00:00
parent 71b2572547
commit 1244225ba8
14 changed files with 257 additions and 36 deletions

View File

@ -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));

View File

@ -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<Object> name() const { return hydrogen()->name(); }
LOperand* value() { return InputAt(1); }
};

View File

@ -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<Code> 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());

View File

@ -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());

View File

@ -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<JSGlobalPropertyCell> cell,
bool check_hole_value)
HStoreGlobalCell(HValue* value,
Handle<JSGlobalPropertyCell> 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<JSGlobalPropertyCell> cell_;
@ -2905,6 +2906,38 @@ class HStoreGlobal: public HUnaryOperation {
};
class HStoreGlobalGeneric: public HTemplateInstruction<3> {
public:
HStoreGlobalGeneric(HValue* context,
HValue* global_object,
Handle<Object> 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<Object> 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<Object> name_;
};
class HLoadContextSlot: public HUnaryOperation {
public:
HLoadContextSlot(HValue* context , int slot_index)

View File

@ -3296,12 +3296,24 @@ void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var,
bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly();
Handle<GlobalObject> global(info()->global_object());
Handle<JSGlobalPropertyCell> 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);
}
}

View File

@ -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<Code> 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());

View File

@ -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));

View File

@ -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<Object> name() const { return hydrogen()->name(); }
LOperand* value() { return InputAt(2); }
};

View File

@ -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<Code> 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;

View File

@ -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));

View File

@ -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<Object> name() const { return hydrogen()->name(); }
LOperand* value() { return InputAt(1); }
};

View File

@ -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);

View File

@ -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));