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 #ifndef V8_HYDROGEN_ESCAPE_ANALYSIS_H_ 6 #define V8_HYDROGEN_ESCAPE_ANALYSIS_H_ 7 8 #include "src/allocation.h" 9 #include "src/hydrogen.h" 10 11 namespace v8 { 12 namespace internal { 13 14 15 class HEscapeAnalysisPhase : public HPhase { 16 public: HEscapeAnalysisPhase(HGraph * graph)17 explicit HEscapeAnalysisPhase(HGraph* graph) 18 : HPhase("H_Escape analysis", graph), 19 captured_(0, zone()), 20 number_of_objects_(0), 21 number_of_values_(0), 22 cumulative_values_(0), 23 block_states_(graph->blocks()->length(), zone()) { } 24 25 void Run(); 26 27 private: 28 void CollectCapturedValues(); 29 bool HasNoEscapingUses(HValue* value, int size); 30 void PerformScalarReplacement(); 31 void AnalyzeDataFlow(HInstruction* instr); 32 33 HCapturedObject* NewState(HInstruction* prev); 34 HCapturedObject* NewStateForAllocation(HInstruction* prev); 35 HCapturedObject* NewStateForLoopHeader(HInstruction* prev, HCapturedObject*); 36 HCapturedObject* NewStateCopy(HInstruction* prev, HCapturedObject* state); 37 38 HPhi* NewPhiAndInsert(HBasicBlock* block, HValue* incoming_value, int index); 39 40 HValue* NewMapCheckAndInsert(HCapturedObject* state, HCheckMaps* mapcheck); 41 42 HValue* NewLoadReplacement(HLoadNamedField* load, HValue* load_value); 43 StateAt(HBasicBlock * block)44 HCapturedObject* StateAt(HBasicBlock* block) { 45 return block_states_.at(block->block_id()); 46 } 47 SetStateAt(HBasicBlock * block,HCapturedObject * state)48 void SetStateAt(HBasicBlock* block, HCapturedObject* state) { 49 block_states_.Set(block->block_id(), state); 50 } 51 52 // List of allocations captured during collection phase. 53 ZoneList<HInstruction*> captured_; 54 55 // Number of captured objects on which scalar replacement was done. 56 int number_of_objects_; 57 58 // Number of scalar values tracked during scalar replacement phase. 59 int number_of_values_; 60 int cumulative_values_; 61 62 // Map of block IDs to the data-flow state at block entry during the 63 // scalar replacement phase. 64 ZoneList<HCapturedObject*> block_states_; 65 }; 66 67 68 } } // namespace v8::internal 69 70 #endif // V8_HYDROGEN_ESCAPE_ANALYSIS_H_ 71