| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_HYDROGEN_FLOW_ENGINE_H_ | 5 #ifndef V8_HYDROGEN_FLOW_ENGINE_H_ |
| 6 #define V8_HYDROGEN_FLOW_ENGINE_H_ | 6 #define V8_HYDROGEN_FLOW_ENGINE_H_ |
| 7 | 7 |
| 8 #include "src/hydrogen.h" | 8 #include "src/hydrogen.h" |
| 9 #include "src/hydrogen-instructions.h" | 9 #include "src/hydrogen-instructions.h" |
| 10 #include "src/zone.h" | 10 #include "src/zone.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // doing a fixed-point iteration. Thus the flow engine is guaranteed to visit | 61 // doing a fixed-point iteration. Thus the flow engine is guaranteed to visit |
| 62 // each block at most twice; once for state, and optionally once for effects. | 62 // each block at most twice; once for state, and optionally once for effects. |
| 63 // | 63 // |
| 64 // The flow engine requires the State and Effects classes to implement methods | 64 // The flow engine requires the State and Effects classes to implement methods |
| 65 // like the example NoState and NoEffects above. It's not necessary to provide | 65 // like the example NoState and NoEffects above. It's not necessary to provide |
| 66 // an effects implementation for local analysis. | 66 // an effects implementation for local analysis. |
| 67 template <class State, class Effects> | 67 template <class State, class Effects> |
| 68 class HFlowEngine { | 68 class HFlowEngine { |
| 69 public: | 69 public: |
| 70 HFlowEngine(HGraph* graph, Zone* zone) | 70 HFlowEngine(HGraph* graph, Zone* zone) |
| 71 : graph_(graph), | 71 : graph_(graph), |
| 72 zone_(zone), | 72 zone_(zone), |
| 73 #if DEBUG | 73 #if DCHECK_IS_ON |
| 74 pred_counts_(graph->blocks()->length(), zone), | 74 pred_counts_(graph->blocks()->length(), zone), |
| 75 #endif | 75 #endif |
| 76 block_states_(graph->blocks()->length(), zone), | 76 block_states_(graph->blocks()->length(), zone), |
| 77 loop_effects_(graph->blocks()->length(), zone) { | 77 loop_effects_(graph->blocks()->length(), zone) { |
| 78 loop_effects_.AddBlock(NULL, graph_->blocks()->length(), zone); | 78 loop_effects_.AddBlock(NULL, graph_->blocks()->length(), zone); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Local analysis. Iterates over the instructions in the given block. | 81 // Local analysis. Iterates over the instructions in the given block. |
| 82 State* AnalyzeOneBlock(HBasicBlock* block, State* state) { | 82 State* AnalyzeOneBlock(HBasicBlock* block, State* state) { |
| 83 // Go through all instructions of the current block, updating the state. | 83 // Go through all instructions of the current block, updating the state. |
| 84 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | 84 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 85 state = state->Process(it.Current(), zone_); | 85 state = state->Process(it.Current(), zone_); |
| 86 } | 86 } |
| 87 return state; | 87 return state; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 inline State* StateAt(HBasicBlock* block) { | 180 inline State* StateAt(HBasicBlock* block) { |
| 181 return block_states_.at(block->block_id()); | 181 return block_states_.at(block->block_id()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 inline void SetStateAt(HBasicBlock* block, State* state) { | 184 inline void SetStateAt(HBasicBlock* block, State* state) { |
| 185 block_states_.Set(block->block_id(), state); | 185 block_states_.Set(block->block_id(), state); |
| 186 } | 186 } |
| 187 | 187 |
| 188 inline void InitializeStates() { | 188 inline void InitializeStates() { |
| 189 #if DEBUG | 189 #if DCHECK_IS_ON |
| 190 pred_counts_.Rewind(0); | 190 pred_counts_.Rewind(0); |
| 191 pred_counts_.AddBlock(0, graph_->blocks()->length(), zone_); | 191 pred_counts_.AddBlock(0, graph_->blocks()->length(), zone_); |
| 192 #endif | 192 #endif |
| 193 block_states_.Rewind(0); | 193 block_states_.Rewind(0); |
| 194 block_states_.AddBlock(NULL, graph_->blocks()->length(), zone_); | 194 block_states_.AddBlock(NULL, graph_->blocks()->length(), zone_); |
| 195 } | 195 } |
| 196 | 196 |
| 197 inline void CheckPredecessorCount(HBasicBlock* block) { | 197 inline void CheckPredecessorCount(HBasicBlock* block) { |
| 198 DCHECK(block->predecessors()->length() == pred_counts_[block->block_id()]); | 198 DCHECK(block->predecessors()->length() == pred_counts_[block->block_id()]); |
| 199 } | 199 } |
| 200 | 200 |
| 201 inline void IncrementPredecessorCount(HBasicBlock* block) { | 201 inline void IncrementPredecessorCount(HBasicBlock* block) { |
| 202 #if DEBUG | 202 #if DCHECK_IS_ON |
| 203 pred_counts_[block->block_id()]++; | 203 pred_counts_[block->block_id()]++; |
| 204 #endif | 204 #endif |
| 205 } | 205 } |
| 206 | 206 |
| 207 HGraph* graph_; // The hydrogen graph. | 207 HGraph* graph_; // The hydrogen graph. |
| 208 Zone* zone_; // Temporary zone. | 208 Zone* zone_; // Temporary zone. |
| 209 #if DEBUG | 209 #if DCHECK_IS_ON |
| 210 ZoneList<int> pred_counts_; // Finished predecessors (by block id). | 210 ZoneList<int> pred_counts_; // Finished predecessors (by block id). |
| 211 #endif | 211 #endif |
| 212 ZoneList<State*> block_states_; // Block states (by block id). | 212 ZoneList<State*> block_states_; // Block states (by block id). |
| 213 ZoneList<Effects*> loop_effects_; // Loop effects (by block id). | 213 ZoneList<Effects*> loop_effects_; // Loop effects (by block id). |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 | 216 |
| 217 } } // namespace v8::internal | 217 } } // namespace v8::internal |
| 218 | 218 |
| 219 #endif // V8_HYDROGEN_FLOW_ENGINE_H_ | 219 #endif // V8_HYDROGEN_FLOW_ENGINE_H_ |
| OLD | NEW |