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 template <typename T> class GrowableArray; | 13 template <typename T> class GrowableArray; |
14 | 14 |
15 class FlowGraphOptimizer : public FlowGraphVisitor { | 15 class FlowGraphOptimizer : public FlowGraphVisitor { |
16 public: | 16 public: |
17 explicit FlowGraphOptimizer(const FlowGraph& flow_graph) | 17 FlowGraphOptimizer(const FlowGraph& flow_graph, bool use_ssa) |
18 : FlowGraphVisitor(flow_graph.reverse_postorder()) {} | 18 : FlowGraphVisitor(flow_graph.reverse_postorder()), use_ssa_(use_ssa) {} |
19 virtual ~FlowGraphOptimizer() {} | 19 virtual ~FlowGraphOptimizer() {} |
20 | 20 |
21 void ApplyICData(); | 21 void ApplyICData(); |
22 | 22 |
23 void OptimizeComputations(); | 23 void OptimizeComputations(); |
24 | 24 |
25 virtual void VisitStaticCall(StaticCallComp* comp, BindInstr* instr); | 25 virtual void VisitStaticCall(StaticCallComp* comp, BindInstr* instr); |
26 virtual void VisitInstanceCall(InstanceCallComp* comp, BindInstr* instr); | 26 virtual void VisitInstanceCall(InstanceCallComp* comp, BindInstr* instr); |
27 virtual void VisitRelationalOp(RelationalOpComp* comp, BindInstr* instr); | 27 virtual void VisitRelationalOp(RelationalOpComp* comp, BindInstr* instr); |
28 virtual void VisitEqualityCompare(EqualityCompareComp* comp, | 28 virtual void VisitEqualityCompare(EqualityCompareComp* comp, |
(...skipping 10 matching lines...) Expand all Loading... |
39 bool TryReplaceWithUnaryOp(BindInstr* instr, | 39 bool TryReplaceWithUnaryOp(BindInstr* instr, |
40 InstanceCallComp* comp, | 40 InstanceCallComp* comp, |
41 Token::Kind op_kind); | 41 Token::Kind op_kind); |
42 | 42 |
43 bool TryInlineInstanceGetter(BindInstr* instr, | 43 bool TryInlineInstanceGetter(BindInstr* instr, |
44 InstanceCallComp* comp); | 44 InstanceCallComp* comp); |
45 bool TryInlineInstanceSetter(BindInstr* instr, InstanceCallComp* comp); | 45 bool TryInlineInstanceSetter(BindInstr* instr, InstanceCallComp* comp); |
46 | 46 |
47 bool TryInlineInstanceMethod(BindInstr* instr, InstanceCallComp* comp); | 47 bool TryInlineInstanceMethod(BindInstr* instr, InstanceCallComp* comp); |
48 | 48 |
| 49 bool use_ssa_; |
| 50 |
49 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); | 51 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); |
50 }; | 52 }; |
51 | 53 |
52 | 54 |
53 // Analyze the generated flow graph. Currently only if it is a leaf | 55 // Analyze the generated flow graph. Currently only if it is a leaf |
54 // method, i.e., does not contain any calls to runtime or other Dart code. | 56 // method, i.e., does not contain any calls to runtime or other Dart code. |
55 class FlowGraphAnalyzer : public ValueObject { | 57 class FlowGraphAnalyzer : public ValueObject { |
56 public: | 58 public: |
57 explicit FlowGraphAnalyzer(const FlowGraph& flow_graph) | 59 explicit FlowGraphAnalyzer(const FlowGraph& flow_graph) |
58 : blocks_(flow_graph.reverse_postorder()), is_leaf_(false) {} | 60 : blocks_(flow_graph.reverse_postorder()), is_leaf_(false) {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 virtual void VisitPushArgument(PushArgumentInstr* bind); | 102 virtual void VisitPushArgument(PushArgumentInstr* bind); |
101 | 103 |
102 private: | 104 private: |
103 const ParsedFunction& parsed_function_; | 105 const ParsedFunction& parsed_function_; |
104 const bool is_ssa_; // TODO(regis): Remove once virtual frame backend is | 106 const bool is_ssa_; // TODO(regis): Remove once virtual frame backend is |
105 // removed. | 107 // removed. |
106 bool still_changing_; | 108 bool still_changing_; |
107 DISALLOW_COPY_AND_ASSIGN(FlowGraphTypePropagator); | 109 DISALLOW_COPY_AND_ASSIGN(FlowGraphTypePropagator); |
108 }; | 110 }; |
109 | 111 |
| 112 |
| 113 class LocalCSE : public ValueObject { |
| 114 public: |
| 115 explicit LocalCSE(const FlowGraph& flow_graph) |
| 116 : blocks_(flow_graph.reverse_postorder()) { } |
| 117 |
| 118 void Optimize(); |
| 119 |
| 120 private: |
| 121 const GrowableArray<BlockEntryInstr*>& blocks_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(LocalCSE); |
| 124 }; |
| 125 |
| 126 |
110 } // namespace dart | 127 } // namespace dart |
111 | 128 |
112 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ | 129 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ |
OLD | NEW |