From eaf9d14be9cc3b28928085b906bd713a140f9e91 Mon Sep 17 00:00:00 2001 From: "jkummerow@chromium.org" Date: Thu, 2 May 2013 17:00:53 +0000 Subject: [PATCH] Use worklist to find out Phis that could not be truncated to int32 Review URL: https://codereview.chromium.org/13950013 Patch from Haitao Feng . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14528 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 60 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index dfe0373..2b62e2d 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -4075,36 +4075,50 @@ void HGraph::InsertRepresentationChanges() { // int32-phis allow truncation and iteratively remove the ones that // are used in an operation that does not allow a truncating // conversion. - // TODO(fschneider): Replace this with a worklist-based iteration. + ZoneList worklist(8, zone()); + for (int i = 0; i < phi_list()->length(); i++) { HPhi* phi = phi_list()->at(i); if (phi->representation().IsInteger32()) { phi->SetFlag(HValue::kTruncatingToInt32); } } - bool change = true; - while (change) { - change = false; - for (int i = 0; i < phi_list()->length(); i++) { - HPhi* phi = phi_list()->at(i); - if (!phi->CheckFlag(HValue::kTruncatingToInt32)) continue; - for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { - // If a Phi is used as a non-truncating int32 or as a double, - // clear its "truncating" flag. - HValue* use = it.value(); - Representation input_representation = - use->RequiredInputRepresentation(it.index()); - if ((input_representation.IsInteger32() && - !use->CheckFlag(HValue::kTruncatingToInt32)) || - input_representation.IsDouble()) { - if (FLAG_trace_representation) { - PrintF("#%d Phi is not truncating because of #%d %s\n", - phi->id(), it.value()->id(), it.value()->Mnemonic()); - } - phi->ClearFlag(HValue::kTruncatingToInt32); - change = true; - break; + + for (int i = 0; i < phi_list()->length(); i++) { + HPhi* phi = phi_list()->at(i); + for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { + // If a Phi is used as a non-truncating int32 or as a double, + // clear its "truncating" flag. + HValue* use = it.value(); + Representation input_representation = + use->RequiredInputRepresentation(it.index()); + if ((input_representation.IsInteger32() && + !use->CheckFlag(HValue::kTruncatingToInt32)) || + input_representation.IsDouble()) { + if (FLAG_trace_representation) { + PrintF("#%d Phi is not truncating because of #%d %s\n", + phi->id(), it.value()->id(), it.value()->Mnemonic()); + } + phi->ClearFlag(HValue::kTruncatingToInt32); + worklist.Add(phi, zone()); + 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()); } } } -- 2.7.4