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 RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ | 5 #ifndef RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ |
6 #define RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ | 6 #define RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
11 #include "vm/intermediate_language.h" | 11 #include "vm/intermediate_language.h" |
12 #include "vm/runtime_entry.h" | 12 #include "vm/runtime_entry.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 // Forward declarations. | 16 // Forward declarations. |
17 class Code; | 17 class Code; |
18 class DeoptInfoBuilder; | 18 class DeoptInfoBuilder; |
19 class FlowGraph; | 19 class FlowGraph; |
20 class FlowGraphCompiler; | 20 class FlowGraphCompiler; |
21 class Function; | 21 class Function; |
22 template <typename T> | 22 template <typename T> |
23 class GrowableArray; | 23 class GrowableArray; |
24 class ParsedFunction; | 24 class ParsedFunction; |
25 | 25 |
26 | |
27 class ParallelMoveResolver : public ValueObject { | 26 class ParallelMoveResolver : public ValueObject { |
28 public: | 27 public: |
29 explicit ParallelMoveResolver(FlowGraphCompiler* compiler); | 28 explicit ParallelMoveResolver(FlowGraphCompiler* compiler); |
30 | 29 |
31 // Resolve a set of parallel moves, emitting assembler instructions. | 30 // Resolve a set of parallel moves, emitting assembler instructions. |
32 void EmitNativeCode(ParallelMoveInstr* parallel_move); | 31 void EmitNativeCode(ParallelMoveInstr* parallel_move); |
33 | 32 |
34 private: | 33 private: |
35 class ScratchFpuRegisterScope : public ValueObject { | 34 class ScratchFpuRegisterScope : public ValueObject { |
36 public: | 35 public: |
(...skipping 15 matching lines...) Expand all Loading... |
52 ~ScratchRegisterScope(); | 51 ~ScratchRegisterScope(); |
53 | 52 |
54 Register reg() const { return reg_; } | 53 Register reg() const { return reg_; } |
55 | 54 |
56 private: | 55 private: |
57 ParallelMoveResolver* resolver_; | 56 ParallelMoveResolver* resolver_; |
58 Register reg_; | 57 Register reg_; |
59 bool spilled_; | 58 bool spilled_; |
60 }; | 59 }; |
61 | 60 |
62 | |
63 bool IsScratchLocation(Location loc); | 61 bool IsScratchLocation(Location loc); |
64 intptr_t AllocateScratchRegister(Location::Kind kind, | 62 intptr_t AllocateScratchRegister(Location::Kind kind, |
65 uword blocked_mask, | 63 uword blocked_mask, |
66 intptr_t first_free_register, | 64 intptr_t first_free_register, |
67 intptr_t last_free_register, | 65 intptr_t last_free_register, |
68 bool* spilled); | 66 bool* spilled); |
69 | 67 |
70 void SpillScratch(Register reg); | 68 void SpillScratch(Register reg); |
71 void RestoreScratch(Register reg); | 69 void RestoreScratch(Register reg); |
72 void SpillFpuScratch(FpuRegister reg); | 70 void SpillFpuScratch(FpuRegister reg); |
(...skipping 29 matching lines...) Expand all Loading... |
102 intptr_t stack_offset1, | 100 intptr_t stack_offset1, |
103 Register base_reg2, | 101 Register base_reg2, |
104 intptr_t stack_offset2); | 102 intptr_t stack_offset2); |
105 | 103 |
106 FlowGraphCompiler* compiler_; | 104 FlowGraphCompiler* compiler_; |
107 | 105 |
108 // List of moves not yet resolved. | 106 // List of moves not yet resolved. |
109 GrowableArray<MoveOperands*> moves_; | 107 GrowableArray<MoveOperands*> moves_; |
110 }; | 108 }; |
111 | 109 |
112 | |
113 // Used for describing a deoptimization point after call (lazy deoptimization). | 110 // Used for describing a deoptimization point after call (lazy deoptimization). |
114 // For deoptimization before instruction use class CompilerDeoptInfoWithStub. | 111 // For deoptimization before instruction use class CompilerDeoptInfoWithStub. |
115 class CompilerDeoptInfo : public ZoneAllocated { | 112 class CompilerDeoptInfo : public ZoneAllocated { |
116 public: | 113 public: |
117 CompilerDeoptInfo(intptr_t deopt_id, | 114 CompilerDeoptInfo(intptr_t deopt_id, |
118 ICData::DeoptReasonId reason, | 115 ICData::DeoptReasonId reason, |
119 uint32_t flags, | 116 uint32_t flags, |
120 Environment* deopt_env) | 117 Environment* deopt_env) |
121 : pc_offset_(-1), | 118 : pc_offset_(-1), |
122 deopt_id_(deopt_id), | 119 deopt_id_(deopt_id), |
123 reason_(reason), | 120 reason_(reason), |
124 flags_(flags), | 121 flags_(flags), |
125 #if defined(TARGET_ARCH_DBC) | 122 #if defined(TARGET_ARCH_DBC) |
126 lazy_deopt_with_result_(false), | 123 lazy_deopt_with_result_(false), |
127 #endif | 124 #endif |
128 deopt_env_(deopt_env) { | 125 deopt_env_(deopt_env) { |
129 ASSERT(deopt_env != NULL); | 126 ASSERT(deopt_env != NULL); |
130 } | 127 } |
131 virtual ~CompilerDeoptInfo() {} | 128 virtual ~CompilerDeoptInfo() {} |
132 | 129 |
133 RawTypedData* CreateDeoptInfo(FlowGraphCompiler* compiler, | 130 RawTypedData* CreateDeoptInfo(FlowGraphCompiler* compiler, |
134 DeoptInfoBuilder* builder, | 131 DeoptInfoBuilder* builder, |
135 const Array& deopt_table); | 132 const Array& deopt_table); |
136 | 133 |
137 | |
138 // No code needs to be generated. | 134 // No code needs to be generated. |
139 virtual void GenerateCode(FlowGraphCompiler* compiler, intptr_t stub_ix) {} | 135 virtual void GenerateCode(FlowGraphCompiler* compiler, intptr_t stub_ix) {} |
140 | 136 |
141 intptr_t pc_offset() const { return pc_offset_; } | 137 intptr_t pc_offset() const { return pc_offset_; } |
142 void set_pc_offset(intptr_t offset) { pc_offset_ = offset; } | 138 void set_pc_offset(intptr_t offset) { pc_offset_ = offset; } |
143 | 139 |
144 intptr_t deopt_id() const { return deopt_id_; } | 140 intptr_t deopt_id() const { return deopt_id_; } |
145 ICData::DeoptReasonId reason() const { return reason_; } | 141 ICData::DeoptReasonId reason() const { return reason_; } |
146 uint32_t flags() const { return flags_; } | 142 uint32_t flags() const { return flags_; } |
147 const Environment* deopt_env() const { return deopt_env_; } | 143 const Environment* deopt_env() const { return deopt_env_; } |
(...skipping 21 matching lines...) Expand all Loading... |
169 const ICData::DeoptReasonId reason_; | 165 const ICData::DeoptReasonId reason_; |
170 const uint32_t flags_; | 166 const uint32_t flags_; |
171 #if defined(TARGET_ARCH_DBC) | 167 #if defined(TARGET_ARCH_DBC) |
172 bool lazy_deopt_with_result_; | 168 bool lazy_deopt_with_result_; |
173 #endif | 169 #endif |
174 Environment* deopt_env_; | 170 Environment* deopt_env_; |
175 | 171 |
176 DISALLOW_COPY_AND_ASSIGN(CompilerDeoptInfo); | 172 DISALLOW_COPY_AND_ASSIGN(CompilerDeoptInfo); |
177 }; | 173 }; |
178 | 174 |
179 | |
180 class CompilerDeoptInfoWithStub : public CompilerDeoptInfo { | 175 class CompilerDeoptInfoWithStub : public CompilerDeoptInfo { |
181 public: | 176 public: |
182 CompilerDeoptInfoWithStub(intptr_t deopt_id, | 177 CompilerDeoptInfoWithStub(intptr_t deopt_id, |
183 ICData::DeoptReasonId reason, | 178 ICData::DeoptReasonId reason, |
184 uint32_t flags, | 179 uint32_t flags, |
185 Environment* deopt_env) | 180 Environment* deopt_env) |
186 : CompilerDeoptInfo(deopt_id, reason, flags, deopt_env), entry_label_() { | 181 : CompilerDeoptInfo(deopt_id, reason, flags, deopt_env), entry_label_() { |
187 ASSERT(reason != ICData::kDeoptAtCall); | 182 ASSERT(reason != ICData::kDeoptAtCall); |
188 } | 183 } |
189 | 184 |
(...skipping 12 matching lines...) Expand all Loading... |
202 DeoptReasonToCString(reason())); | 197 DeoptReasonToCString(reason())); |
203 return chars; | 198 return chars; |
204 } | 199 } |
205 | 200 |
206 private: | 201 private: |
207 Label entry_label_; | 202 Label entry_label_; |
208 | 203 |
209 DISALLOW_COPY_AND_ASSIGN(CompilerDeoptInfoWithStub); | 204 DISALLOW_COPY_AND_ASSIGN(CompilerDeoptInfoWithStub); |
210 }; | 205 }; |
211 | 206 |
212 | |
213 class SlowPathCode : public ZoneAllocated { | 207 class SlowPathCode : public ZoneAllocated { |
214 public: | 208 public: |
215 SlowPathCode() : entry_label_(), exit_label_() {} | 209 SlowPathCode() : entry_label_(), exit_label_() {} |
216 virtual ~SlowPathCode() {} | 210 virtual ~SlowPathCode() {} |
217 | 211 |
218 Label* entry_label() { return &entry_label_; } | 212 Label* entry_label() { return &entry_label_; } |
219 Label* exit_label() { return &exit_label_; } | 213 Label* exit_label() { return &exit_label_; } |
220 | 214 |
221 void GenerateCode(FlowGraphCompiler* compiler) { | 215 void GenerateCode(FlowGraphCompiler* compiler) { |
222 EmitNativeCode(compiler); | 216 EmitNativeCode(compiler); |
223 ASSERT(entry_label_.IsBound()); | 217 ASSERT(entry_label_.IsBound()); |
224 } | 218 } |
225 | 219 |
226 private: | 220 private: |
227 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; | 221 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; |
228 | 222 |
229 Label entry_label_; | 223 Label entry_label_; |
230 Label exit_label_; | 224 Label exit_label_; |
231 | 225 |
232 DISALLOW_COPY_AND_ASSIGN(SlowPathCode); | 226 DISALLOW_COPY_AND_ASSIGN(SlowPathCode); |
233 }; | 227 }; |
234 | 228 |
235 | |
236 class FlowGraphCompiler : public ValueObject { | 229 class FlowGraphCompiler : public ValueObject { |
237 private: | 230 private: |
238 class BlockInfo : public ZoneAllocated { | 231 class BlockInfo : public ZoneAllocated { |
239 public: | 232 public: |
240 BlockInfo() | 233 BlockInfo() |
241 : block_label_(), | 234 : block_label_(), |
242 jump_label_(&block_label_), | 235 jump_label_(&block_label_), |
243 next_nonempty_label_(NULL), | 236 next_nonempty_label_(NULL), |
244 is_marked_(false) {} | 237 is_marked_(false) {} |
245 | 238 |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 ZoneGrowableArray<const ICData*>* deopt_id_to_ic_data_; | 834 ZoneGrowableArray<const ICData*>* deopt_id_to_ic_data_; |
842 | 835 |
843 Array& edge_counters_array_; | 836 Array& edge_counters_array_; |
844 | 837 |
845 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler); | 838 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler); |
846 }; | 839 }; |
847 | 840 |
848 } // namespace dart | 841 } // namespace dart |
849 | 842 |
850 #endif // RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ | 843 #endif // RUNTIME_VM_FLOW_GRAPH_COMPILER_H_ |
OLD | NEW |