Commit 7a98cb62 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Speed up removing phi nodes.

BUG=
TEST=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10817 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0a6f1829
...@@ -383,19 +383,7 @@ void HValue::DeleteAndReplaceWith(HValue* other) { ...@@ -383,19 +383,7 @@ void HValue::DeleteAndReplaceWith(HValue* other) {
// We replace all uses first, so Delete can assert that there are none. // We replace all uses first, so Delete can assert that there are none.
if (other != NULL) ReplaceAllUsesWith(other); if (other != NULL) ReplaceAllUsesWith(other);
ASSERT(HasNoUses()); ASSERT(HasNoUses());
// Clearing the operands includes going through the use list of each operand Kill();
// to remove this HValue, which can be expensive. Instead, we mark this as
// dead and only check the first item in the use list of each operand.
// For the following items in the use lists we rely on the tail() method to
// skip dead dead items and remove them lazily.
SetFlag(kIsDead);
for (int i = 0; i < OperandCount(); ++i) {
HValue* operand = OperandAt(i);
HUseListNode* first = operand->use_list_;
if (first != NULL && first->index() == i && first->value() == this) {
operand->use_list_ = first->tail();
}
}
DeleteFromGraph(); DeleteFromGraph();
} }
...@@ -413,9 +401,17 @@ void HValue::ReplaceAllUsesWith(HValue* other) { ...@@ -413,9 +401,17 @@ void HValue::ReplaceAllUsesWith(HValue* other) {
} }
void HValue::ClearOperands() { void HValue::Kill() {
// Instead of going through the entire use list of each operand, we only
// check the first item in each use list and rely on the tail() method to
// skip dead items, removing them lazily next time we traverse the list.
SetFlag(kIsDead);
for (int i = 0; i < OperandCount(); ++i) { for (int i = 0; i < OperandCount(); ++i) {
SetOperandAt(i, NULL); HValue* operand = OperandAt(i);
HUseListNode* first = operand->use_list_;
if (first != NULL && first->value() == this && first->index() == i) {
operand->use_list_ = first->tail();
}
} }
} }
......
...@@ -631,7 +631,9 @@ class HValue: public ZoneObject { ...@@ -631,7 +631,9 @@ class HValue: public ZoneObject {
return use_list_ != NULL && use_list_->tail() != NULL; return use_list_ != NULL && use_list_->tail() != NULL;
} }
int UseCount() const; int UseCount() const;
void ClearOperands();
// Mark this HValue as dead and to be removed from other HValues' use lists.
void Kill();
int flags() const { return flags_; } int flags() const { return flags_; }
void SetFlag(Flag f) { flags_ |= (1 << f); } void SetFlag(Flag f) { flags_ |= (1 << f); }
......
...@@ -97,7 +97,7 @@ void HBasicBlock::RemovePhi(HPhi* phi) { ...@@ -97,7 +97,7 @@ void HBasicBlock::RemovePhi(HPhi* phi) {
ASSERT(phi->block() == this); ASSERT(phi->block() == this);
ASSERT(phis_.Contains(phi)); ASSERT(phis_.Contains(phi));
ASSERT(phi->HasNoUses() || !phi->is_live()); ASSERT(phi->HasNoUses() || !phi->is_live());
phi->ClearOperands(); phi->Kill();
phis_.RemoveElement(phi); phis_.RemoveElement(phi);
phi->SetBlock(NULL); phi->SetBlock(NULL);
} }
......
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