Commit 36910718 authored by ulan@chromium.org's avatar ulan@chromium.org

Verify that no-side-effects scope does not add unsafe phis and does not change...

Verify that no-side-effects scope does not add unsafe phis and does not change push-pop balance of the environment.

R=danno@chromium.org
BUG=v8:2671

Review URL: https://chromiumcodereview.appspot.com/14696015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14610 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e40419d9
...@@ -752,6 +752,7 @@ void HGraphBuilder::IfBuilder::AddCompare(HControlInstruction* compare) { ...@@ -752,6 +752,7 @@ void HGraphBuilder::IfBuilder::AddCompare(HControlInstruction* compare) {
compare->SetSuccessorAt(1, split_edge); compare->SetSuccessorAt(1, split_edge);
} }
split_edge->GotoNoSimulate(split_edge_merge_block_); split_edge->GotoNoSimulate(split_edge_merge_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
} else { } else {
compare->SetSuccessorAt(0, first_true_block_); compare->SetSuccessorAt(0, first_true_block_);
compare->SetSuccessorAt(1, first_false_block_); compare->SetSuccessorAt(1, first_false_block_);
...@@ -769,6 +770,7 @@ void HGraphBuilder::IfBuilder::Or() { ...@@ -769,6 +770,7 @@ void HGraphBuilder::IfBuilder::Or() {
split_edge_merge_block_ = split_edge_merge_block_ =
builder_->CreateBasicBlock(env->Copy()); builder_->CreateBasicBlock(env->Copy());
first_true_block_->GotoNoSimulate(split_edge_merge_block_); first_true_block_->GotoNoSimulate(split_edge_merge_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
first_true_block_ = split_edge_merge_block_; first_true_block_ = split_edge_merge_block_;
} }
builder_->set_current_block(first_false_block_); builder_->set_current_block(first_false_block_);
...@@ -783,6 +785,7 @@ void HGraphBuilder::IfBuilder::And() { ...@@ -783,6 +785,7 @@ void HGraphBuilder::IfBuilder::And() {
if (split_edge_merge_block_ == NULL) { if (split_edge_merge_block_ == NULL) {
split_edge_merge_block_ = builder_->CreateBasicBlock(env->Copy()); split_edge_merge_block_ = builder_->CreateBasicBlock(env->Copy());
first_false_block_->GotoNoSimulate(split_edge_merge_block_); first_false_block_->GotoNoSimulate(split_edge_merge_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
first_false_block_ = split_edge_merge_block_; first_false_block_ = split_edge_merge_block_;
} }
builder_->set_current_block(first_true_block_); builder_->set_current_block(first_true_block_);
...@@ -814,6 +817,7 @@ void HGraphBuilder::IfBuilder::Then() { ...@@ -814,6 +817,7 @@ void HGraphBuilder::IfBuilder::Then() {
// Handle if's without any expressions, they jump directly to the "else" // Handle if's without any expressions, they jump directly to the "else"
// branch. // branch.
builder_->current_block()->GotoNoSimulate(first_false_block_); builder_->current_block()->GotoNoSimulate(first_false_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
first_true_block_ = NULL; first_true_block_ = NULL;
} }
builder_->set_current_block(first_true_block_); builder_->set_current_block(first_true_block_);
...@@ -876,6 +880,7 @@ void HGraphBuilder::IfBuilder::End() { ...@@ -876,6 +880,7 @@ void HGraphBuilder::IfBuilder::End() {
ASSERT(!last_false_block->IsFinished()); ASSERT(!last_false_block->IsFinished());
last_true_block_->GotoNoSimulate(merge_block_); last_true_block_->GotoNoSimulate(merge_block_);
last_false_block->GotoNoSimulate(merge_block_); last_false_block->GotoNoSimulate(merge_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
builder_->set_current_block(merge_block_); builder_->set_current_block(merge_block_);
} }
} }
...@@ -908,6 +913,7 @@ HValue* HGraphBuilder::LoopBuilder::BeginBody( ...@@ -908,6 +913,7 @@ HValue* HGraphBuilder::LoopBuilder::BeginBody(
phi_->ChangeRepresentation(Representation::Integer32()); phi_->ChangeRepresentation(Representation::Integer32());
env->Push(initial); env->Push(initial);
builder_->current_block()->GotoNoSimulate(header_block_); builder_->current_block()->GotoNoSimulate(header_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
HEnvironment* body_env = env->Copy(); HEnvironment* body_env = env->Copy();
HEnvironment* exit_env = env->Copy(); HEnvironment* exit_env = env->Copy();
...@@ -962,6 +968,7 @@ void HGraphBuilder::LoopBuilder::EndBody() { ...@@ -962,6 +968,7 @@ void HGraphBuilder::LoopBuilder::EndBody() {
// Push the new increment value on the expression stack to merge into the phi. // Push the new increment value on the expression stack to merge into the phi.
builder_->environment()->Push(increment_); builder_->environment()->Push(increment_);
builder_->current_block()->GotoNoSimulate(header_block_); builder_->current_block()->GotoNoSimulate(header_block_);
ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope());
header_block_->loop_information()->RegisterBackEdge(body_block_); header_block_->loop_information()->RegisterBackEdge(body_block_);
builder_->set_current_block(exit_block_); builder_->set_current_block(exit_block_);
...@@ -8181,6 +8188,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -8181,6 +8188,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
access->set_position(position); access->set_position(position);
} }
if_jsarray->GotoNoSimulate(join); if_jsarray->GotoNoSimulate(join);
ASSERT(SafeToAddPhiInNoSideEffectsScope());
set_current_block(if_fastobject); set_current_block(if_fastobject);
length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements)); length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements));
...@@ -8207,6 +8215,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -8207,6 +8215,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
Push(access); Push(access);
} }
current_block()->GotoNoSimulate(join); current_block()->GotoNoSimulate(join);
ASSERT(SafeToAddPhiInNoSideEffectsScope());
set_current_block(if_false); set_current_block(if_false);
} }
} }
......
...@@ -934,6 +934,7 @@ class HGraphBuilder { ...@@ -934,6 +934,7 @@ class HGraphBuilder {
: info_(info), : info_(info),
graph_(NULL), graph_(NULL),
current_block_(NULL), current_block_(NULL),
no_side_effects_scope_environment_delta_(0),
no_side_effects_scope_count_(0) {} no_side_effects_scope_count_(0) {}
virtual ~HGraphBuilder() {} virtual ~HGraphBuilder() {}
...@@ -965,11 +966,31 @@ class HGraphBuilder { ...@@ -965,11 +966,31 @@ class HGraphBuilder {
HReturn* AddReturn(HValue* value); HReturn* AddReturn(HValue* value);
void IncrementInNoSideEffectsScope() { void IncrementInNoSideEffectsScope() {
if (no_side_effects_scope_count_ == 0) {
no_side_effects_scope_environment_delta_ =
environment()->push_count() - environment()->pop_count();
}
no_side_effects_scope_count_++; no_side_effects_scope_count_++;
} }
void DecrementInNoSideEffectsScope() { void DecrementInNoSideEffectsScope() {
no_side_effects_scope_count_--; no_side_effects_scope_count_--;
if (no_side_effects_scope_count_ == 0) {
// No-side-effects scope should not change push-pop delta.
ASSERT_EQ(no_side_effects_scope_environment_delta_,
environment()->push_count() - environment()->pop_count());
no_side_effects_scope_environment_delta_ = 0;
}
}
bool SafeToAddPhiInNoSideEffectsScope() {
// Pops and pushes after a simulate are not visible in LChunkBuilder.
// If the number of pops is greater than the number pushes then the
// environment in HGraphBuilder is shorter then the corresponding
// environment in LChunkBuilder. This causes non-observable phis
// to be pushed in the environment, which breaks deoptimization.
return no_side_effects_scope_count_ == 0 ||
no_side_effects_scope_environment_delta_ >= 0;
} }
protected: protected:
...@@ -1332,6 +1353,7 @@ class HGraphBuilder { ...@@ -1332,6 +1353,7 @@ class HGraphBuilder {
CompilationInfo* info_; CompilationInfo* info_;
HGraph* graph_; HGraph* graph_;
HBasicBlock* current_block_; HBasicBlock* current_block_;
int no_side_effects_scope_environment_delta_;
int no_side_effects_scope_count_; int no_side_effects_scope_count_;
}; };
......
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