Revision: 7495
Author: [email protected]
Date: Mon Apr 4 08:03:34 2011
Log: 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.
[email protected]
BUG=
TEST=
Review URL: http://codereview.chromium.org//6693066
http://code.google.com/p/v8/source/detail?r=7495
Added:
/branches/bleeding_edge/test/mjsunit/global-accessors.js
Modified:
/branches/bleeding_edge/src/arm/lithium-arm.cc
/branches/bleeding_edge/src/arm/lithium-arm.h
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.h
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.h
/branches/bleeding_edge/test/cctest/test-log-stack-tracer.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/global-accessors.js Mon Apr 4
08:03:34 2011
@@ -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));
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc Fri Apr 1 04:54:04 2011
+++ /branches/bleeding_edge/src/arm/lithium-arm.cc Mon Apr 4 08:03:34 2011
@@ -1738,16 +1738,25 @@
}
-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) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h Fri Apr 1 04:54:04 2011
+++ /branches/bleeding_edge/src/arm/lithium-arm.h Mon Apr 4 08:03:34 2011
@@ -145,7 +145,8 @@
V(SmiUntag) \
V(StackCheck) \
V(StoreContextSlot) \
- V(StoreGlobal) \
+ V(StoreGlobalCell) \
+ V(StoreGlobalGeneric) \
V(StoreKeyedFastElement) \
V(StoreKeyedGeneric) \
V(StoreKeyedSpecializedArrayElement) \
@@ -1282,15 +1283,32 @@
};
-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); }
};
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Fri Apr 1
04:54:04 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Mon Apr 4
08:03:34 2011
@@ -2187,7 +2187,7 @@
}
-void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) {
+void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) {
Register value = ToRegister(instr->InputAt(0));
Register scratch = scratch0();
@@ -2210,6 +2210,16 @@
// Store the value.
__ str(value, FieldMemOperand(scratch,
JSGlobalPropertyCell::kValueOffset));
}
+
+
+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) {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Mon Apr 4
01:57:21 2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Mon Apr 4
08:03:34 2011
@@ -1353,10 +1353,16 @@
}
-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) {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Mon Apr 4 01:57:21
2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Mon Apr 4 08:03:34
2011
@@ -148,7 +148,8 @@
V(Simulate) \
V(StackCheck) \
V(StoreContextSlot) \
- V(StoreGlobal) \
+ V(StoreGlobalCell) \
+ V(StoreGlobalGeneric) \
V(StoreKeyedFastElement) \
V(StoreKeyedSpecializedArrayElement) \
V(StoreKeyedGeneric) \
@@ -2878,11 +2879,11 @@
};
-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 @@
}
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 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)
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Fri Apr 1 07:46:30 2011
+++ /branches/bleeding_edge/src/hydrogen.cc Mon Apr 4 08:03:34 2011
@@ -3296,12 +3296,24 @@
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);
}
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Fri Apr 1
04:54:04 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Mon Apr 4
08:03:34 2011
@@ -2055,7 +2055,7 @@
}
-void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) {
+void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) {
Register value = ToRegister(instr->InputAt(0));
Operand cell_operand = Operand::Cell(instr->hydrogen()->cell());
@@ -2071,6 +2071,17 @@
// Store the value.
__ mov(cell_operand, value);
}
+
+
+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) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Fri Apr 1 04:54:04
2011
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Mon Apr 4 08:03:34
2011
@@ -1761,10 +1761,21 @@
}
-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) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h Fri Apr 1 04:54:04 2011
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h Mon Apr 4 08:03:34 2011
@@ -147,7 +147,8 @@
V(SmiUntag) \
V(StackCheck) \
V(StoreContextSlot) \
- V(StoreGlobal) \
+ V(StoreGlobalCell) \
+ V(StoreGlobalGeneric) \
V(StoreKeyedFastElement) \
V(StoreKeyedGeneric) \
V(StoreKeyedSpecializedArrayElement) \
@@ -1317,14 +1318,34 @@
};
-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); }
};
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Fri Apr 1
06:27:28 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Mon Apr 4
08:03:34 2011
@@ -2047,7 +2047,7 @@
}
-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));
@@ -2068,6 +2068,16 @@
}
__ movq(Operand(temp, 0), value);
}
+
+
+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) {
@@ -2744,7 +2754,6 @@
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;
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc Fri Apr 1 06:27:28 2011
+++ /branches/bleeding_edge/src/x64/lithium-x64.cc Mon Apr 4 08:03:34 2011
@@ -1732,11 +1732,19 @@
}
-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) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h Fri Apr 1 04:54:04 2011
+++ /branches/bleeding_edge/src/x64/lithium-x64.h Mon Apr 4 08:03:34 2011
@@ -145,7 +145,8 @@
V(SmiUntag) \
V(StackCheck) \
V(StoreContextSlot) \
- V(StoreGlobal) \
+ V(StoreGlobalCell) \
+ V(StoreGlobalGeneric) \
V(StoreKeyedFastElement) \
V(StoreKeyedGeneric) \
V(StoreKeyedSpecializedArrayElement) \
@@ -1268,15 +1269,32 @@
};
-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); }
};
=======================================
--- /branches/bleeding_edge/test/cctest/test-log-stack-tracer.cc Mon Mar 21
11:13:27 2011
+++ /branches/bleeding_edge/test/cctest/test-log-stack-tracer.cc Mon Apr 4
08:03:34 2011
@@ -280,6 +280,9 @@
// 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);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev