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. 4 5 #include "src/crankshaft/hydrogen-infer-types.h" 6 #include "src/objects-inl.h" 7 8 namespace v8 { 9 namespace internal { 10 11 void HInferTypesPhase::InferTypes(int from_inclusive, int to_inclusive) { 12 for (int i = from_inclusive; i <= to_inclusive; ++i) { 13 HBasicBlock* block = graph()->blocks()->at(i); 14 15 const ZoneList<HPhi*>* phis = block->phis(); 16 for (int j = 0; j < phis->length(); j++) { 17 phis->at(j)->UpdateInferredType(); 18 } 19 20 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { 21 it.Current()->UpdateInferredType(); 22 } 23 24 if (block->IsLoopHeader()) { 25 HBasicBlock* last_back_edge = 26 block->loop_information()->GetLastBackEdge(); 27 InferTypes(i + 1, last_back_edge->block_id()); 28 // Skip all blocks already processed by the recursive call. 29 i = last_back_edge->block_id(); 30 // Update phis of the loop header now after the whole loop body is 31 // guaranteed to be processed. 32 for (int j = 0; j < block->phis()->length(); ++j) { 33 HPhi* phi = block->phis()->at(j); 34 worklist_.Add(phi, zone()); 35 in_worklist_.Add(phi->id()); 36 } 37 while (!worklist_.is_empty()) { 38 HValue* current = worklist_.RemoveLast(); 39 in_worklist_.Remove(current->id()); 40 if (current->UpdateInferredType()) { 41 for (HUseIterator it(current->uses()); !it.Done(); it.Advance()) { 42 HValue* use = it.value(); 43 if (!in_worklist_.Contains(use->id())) { 44 in_worklist_.Add(use->id()); 45 worklist_.Add(use, zone()); 46 } 47 } 48 } 49 } 50 DCHECK(in_worklist_.IsEmpty()); 51 } 52 } 53 } 54 55 } // namespace internal 56 } // namespace v8 57