Use worklist to find out Phis that could not be truncated to int32

Review URL: https://codereview.chromium.org/13950013

Patch from Haitao Feng <haitao.feng@intel.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14528 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b3e65aff
...@@ -4075,36 +4075,50 @@ void HGraph::InsertRepresentationChanges() { ...@@ -4075,36 +4075,50 @@ void HGraph::InsertRepresentationChanges() {
// int32-phis allow truncation and iteratively remove the ones that // int32-phis allow truncation and iteratively remove the ones that
// are used in an operation that does not allow a truncating // are used in an operation that does not allow a truncating
// conversion. // conversion.
// TODO(fschneider): Replace this with a worklist-based iteration. ZoneList<HPhi*> worklist(8, zone());
for (int i = 0; i < phi_list()->length(); i++) { for (int i = 0; i < phi_list()->length(); i++) {
HPhi* phi = phi_list()->at(i); HPhi* phi = phi_list()->at(i);
if (phi->representation().IsInteger32()) { if (phi->representation().IsInteger32()) {
phi->SetFlag(HValue::kTruncatingToInt32); phi->SetFlag(HValue::kTruncatingToInt32);
} }
} }
bool change = true;
while (change) { for (int i = 0; i < phi_list()->length(); i++) {
change = false; HPhi* phi = phi_list()->at(i);
for (int i = 0; i < phi_list()->length(); i++) { for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) {
HPhi* phi = phi_list()->at(i); // If a Phi is used as a non-truncating int32 or as a double,
if (!phi->CheckFlag(HValue::kTruncatingToInt32)) continue; // clear its "truncating" flag.
for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { HValue* use = it.value();
// If a Phi is used as a non-truncating int32 or as a double, Representation input_representation =
// clear its "truncating" flag. use->RequiredInputRepresentation(it.index());
HValue* use = it.value(); if ((input_representation.IsInteger32() &&
Representation input_representation = !use->CheckFlag(HValue::kTruncatingToInt32)) ||
use->RequiredInputRepresentation(it.index()); input_representation.IsDouble()) {
if ((input_representation.IsInteger32() && if (FLAG_trace_representation) {
!use->CheckFlag(HValue::kTruncatingToInt32)) || PrintF("#%d Phi is not truncating because of #%d %s\n",
input_representation.IsDouble()) { phi->id(), it.value()->id(), it.value()->Mnemonic());
if (FLAG_trace_representation) { }
PrintF("#%d Phi is not truncating because of #%d %s\n", phi->ClearFlag(HValue::kTruncatingToInt32);
phi->id(), it.value()->id(), it.value()->Mnemonic()); worklist.Add(phi, zone());
} break;
phi->ClearFlag(HValue::kTruncatingToInt32); }
change = true; }
break; }
while (!worklist.is_empty()) {
HPhi* current = worklist.RemoveLast();
for (int i = 0; i < current->OperandCount(); ++i) {
HValue* input = current->OperandAt(i);
if (input->IsPhi() &&
input->representation().IsInteger32() &&
input->CheckFlag(HValue::kTruncatingToInt32)) {
if (FLAG_trace_representation) {
PrintF("#%d Phi is not truncating because of #%d %s\n",
input->id(), current->id(), current->Mnemonic());
} }
input->ClearFlag(HValue::kTruncatingToInt32);
worklist.Add(HPhi::cast(input), zone());
} }
} }
} }
......
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