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 BlockEffects; |
14 class FlowGraphBuilder; | 15 class FlowGraphBuilder; |
15 class ValueInliningContext; | 16 class ValueInliningContext; |
16 class VariableLivenessAnalysis; | 17 class VariableLivenessAnalysis; |
17 | 18 |
18 class BlockIterator : public ValueObject { | 19 class BlockIterator : public ValueObject { |
19 public: | 20 public: |
20 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order) | 21 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order) |
21 : block_order_(block_order), current_(0) { } | 22 : block_order_(block_order), current_(0) { } |
22 | 23 |
23 BlockIterator(const BlockIterator& other) | 24 BlockIterator(const BlockIterator& other) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // TODO(zerny): Once the SSA is feature complete this should be removed. | 134 // TODO(zerny): Once the SSA is feature complete this should be removed. |
134 void Bailout(const char* reason) const; | 135 void Bailout(const char* reason) const; |
135 | 136 |
136 #ifdef DEBUG | 137 #ifdef DEBUG |
137 // Verification methods for debugging. | 138 // Verification methods for debugging. |
138 bool VerifyUseLists(); | 139 bool VerifyUseLists(); |
139 #endif // DEBUG | 140 #endif // DEBUG |
140 | 141 |
141 void DiscoverBlocks(); | 142 void DiscoverBlocks(); |
142 | 143 |
| 144 // Compute information about effects occuring in different blocks and |
| 145 // discover side-effect free paths. |
| 146 void ComputeBlockEffects(); |
| 147 BlockEffects* block_effects() const { return block_effects_; } |
| 148 |
143 private: | 149 private: |
144 friend class IfConverter; | 150 friend class IfConverter; |
145 friend class BranchSimplifier; | 151 friend class BranchSimplifier; |
146 friend class ConstantPropagator; | 152 friend class ConstantPropagator; |
147 | 153 |
148 // SSA transformation methods and fields. | 154 // SSA transformation methods and fields. |
149 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); | 155 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); |
150 | 156 |
151 void CompressPath( | 157 void CompressPath( |
152 intptr_t start_index, | 158 intptr_t start_index, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // Flow graph fields. | 192 // Flow graph fields. |
187 const ParsedFunction& parsed_function_; | 193 const ParsedFunction& parsed_function_; |
188 const intptr_t num_copied_params_; | 194 const intptr_t num_copied_params_; |
189 const intptr_t num_non_copied_params_; | 195 const intptr_t num_non_copied_params_; |
190 const intptr_t num_stack_locals_; | 196 const intptr_t num_stack_locals_; |
191 GraphEntryInstr* graph_entry_; | 197 GraphEntryInstr* graph_entry_; |
192 GrowableArray<BlockEntryInstr*> preorder_; | 198 GrowableArray<BlockEntryInstr*> preorder_; |
193 GrowableArray<BlockEntryInstr*> postorder_; | 199 GrowableArray<BlockEntryInstr*> postorder_; |
194 GrowableArray<BlockEntryInstr*> reverse_postorder_; | 200 GrowableArray<BlockEntryInstr*> reverse_postorder_; |
195 ConstantInstr* constant_null_; | 201 ConstantInstr* constant_null_; |
| 202 |
| 203 BlockEffects* block_effects_; |
196 }; | 204 }; |
197 | 205 |
198 | 206 |
199 class LivenessAnalysis : public ValueObject { | 207 class LivenessAnalysis : public ValueObject { |
200 public: | 208 public: |
201 LivenessAnalysis(intptr_t variable_count, | 209 LivenessAnalysis(intptr_t variable_count, |
202 const GrowableArray<BlockEntryInstr*>& postorder); | 210 const GrowableArray<BlockEntryInstr*>& postorder); |
203 | 211 |
204 void Analyze(); | 212 void Analyze(); |
205 | 213 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 267 |
260 // Kill sets for each block. They contain indices of variables that | 268 // Kill sets for each block. They contain indices of variables that |
261 // are defined by this block. | 269 // are defined by this block. |
262 GrowableArray<BitVector*> kill_; | 270 GrowableArray<BitVector*> kill_; |
263 | 271 |
264 // Live-in sets for each block. They contain indices of variables | 272 // Live-in sets for each block. They contain indices of variables |
265 // that are used by this block or its successors. | 273 // that are used by this block or its successors. |
266 GrowableArray<BitVector*> live_in_; | 274 GrowableArray<BitVector*> live_in_; |
267 }; | 275 }; |
268 | 276 |
| 277 |
| 278 // Information about side effect free paths between blocks. |
| 279 class BlockEffects : public ZoneAllocated { |
| 280 public: |
| 281 explicit BlockEffects(FlowGraph* flow_graph); |
| 282 |
| 283 // Return true if the given instruction is not affected by anything between |
| 284 // its current block and target block. Used by CSE to determine if |
| 285 // a computation is available in the given block. |
| 286 bool IsAvailableAt(Instruction* instr, BlockEntryInstr* block) const; |
| 287 |
| 288 // Return true if the given instruction is not affected by anything between |
| 289 // the given block and its current block. Used by LICM to determine if |
| 290 // a computation can be moved to loop's preheader and remain available at |
| 291 // its current location. |
| 292 bool CanBeMovedTo(Instruction* instr, BlockEntryInstr* block) const; |
| 293 |
| 294 private: |
| 295 // Returns true if from dominates to and all paths between from and to are |
| 296 // free of side effects. |
| 297 bool IsSideEffectFreePath(BlockEntryInstr* from, BlockEntryInstr* to) const; |
| 298 |
| 299 // Per block sets of available blocks. Block A is available at the block B if |
| 300 // and only if A dominates B and all paths from A to B are free of side |
| 301 // effects. |
| 302 GrowableArray<BitVector*> available_at_; |
| 303 }; |
| 304 |
| 305 |
269 } // namespace dart | 306 } // namespace dart |
270 | 307 |
271 #endif // VM_FLOW_GRAPH_H_ | 308 #endif // VM_FLOW_GRAPH_H_ |
OLD | NEW |