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