| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_OPTIMIZER_H_ | 5 #ifndef VM_FLOW_GRAPH_OPTIMIZER_H_ |
| 6 #define VM_FLOW_GRAPH_OPTIMIZER_H_ | 6 #define VM_FLOW_GRAPH_OPTIMIZER_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 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 public: | 149 public: |
| 150 static void Optimize(FlowGraph* graph); | 150 static void Optimize(FlowGraph* graph); |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 static void OptimizeRecursive( | 153 static void OptimizeRecursive( |
| 154 BlockEntryInstr* entry, | 154 BlockEntryInstr* entry, |
| 155 DirectChainedHashMap<Definition*>* map); | 155 DirectChainedHashMap<Definition*>* map); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 | 158 |
| 159 // Sparse conditional constant propagation and unreachable code elimination. |
| 160 // Assumes that use lists are computed and preserves them. |
| 161 class ConstantPropagator : public FlowGraphVisitor { |
| 162 public: |
| 163 ConstantPropagator(FlowGraph* graph, |
| 164 const GrowableArray<BlockEntryInstr*>& ignored); |
| 165 |
| 166 static void Optimize(FlowGraph* graph); |
| 167 |
| 168 // Used to initialize the abstract value of definitions. |
| 169 static RawObject* Unknown() { return Object::transition_sentinel(); } |
| 170 |
| 171 private: |
| 172 void Analyze(); |
| 173 void Transform(); |
| 174 |
| 175 void SetReachable(BlockEntryInstr* block); |
| 176 void SetValue(Definition* definition, const Object& value); |
| 177 |
| 178 // Assign the join (least upper bound) of a pair of abstract values to the |
| 179 // first one. |
| 180 void Join(Object* left, const Object& right); |
| 181 |
| 182 bool IsUnknown(const Object& value) { |
| 183 return value.raw() == unknown_.raw(); |
| 184 } |
| 185 bool IsNonConstant(const Object& value) { |
| 186 return value.raw() == non_constant_.raw(); |
| 187 } |
| 188 bool IsConstant(const Object& value) { |
| 189 return !IsNonConstant(value) && !IsUnknown(value); |
| 190 } |
| 191 |
| 192 virtual void VisitBlocks() { UNREACHABLE(); } |
| 193 |
| 194 #define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr); |
| 195 FOR_EACH_INSTRUCTION(DECLARE_VISIT) |
| 196 #undef DECLARE_VISIT |
| 197 |
| 198 FlowGraph* graph_; |
| 199 |
| 200 // Sentinels for unknown constant and non-constant values. |
| 201 const Object& unknown_; |
| 202 const Object& non_constant_; |
| 203 |
| 204 // Analysis results. For each block, a reachability bit. Indexed by |
| 205 // preorder number. |
| 206 BitVector* reachable_; |
| 207 |
| 208 // Definitions can move up the lattice twice, so we use a mark bit to |
| 209 // indicate that they are already on the worklist in order to avoid adding |
| 210 // them again. Indexed by SSA temp index. |
| 211 BitVector* definition_marks_; |
| 212 |
| 213 // Worklists of blocks and definitions. |
| 214 GrowableArray<BlockEntryInstr*> block_worklist_; |
| 215 GrowableArray<Definition*> definition_worklist_; |
| 216 }; |
| 217 |
| 218 |
| 159 } // namespace dart | 219 } // namespace dart |
| 160 | 220 |
| 161 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ | 221 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ |
| OLD | NEW |