1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "src/hydrogen-infer-types.h"
10 void HInferTypesPhase::InferTypes(int from_inclusive, int to_inclusive) {
11 for (int i = from_inclusive; i <= to_inclusive; ++i) {
12 HBasicBlock* block = graph()->blocks()->at(i);
14 const ZoneList<HPhi*>* phis = block->phis();
15 for (int j = 0; j < phis->length(); j++) {
16 phis->at(j)->UpdateInferredType();
19 for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
20 it.Current()->UpdateInferredType();
23 if (block->IsLoopHeader()) {
24 HBasicBlock* last_back_edge =
25 block->loop_information()->GetLastBackEdge();
26 InferTypes(i + 1, last_back_edge->block_id());
27 // Skip all blocks already processed by the recursive call.
28 i = last_back_edge->block_id();
29 // Update phis of the loop header now after the whole loop body is
30 // guaranteed to be processed.
31 for (int j = 0; j < block->phis()->length(); ++j) {
32 HPhi* phi = block->phis()->at(j);
33 worklist_.Add(phi, zone());
34 in_worklist_.Add(phi->id());
36 while (!worklist_.is_empty()) {
37 HValue* current = worklist_.RemoveLast();
38 in_worklist_.Remove(current->id());
39 if (current->UpdateInferredType()) {
40 for (HUseIterator it(current->uses()); !it.Done(); it.Advance()) {
41 HValue* use = it.value();
42 if (!in_worklist_.Contains(use->id())) {
43 in_worklist_.Add(use->id());
44 worklist_.Add(use, zone());
49 DCHECK(in_worklist_.IsEmpty());
54 } } // namespace v8::internal