OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #ifndef VM_REDUNDANCY_ELIMINATION_H_ |
| 6 #define VM_REDUNDANCY_ELIMINATION_H_ |
| 7 |
| 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/flow_graph.h" |
| 10 |
| 11 namespace dart { |
| 12 |
| 13 class CSEInstructionMap; |
| 14 |
| 15 class AllocationSinking : public ZoneAllocated { |
| 16 public: |
| 17 explicit AllocationSinking(FlowGraph* flow_graph) |
| 18 : flow_graph_(flow_graph), |
| 19 candidates_(5), |
| 20 materializations_(5) { } |
| 21 |
| 22 const GrowableArray<Definition*>& candidates() const { |
| 23 return candidates_; |
| 24 } |
| 25 |
| 26 // Find the materialization insterted for the given allocation |
| 27 // at the given exit. |
| 28 MaterializeObjectInstr* MaterializationFor(Definition* alloc, |
| 29 Instruction* exit); |
| 30 |
| 31 void Optimize(); |
| 32 |
| 33 void DetachMaterializations(); |
| 34 |
| 35 private: |
| 36 // Helper class to collect deoptimization exits that might need to |
| 37 // rematerialize an object: that is either instructions that reference |
| 38 // this object explicitly in their deoptimization environment or |
| 39 // reference some other allocation sinking candidate that points to |
| 40 // this object. |
| 41 class ExitsCollector : public ValueObject { |
| 42 public: |
| 43 ExitsCollector() : exits_(10), worklist_(3) { } |
| 44 |
| 45 const GrowableArray<Instruction*>& exits() const { return exits_; } |
| 46 |
| 47 void CollectTransitively(Definition* alloc); |
| 48 |
| 49 private: |
| 50 // Collect immediate uses of this object in the environments. |
| 51 // If this object is stored into other allocation sinking candidates |
| 52 // put them onto worklist so that CollectTransitively will process them. |
| 53 void Collect(Definition* alloc); |
| 54 |
| 55 GrowableArray<Instruction*> exits_; |
| 56 GrowableArray<Definition*> worklist_; |
| 57 }; |
| 58 |
| 59 void CollectCandidates(); |
| 60 |
| 61 void NormalizeMaterializations(); |
| 62 |
| 63 void RemoveUnusedMaterializations(); |
| 64 |
| 65 void DiscoverFailedCandidates(); |
| 66 |
| 67 void InsertMaterializations(Definition* alloc); |
| 68 |
| 69 void CreateMaterializationAt( |
| 70 Instruction* exit, |
| 71 Definition* alloc, |
| 72 const ZoneGrowableArray<const Object*>& fields); |
| 73 |
| 74 void EliminateAllocation(Definition* alloc); |
| 75 |
| 76 Isolate* isolate() const { return flow_graph_->isolate(); } |
| 77 Zone* zone() const { return flow_graph_->zone(); } |
| 78 |
| 79 FlowGraph* flow_graph_; |
| 80 |
| 81 GrowableArray<Definition*> candidates_; |
| 82 GrowableArray<MaterializeObjectInstr*> materializations_; |
| 83 |
| 84 ExitsCollector exits_collector_; |
| 85 }; |
| 86 |
| 87 |
| 88 // A simple common subexpression elimination based |
| 89 // on the dominator tree. |
| 90 class DominatorBasedCSE : public AllStatic { |
| 91 public: |
| 92 // Return true, if the optimization changed the flow graph. |
| 93 // False, if nothing changed. |
| 94 static bool Optimize(FlowGraph* graph); |
| 95 |
| 96 private: |
| 97 static bool OptimizeRecursive( |
| 98 FlowGraph* graph, |
| 99 BlockEntryInstr* entry, |
| 100 CSEInstructionMap* map); |
| 101 }; |
| 102 |
| 103 |
| 104 class DeadStoreElimination : public AllStatic { |
| 105 public: |
| 106 static void Optimize(FlowGraph* graph); |
| 107 }; |
| 108 |
| 109 |
| 110 class DeadCodeElimination : public AllStatic { |
| 111 public: |
| 112 static void EliminateDeadPhis(FlowGraph* graph); |
| 113 }; |
| 114 |
| 115 |
| 116 // Optimize spill stores inside try-blocks by identifying values that always |
| 117 // contain a single known constant at catch block entry. |
| 118 class TryCatchAnalyzer : public AllStatic { |
| 119 public: |
| 120 static void Optimize(FlowGraph* flow_graph); |
| 121 }; |
| 122 |
| 123 |
| 124 // Loop invariant code motion. |
| 125 class LICM : public ValueObject { |
| 126 public: |
| 127 explicit LICM(FlowGraph* flow_graph); |
| 128 |
| 129 void Optimize(); |
| 130 |
| 131 void OptimisticallySpecializeSmiPhis(); |
| 132 |
| 133 private: |
| 134 FlowGraph* flow_graph() const { return flow_graph_; } |
| 135 |
| 136 void Hoist(ForwardInstructionIterator* it, |
| 137 BlockEntryInstr* pre_header, |
| 138 Instruction* current); |
| 139 |
| 140 void TrySpecializeSmiPhi(PhiInstr* phi, |
| 141 BlockEntryInstr* header, |
| 142 BlockEntryInstr* pre_header); |
| 143 |
| 144 FlowGraph* const flow_graph_; |
| 145 }; |
| 146 |
| 147 } // namespace dart |
| 148 |
| 149 #endif // VM_REDUNDANCY_ELIMINATION_H_ |
OLD | NEW |