| 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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class CSEInstructionMap; | 13 class CSEInstructionMap; |
| 14 template <typename T> class GrowableArray; | 14 template <typename T> class GrowableArray; |
| 15 class ParsedFunction; | 15 class ParsedFunction; |
| 16 | 16 |
| 17 class FlowGraphOptimizer : public FlowGraphVisitor { | 17 class FlowGraphOptimizer : public FlowGraphVisitor { |
| 18 public: | 18 public: |
| 19 FlowGraphOptimizer(FlowGraph* flow_graph, | 19 FlowGraphOptimizer(FlowGraph* flow_graph, |
| 20 GrowableArray<Field*>* guarded_fields) | 20 GrowableArray<const Field*>* guarded_fields) |
| 21 : FlowGraphVisitor(flow_graph->reverse_postorder()), | 21 : FlowGraphVisitor(flow_graph->reverse_postorder()), |
| 22 flow_graph_(flow_graph), | 22 flow_graph_(flow_graph), |
| 23 guarded_fields_(guarded_fields) { } | 23 guarded_fields_(guarded_fields) { } |
| 24 virtual ~FlowGraphOptimizer() {} | 24 virtual ~FlowGraphOptimizer() {} |
| 25 | 25 |
| 26 FlowGraph* flow_graph() const { return flow_graph_; } | 26 FlowGraph* flow_graph() const { return flow_graph_; } |
| 27 | 27 |
| 28 // Use ICData to optimize, replace or eliminate instructions. | 28 // Use ICData to optimize, replace or eliminate instructions. |
| 29 void ApplyICData(); | 29 void ApplyICData(); |
| 30 | 30 |
| 31 // Use propagated class ids to optimize, replace or eliminate instructions. | 31 // Use propagated class ids to optimize, replace or eliminate instructions. |
| 32 void ApplyClassIds(); | 32 void ApplyClassIds(); |
| 33 | 33 |
| 34 // Optimize (a << b) & c pattern: if c is a positive Smi or zero, then the | 34 // Optimize (a << b) & c pattern: if c is a positive Smi or zero, then the |
| 35 // shift can be a truncating Smi shift-left and result is always Smi. | 35 // shift can be a truncating Smi shift-left and result is always Smi. |
| 36 void TryOptimizeLeftShiftWithBitAndPattern(); | 36 void TryOptimizeLeftShiftWithBitAndPattern(); |
| 37 | 37 |
| 38 void Canonicalize(); | 38 // Returns true if any instructions were canonicalized away. |
| 39 bool Canonicalize(); |
| 39 | 40 |
| 40 void EliminateDeadPhis(); | 41 void EliminateDeadPhis(); |
| 41 | 42 |
| 42 void SelectRepresentations(); | 43 void SelectRepresentations(); |
| 43 | 44 |
| 44 void InferSmiRanges(); | 45 void InferSmiRanges(); |
| 45 | 46 |
| 46 virtual void VisitStaticCall(StaticCallInstr* instr); | 47 virtual void VisitStaticCall(StaticCallInstr* instr); |
| 47 virtual void VisitInstanceCall(InstanceCallInstr* instr); | 48 virtual void VisitInstanceCall(InstanceCallInstr* instr); |
| 48 virtual void VisitRelationalOp(RelationalOpInstr* instr); | 49 virtual void VisitRelationalOp(RelationalOpInstr* instr); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 static bool CanStrictifyEqualityCompare(EqualityCompareInstr* call); | 164 static bool CanStrictifyEqualityCompare(EqualityCompareInstr* call); |
| 164 | 165 |
| 165 template <typename T> | 166 template <typename T> |
| 166 bool StrictifyEqualityCompare(EqualityCompareInstr* compare, | 167 bool StrictifyEqualityCompare(EqualityCompareInstr* compare, |
| 167 T current_instruction) const; | 168 T current_instruction) const; |
| 168 | 169 |
| 169 void OptimizeLeftShiftBitAndSmiOp(Definition* bit_and_instr, | 170 void OptimizeLeftShiftBitAndSmiOp(Definition* bit_and_instr, |
| 170 Definition* left_instr, | 171 Definition* left_instr, |
| 171 Definition* right_instr); | 172 Definition* right_instr); |
| 172 | 173 |
| 173 void AddToGuardedFields(Field* field); | 174 void AddToGuardedFields(const Field& field); |
| 174 | 175 |
| 175 FlowGraph* flow_graph_; | 176 FlowGraph* flow_graph_; |
| 176 GrowableArray<Field*>* guarded_fields_; | 177 GrowableArray<const Field*>* guarded_fields_; |
| 177 | 178 |
| 178 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); | 179 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 | 182 |
| 182 // Loop invariant code motion. | 183 // Loop invariant code motion. |
| 183 class LICM : public ValueObject { | 184 class LICM : public ValueObject { |
| 184 public: | 185 public: |
| 185 explicit LICM(FlowGraph* flow_graph); | 186 explicit LICM(FlowGraph* flow_graph); |
| 186 | 187 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // platform. | 318 // platform. |
| 318 class IfConverter : public AllStatic { | 319 class IfConverter : public AllStatic { |
| 319 public: | 320 public: |
| 320 static void Simplify(FlowGraph* flow_graph); | 321 static void Simplify(FlowGraph* flow_graph); |
| 321 }; | 322 }; |
| 322 | 323 |
| 323 | 324 |
| 324 } // namespace dart | 325 } // namespace dart |
| 325 | 326 |
| 326 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ | 327 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ |
| OLD | NEW |