| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_FLOW_GRAPH_H_ | 5 #ifndef VM_FLOW_GRAPH_H_ |
| 6 #define VM_FLOW_GRAPH_H_ | 6 #define VM_FLOW_GRAPH_H_ |
| 7 | 7 |
| 8 #include "vm/growable_array.h" | 8 #include "vm/growable_array.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class FlowGraphBuilder; | 14 class FlowGraphBuilder; |
| 15 class ValueInliningContext; | 15 class ValueInliningContext; |
| 16 class VariableLivenessAnalysis; | |
| 17 | 16 |
| 18 class BlockIterator : public ValueObject { | 17 class BlockIterator : public ValueObject { |
| 19 public: | 18 public: |
| 20 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order) | 19 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order) |
| 21 : block_order_(block_order), current_(0) { } | 20 : block_order_(block_order), current_(0) { } |
| 22 | 21 |
| 23 BlockIterator(const BlockIterator& other) | 22 BlockIterator(const BlockIterator& other) |
| 24 : ValueObject(), | 23 : ValueObject(), |
| 25 block_order_(other.block_order_), | 24 block_order_(other.block_order_), |
| 26 current_(other.current_) { } | 25 current_(other.current_) { } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // SSA transformation methods and fields. | 155 // SSA transformation methods and fields. |
| 157 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); | 156 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); |
| 158 | 157 |
| 159 void CompressPath( | 158 void CompressPath( |
| 160 intptr_t start_index, | 159 intptr_t start_index, |
| 161 intptr_t current_index, | 160 intptr_t current_index, |
| 162 GrowableArray<intptr_t>* parent, | 161 GrowableArray<intptr_t>* parent, |
| 163 GrowableArray<intptr_t>* label); | 162 GrowableArray<intptr_t>* label); |
| 164 | 163 |
| 165 void Rename(GrowableArray<PhiInstr*>* live_phis, | 164 void Rename(GrowableArray<PhiInstr*>* live_phis, |
| 166 VariableLivenessAnalysis* variable_liveness, | |
| 167 GrowableArray<Definition*>* inlining_parameters); | 165 GrowableArray<Definition*>* inlining_parameters); |
| 168 | |
| 169 void RenameRecursive( | 166 void RenameRecursive( |
| 170 BlockEntryInstr* block_entry, | 167 BlockEntryInstr* block_entry, |
| 171 GrowableArray<Definition*>* env, | 168 GrowableArray<Definition*>* env, |
| 172 GrowableArray<PhiInstr*>* live_phis, | 169 GrowableArray<PhiInstr*>* live_phis); |
| 173 VariableLivenessAnalysis* variable_liveness); | |
| 174 | 170 |
| 175 void InsertPhis( | 171 void InsertPhis( |
| 176 const GrowableArray<BlockEntryInstr*>& preorder, | 172 const GrowableArray<BlockEntryInstr*>& preorder, |
| 177 const GrowableArray<BitVector*>& assigned_vars, | 173 const GrowableArray<BitVector*>& assigned_vars, |
| 178 const GrowableArray<BitVector*>& dom_frontier); | 174 const GrowableArray<BitVector*>& dom_frontier); |
| 179 | 175 |
| 180 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis); | 176 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis); |
| 181 | 177 |
| 182 void ReplacePredecessor(BlockEntryInstr* old_block, | 178 void ReplacePredecessor(BlockEntryInstr* old_block, |
| 183 BlockEntryInstr* new_block); | 179 BlockEntryInstr* new_block); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 196 const intptr_t num_non_copied_params_; | 192 const intptr_t num_non_copied_params_; |
| 197 const intptr_t num_stack_locals_; | 193 const intptr_t num_stack_locals_; |
| 198 GraphEntryInstr* graph_entry_; | 194 GraphEntryInstr* graph_entry_; |
| 199 GrowableArray<BlockEntryInstr*> preorder_; | 195 GrowableArray<BlockEntryInstr*> preorder_; |
| 200 GrowableArray<BlockEntryInstr*> postorder_; | 196 GrowableArray<BlockEntryInstr*> postorder_; |
| 201 GrowableArray<BlockEntryInstr*> reverse_postorder_; | 197 GrowableArray<BlockEntryInstr*> reverse_postorder_; |
| 202 bool invalid_dominator_tree_; | 198 bool invalid_dominator_tree_; |
| 203 ConstantInstr* constant_null_; | 199 ConstantInstr* constant_null_; |
| 204 }; | 200 }; |
| 205 | 201 |
| 206 | |
| 207 class LivenessAnalysis : public ValueObject { | |
| 208 public: | |
| 209 LivenessAnalysis(intptr_t variable_count, | |
| 210 const GrowableArray<BlockEntryInstr*>& postorder); | |
| 211 | |
| 212 void Analyze(); | |
| 213 | |
| 214 virtual ~LivenessAnalysis() { } | |
| 215 | |
| 216 BitVector* GetLiveInSetAt(intptr_t postorder_number) const { | |
| 217 return live_in_[postorder_number]; | |
| 218 } | |
| 219 | |
| 220 BitVector* GetLiveOutSetAt(intptr_t postorder_number) const { | |
| 221 return live_out_[postorder_number]; | |
| 222 } | |
| 223 | |
| 224 BitVector* GetLiveInSet(BlockEntryInstr* block) const { | |
| 225 return GetLiveInSetAt(block->postorder_number()); | |
| 226 } | |
| 227 | |
| 228 BitVector* GetKillSet(BlockEntryInstr* block) const { | |
| 229 return kill_[block->postorder_number()]; | |
| 230 } | |
| 231 | |
| 232 BitVector* GetLiveOutSet(BlockEntryInstr* block) const { | |
| 233 return GetLiveOutSetAt(block->postorder_number()); | |
| 234 } | |
| 235 | |
| 236 // Print results of liveness analysis. | |
| 237 void Dump(); | |
| 238 | |
| 239 protected: | |
| 240 // Compute initial values for live-out, kill and live-in sets. | |
| 241 virtual void ComputeInitialSets() = 0; | |
| 242 | |
| 243 // Update live-out set for the given block: live-out should contain | |
| 244 // all values that are live-in for block's successors. | |
| 245 // Returns true if live-out set was changed. | |
| 246 bool UpdateLiveOut(const BlockEntryInstr& instr); | |
| 247 | |
| 248 // Update live-in set for the given block: live-in should contain | |
| 249 // all values that are live-out from the block and are not defined | |
| 250 // by this block. | |
| 251 // Returns true if live-in set was changed. | |
| 252 bool UpdateLiveIn(const BlockEntryInstr& instr); | |
| 253 | |
| 254 // Perform fix-point iteration updating live-out and live-in sets | |
| 255 // for blocks until they stop changing. | |
| 256 void ComputeLiveInAndLiveOutSets(); | |
| 257 | |
| 258 const intptr_t variable_count_; | |
| 259 | |
| 260 const GrowableArray<BlockEntryInstr*>& postorder_; | |
| 261 | |
| 262 // Live-out sets for each block. They contain indices of variables | |
| 263 // that are live out from this block: that is values that were either | |
| 264 // defined in this block or live into it and that are used in some | |
| 265 // successor block. | |
| 266 GrowableArray<BitVector*> live_out_; | |
| 267 | |
| 268 // Kill sets for each block. They contain indices of variables that | |
| 269 // are defined by this block. | |
| 270 GrowableArray<BitVector*> kill_; | |
| 271 | |
| 272 // Live-in sets for each block. They contain indices of variables | |
| 273 // that are used by this block or its successors. | |
| 274 GrowableArray<BitVector*> live_in_; | |
| 275 }; | |
| 276 | |
| 277 } // namespace dart | 202 } // namespace dart |
| 278 | 203 |
| 279 #endif // VM_FLOW_GRAPH_H_ | 204 #endif // VM_FLOW_GRAPH_H_ |
| OLD | NEW |