Commit 0766a138 authored by danno@chromium.org's avatar danno@chromium.org

Add and use ElementsKind side effect

Also partition side effects into observable and not observable, with only observable requiring Simulates and non-observable changes able to participate in GVN and code hoisting.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/8380017

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9847 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0df9569f
...@@ -750,7 +750,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -750,7 +750,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
instr->MarkAsCall(); instr->MarkAsCall();
instr = AssignPointerMap(instr); instr = AssignPointerMap(instr);
if (hinstr->HasSideEffects()) { if (hinstr->HasObservableSideEffects()) {
ASSERT(hinstr->next()->IsSimulate()); ASSERT(hinstr->next()->IsSimulate());
HSimulate* sim = HSimulate::cast(hinstr->next()); HSimulate* sim = HSimulate::cast(hinstr->next());
instr = SetInstructionPendingDeoptimizationEnvironment( instr = SetInstructionPendingDeoptimizationEnvironment(
...@@ -762,7 +762,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -762,7 +762,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
// Thus we still need to attach environment to this call even if // Thus we still need to attach environment to this call even if
// call sequence can not deoptimize eagerly. // call sequence can not deoptimize eagerly.
bool needs_environment = bool needs_environment =
(can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) { if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr); instr = AssignEnvironment(instr);
} }
......
...@@ -564,7 +564,7 @@ void HInstruction::InsertAfter(HInstruction* previous) { ...@@ -564,7 +564,7 @@ void HInstruction::InsertAfter(HInstruction* previous) {
// followed by a simulate instruction, we need to insert after the // followed by a simulate instruction, we need to insert after the
// simulate instruction instead. // simulate instruction instead.
HInstruction* next = previous->next_; HInstruction* next = previous->next_;
if (previous->HasSideEffects() && next != NULL) { if (previous->HasObservableSideEffects() && next != NULL) {
ASSERT(next->IsSimulate()); ASSERT(next->IsSimulate());
previous = next; previous = next;
next = previous->next_; next = previous->next_;
...@@ -604,7 +604,7 @@ void HInstruction::Verify() { ...@@ -604,7 +604,7 @@ void HInstruction::Verify() {
// Verify that instructions that may have side-effects are followed // Verify that instructions that may have side-effects are followed
// by a simulate instruction. // by a simulate instruction.
if (HasSideEffects() && !IsOsrEntry()) { if (HasObservableSideEffects() && !IsOsrEntry()) {
ASSERT(next()->IsSimulate()); ASSERT(next()->IsSimulate());
} }
......
...@@ -181,6 +181,7 @@ class LChunkBuilder; ...@@ -181,6 +181,7 @@ class LChunkBuilder;
V(Calls) \ V(Calls) \
V(InobjectFields) \ V(InobjectFields) \
V(BackingStoreFields) \ V(BackingStoreFields) \
V(ElementsKind) \
V(ArrayElements) \ V(ArrayElements) \
V(DoubleArrayElements) \ V(DoubleArrayElements) \
V(SpecializedArrayElements) \ V(SpecializedArrayElements) \
...@@ -619,8 +620,14 @@ class HValue: public ZoneObject { ...@@ -619,8 +620,14 @@ class HValue: public ZoneObject {
void SetAllSideEffects() { flags_ |= AllSideEffects(); } void SetAllSideEffects() { flags_ |= AllSideEffects(); }
void ClearAllSideEffects() { flags_ &= ~AllSideEffects(); } void ClearAllSideEffects() { flags_ &= ~AllSideEffects(); }
bool HasSideEffects() const { return (flags_ & AllSideEffects()) != 0; } bool HasSideEffects() const { return (flags_ & AllSideEffects()) != 0; }
bool HasObservableSideEffects() const {
return (flags_ & ObservableSideEffects()) != 0;
}
int ChangesFlags() const { return flags_ & ChangesFlagsMask(); } int ChangesFlags() const { return flags_ & ChangesFlagsMask(); }
int ObservableChangesFlags() const {
return flags_ & ChangesFlagsMask() & ObservableSideEffects();
}
Range* range() const { return range_; } Range* range() const { return range_; }
bool HasRange() const { return range_ != NULL; } bool HasRange() const { return range_ != NULL; }
...@@ -700,6 +707,12 @@ class HValue: public ZoneObject { ...@@ -700,6 +707,12 @@ class HValue: public ZoneObject {
return ChangesFlagsMask() & ~(1 << kChangesOsrEntries); return ChangesFlagsMask() & ~(1 << kChangesOsrEntries);
} }
// A flag mask of all side effects that can make observable changes in
// an executing program (i.e. are not safe to repeat, move or remove);
static int ObservableSideEffects() {
return ChangesFlagsMask() & ~(1 << kChangesElementsKind);
}
// Remove the matching use from the use list if present. Returns the // Remove the matching use from the use list if present. Returns the
// removed list node or NULL. // removed list node or NULL.
HUseListNode* RemoveUse(HValue* value, int index); HUseListNode* RemoveUse(HValue* value, int index);
...@@ -1737,7 +1750,7 @@ class HElementsKind: public HUnaryOperation { ...@@ -1737,7 +1750,7 @@ class HElementsKind: public HUnaryOperation {
explicit HElementsKind(HValue* value) : HUnaryOperation(value) { explicit HElementsKind(HValue* value) : HUnaryOperation(value) {
set_representation(Representation::Integer32()); set_representation(Representation::Integer32());
SetFlag(kUseGVN); SetFlag(kUseGVN);
SetFlag(kDependsOnMaps); SetFlag(kDependsOnElementsKind);
} }
virtual Representation RequiredInputRepresentation(int index) { virtual Representation RequiredInputRepresentation(int index) {
...@@ -1864,6 +1877,7 @@ class HLoadElements: public HUnaryOperation { ...@@ -1864,6 +1877,7 @@ class HLoadElements: public HUnaryOperation {
set_representation(Representation::Tagged()); set_representation(Representation::Tagged());
SetFlag(kUseGVN); SetFlag(kUseGVN);
SetFlag(kDependsOnMaps); SetFlag(kDependsOnMaps);
SetFlag(kDependsOnElementsKind);
} }
virtual Representation RequiredInputRepresentation(int index) { virtual Representation RequiredInputRepresentation(int index) {
...@@ -3886,7 +3900,7 @@ class HTransitionElementsKind: public HTemplateInstruction<1> { ...@@ -3886,7 +3900,7 @@ class HTransitionElementsKind: public HTemplateInstruction<1> {
transitioned_map_(transitioned_map) { transitioned_map_(transitioned_map) {
SetOperandAt(0, object); SetOperandAt(0, object);
SetFlag(kUseGVN); SetFlag(kUseGVN);
SetFlag(kDependsOnMaps); SetFlag(kChangesElementsKind);
set_representation(Representation::Tagged()); set_representation(Representation::Tagged());
} }
......
This diff is collapsed.
...@@ -750,7 +750,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -750,7 +750,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
instr->MarkAsCall(); instr->MarkAsCall();
instr = AssignPointerMap(instr); instr = AssignPointerMap(instr);
if (hinstr->HasSideEffects()) { if (hinstr->HasObservableSideEffects()) {
ASSERT(hinstr->next()->IsSimulate()); ASSERT(hinstr->next()->IsSimulate());
HSimulate* sim = HSimulate::cast(hinstr->next()); HSimulate* sim = HSimulate::cast(hinstr->next());
instr = SetInstructionPendingDeoptimizationEnvironment( instr = SetInstructionPendingDeoptimizationEnvironment(
...@@ -762,7 +762,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -762,7 +762,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
// Thus we still need to attach environment to this call even if // Thus we still need to attach environment to this call even if
// call sequence can not deoptimize eagerly. // call sequence can not deoptimize eagerly.
bool needs_environment = bool needs_environment =
(can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) { if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr); instr = AssignEnvironment(instr);
} }
......
...@@ -745,7 +745,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -745,7 +745,7 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
instr->MarkAsCall(); instr->MarkAsCall();
instr = AssignPointerMap(instr); instr = AssignPointerMap(instr);
if (hinstr->HasSideEffects()) { if (hinstr->HasObservableSideEffects()) {
ASSERT(hinstr->next()->IsSimulate()); ASSERT(hinstr->next()->IsSimulate());
HSimulate* sim = HSimulate::cast(hinstr->next()); HSimulate* sim = HSimulate::cast(hinstr->next());
instr = SetInstructionPendingDeoptimizationEnvironment( instr = SetInstructionPendingDeoptimizationEnvironment(
...@@ -757,7 +757,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, ...@@ -757,7 +757,8 @@ LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
// Thus we still need to attach environment to this call even if // Thus we still need to attach environment to this call even if
// call sequence can not deoptimize eagerly. // call sequence can not deoptimize eagerly.
bool needs_environment = bool needs_environment =
(can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) { if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr); instr = AssignEnvironment(instr);
} }
......
// Copyright 2011 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 --smi-only-arrays
function burn() {
var a = new Array(3);
a[0] = 10;
a[1] = 15.5;
a[2] = 20;
return a;
}
function check(a) {
assertEquals(10, a[0]);
assertEquals(15.5, a[1]);
assertEquals(20, a[2]);
}
var b;
for (var i = 0; i < 3; ++i) {
b = burn();
check(b); // all OK
}
%OptimizeFunctionOnNextCall(burn);
b = burn();
check(b); // fails
function loop_test(x) {
for (i=0;i<3;i++) {
x[i] = (i+1) * 0.5;
}
}
function check2(b) {
assertEquals(0.5, b[0]);
assertEquals(1.0, b[1]);
assertEquals(1.5, b[2]);
}
for (var i = 0; i < 3; ++i) {
b = [0,1,2];
loop_test(b);
check2(b);
}
%OptimizeFunctionOnNextCall(loop_test);
b = [0,1,2];
loop_test(b);
check2(b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment