| 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/hash_map.h" |
| 9 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
| 10 #include "vm/parser.h" | 11 #include "vm/parser.h" |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 class BlockEffects; | 15 class BlockEffects; |
| 15 class FlowGraphBuilder; | 16 class FlowGraphBuilder; |
| 16 class ValueInliningContext; | 17 class ValueInliningContext; |
| 17 class VariableLivenessAnalysis; | 18 class VariableLivenessAnalysis; |
| 18 | 19 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 bool Done() const { return current_ >= block_order_.length(); } | 35 bool Done() const { return current_ >= block_order_.length(); } |
| 35 | 36 |
| 36 BlockEntryInstr* Current() const { return block_order_[current_]; } | 37 BlockEntryInstr* Current() const { return block_order_[current_]; } |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 const GrowableArray<BlockEntryInstr*>& block_order_; | 40 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 40 intptr_t current_; | 41 intptr_t current_; |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 | 44 |
| 45 struct ConstantPoolTrait { |
| 46 typedef ConstantInstr* Value; |
| 47 typedef const Object& Key; |
| 48 typedef ConstantInstr* Pair; |
| 49 |
| 50 static Key KeyOf(Pair kv) { |
| 51 return kv->value(); |
| 52 } |
| 53 |
| 54 static Value ValueOf(Pair kv) { |
| 55 return kv; |
| 56 } |
| 57 |
| 58 static inline intptr_t Hashcode(Key key) { |
| 59 if (key.IsSmi()) { |
| 60 return Smi::Cast(key).Value(); |
| 61 } |
| 62 if (key.IsDouble()) { |
| 63 return static_cast<intptr_t>( |
| 64 bit_cast<int32_t, float>( |
| 65 static_cast<float>(Double::Cast(key).value()))); |
| 66 } |
| 67 if (key.IsMint()) { |
| 68 return static_cast<intptr_t>(Mint::Cast(key).value()); |
| 69 } |
| 70 if (key.IsString()) { |
| 71 return String::Cast(key).Hash(); |
| 72 } |
| 73 return key.GetClassId(); |
| 74 } |
| 75 |
| 76 static inline bool IsKeyEqual(Pair kv, Key key) { |
| 77 return kv->value().raw() == key.raw(); |
| 78 } |
| 79 }; |
| 80 |
| 81 |
| 44 // Class to encapsulate the construction and manipulation of the flow graph. | 82 // Class to encapsulate the construction and manipulation of the flow graph. |
| 45 class FlowGraph : public ZoneAllocated { | 83 class FlowGraph : public ZoneAllocated { |
| 46 public: | 84 public: |
| 47 FlowGraph(const FlowGraphBuilder& builder, | 85 FlowGraph(const FlowGraphBuilder& builder, |
| 48 GraphEntryInstr* graph_entry, | 86 GraphEntryInstr* graph_entry, |
| 49 intptr_t max_block_id); | 87 intptr_t max_block_id); |
| 50 | 88 |
| 51 const FlowGraphBuilder& builder() const { | 89 const FlowGraphBuilder& builder() const { |
| 52 return builder_; | 90 return builder_; |
| 53 } | 91 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 332 |
| 295 BlockEffects* block_effects_; | 333 BlockEffects* block_effects_; |
| 296 bool licm_allowed_; | 334 bool licm_allowed_; |
| 297 | 335 |
| 298 bool use_far_branches_; | 336 bool use_far_branches_; |
| 299 | 337 |
| 300 ZoneGrowableArray<BlockEntryInstr*>* loop_headers_; | 338 ZoneGrowableArray<BlockEntryInstr*>* loop_headers_; |
| 301 ZoneGrowableArray<BitVector*>* loop_invariant_loads_; | 339 ZoneGrowableArray<BitVector*>* loop_invariant_loads_; |
| 302 ZoneGrowableArray<const Field*>* guarded_fields_; | 340 ZoneGrowableArray<const Field*>* guarded_fields_; |
| 303 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; | 341 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; |
| 342 DirectChainedHashMap<ConstantPoolTrait> constant_instr_pool_; |
| 304 }; | 343 }; |
| 305 | 344 |
| 306 | 345 |
| 307 class LivenessAnalysis : public ValueObject { | 346 class LivenessAnalysis : public ValueObject { |
| 308 public: | 347 public: |
| 309 LivenessAnalysis(intptr_t variable_count, | 348 LivenessAnalysis(intptr_t variable_count, |
| 310 const GrowableArray<BlockEntryInstr*>& postorder); | 349 const GrowableArray<BlockEntryInstr*>& postorder); |
| 311 | 350 |
| 312 void Analyze(); | 351 void Analyze(); |
| 313 | 352 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // Per block sets of available blocks. Block A is available at the block B if | 442 // Per block sets of available blocks. Block A is available at the block B if |
| 404 // and only if A dominates B and all paths from A to B are free of side | 443 // and only if A dominates B and all paths from A to B are free of side |
| 405 // effects. | 444 // effects. |
| 406 GrowableArray<BitVector*> available_at_; | 445 GrowableArray<BitVector*> available_at_; |
| 407 }; | 446 }; |
| 408 | 447 |
| 409 | 448 |
| 410 } // namespace dart | 449 } // namespace dart |
| 411 | 450 |
| 412 #endif // VM_FLOW_GRAPH_H_ | 451 #endif // VM_FLOW_GRAPH_H_ |
| OLD | NEW |