OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 #include "vm/precompiler.h" | 5 #include "vm/precompiler.h" |
6 | 6 |
7 #include "vm/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/branch_optimizer.h" | 10 #include "vm/branch_optimizer.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 | 186 |
187 void Precompiler::DoCompileAll( | 187 void Precompiler::DoCompileAll( |
188 Dart_QualifiedFunctionName embedder_entry_points[]) { | 188 Dart_QualifiedFunctionName embedder_entry_points[]) { |
189 ASSERT(I->compilation_allowed()); | 189 ASSERT(I->compilation_allowed()); |
190 | 190 |
191 { | 191 { |
192 StackZone stack_zone(T); | 192 StackZone stack_zone(T); |
193 zone_ = stack_zone.GetZone(); | 193 zone_ = stack_zone.GetZone(); |
194 | 194 |
195 // Make sure class hierarchy is stable before compilation so that CHA | 195 { HANDLESCOPE(T); |
196 // can be used. Also ensures lookup of entry points won't miss functions | 196 // Make sure class hierarchy is stable before compilation so that CHA |
197 // because their class hasn't been finalized yet. | 197 // can be used. Also ensures lookup of entry points won't miss functions |
198 FinalizeAllClasses(); | 198 // because their class hasn't been finalized yet. |
| 199 FinalizeAllClasses(); |
199 | 200 |
200 // Precompile static initializers to compute result type information. | 201 // Precompile static initializers to compute result type information. |
201 PrecompileStaticInitializers(); | 202 PrecompileStaticInitializers(); |
202 | 203 |
203 for (intptr_t round = 0; round < FLAG_precompiler_rounds; round++) { | 204 for (intptr_t round = 0; round < FLAG_precompiler_rounds; round++) { |
204 if (FLAG_trace_precompiler) { | 205 if (FLAG_trace_precompiler) { |
205 THR_Print("Precompiler round %" Pd "\n", round); | 206 THR_Print("Precompiler round %" Pd "\n", round); |
| 207 } |
| 208 |
| 209 if (round > 0) { |
| 210 ResetPrecompilerState(); |
| 211 } |
| 212 |
| 213 // TODO(rmacnak): We should be able to do a more thorough job and drop |
| 214 // some |
| 215 // - implicit static closures |
| 216 // - field initializers |
| 217 // - invoke-field-dispatchers |
| 218 // - method-extractors |
| 219 // that are needed in early iterations but optimized away in later |
| 220 // iterations. |
| 221 ClearAllCode(); |
| 222 |
| 223 CollectDynamicFunctionNames(); |
| 224 |
| 225 // Start with the allocations and invocations that happen from C++. |
| 226 AddRoots(embedder_entry_points); |
| 227 |
| 228 // Compile newly found targets and add their callees until we reach a |
| 229 // fixed point. |
| 230 Iterate(); |
206 } | 231 } |
207 | 232 |
208 if (round > 0) { | 233 I->set_compilation_allowed(false); |
209 ResetPrecompilerState(); | |
210 } | |
211 | 234 |
212 // TODO(rmacnak): We should be able to do a more thorough job and drop | 235 TraceForRetainedFunctions(); |
213 // some | 236 DropFunctions(); |
214 // - implicit static closures | 237 DropFields(); |
215 // - field initializers | 238 TraceTypesFromRetainedClasses(); |
216 // - invoke-field-dispatchers | 239 DropTypes(); |
217 // - method-extractors | 240 DropTypeArguments(); |
218 // that are needed in early iterations but optimized away in later | |
219 // iterations. | |
220 ClearAllCode(); | |
221 | 241 |
222 CollectDynamicFunctionNames(); | 242 // Clear these before dropping classes as they may hold onto otherwise |
223 | 243 // dead instances of classes we will remove. |
224 // Start with the allocations and invocations that happen from C++. | 244 I->object_store()->set_compile_time_constants(Array::null_array()); |
225 AddRoots(embedder_entry_points); | 245 I->object_store()->set_unique_dynamic_targets(Array::null_array()); |
226 | 246 Class& null_class = Class::Handle(Z); |
227 // Compile newly found targets and add their callees until we reach a | 247 I->object_store()->set_future_class(null_class); |
228 // fixed point. | 248 I->object_store()->set_completer_class(null_class); |
229 Iterate(); | 249 I->object_store()->set_stream_iterator_class(null_class); |
| 250 I->object_store()->set_symbol_class(null_class); |
230 } | 251 } |
231 | |
232 I->set_compilation_allowed(false); | |
233 | |
234 TraceForRetainedFunctions(); | |
235 DropFunctions(); | |
236 DropFields(); | |
237 TraceTypesFromRetainedClasses(); | |
238 DropTypes(); | |
239 DropTypeArguments(); | |
240 | |
241 // Clear these before dropping classes as they may hold onto otherwise | |
242 // dead instances of classes we will remove. | |
243 I->object_store()->set_compile_time_constants(Array::null_array()); | |
244 I->object_store()->set_unique_dynamic_targets(Array::null_array()); | |
245 Class& null_class = Class::Handle(Z); | |
246 I->object_store()->set_future_class(null_class); | |
247 I->object_store()->set_completer_class(null_class); | |
248 I->object_store()->set_stream_iterator_class(null_class); | |
249 I->object_store()->set_symbol_class(null_class); | |
250 | |
251 DropClasses(); | 252 DropClasses(); |
252 DropLibraries(); | 253 DropLibraries(); |
253 | 254 |
254 BindStaticCalls(); | 255 BindStaticCalls(); |
255 SwitchICCalls(); | 256 SwitchICCalls(); |
256 | 257 |
257 DedupStackmaps(); | 258 DedupStackmaps(); |
258 DedupStackmapLists(); | 259 DedupStackmapLists(); |
259 | 260 |
260 if (FLAG_dedup_instructions) { | 261 if (FLAG_dedup_instructions) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 CompileStaticInitializerIgnoreErrors(field_); | 323 CompileStaticInitializerIgnoreErrors(field_); |
323 } | 324 } |
324 } | 325 } |
325 } | 326 } |
326 | 327 |
327 private: | 328 private: |
328 Array& fields_; | 329 Array& fields_; |
329 Field& field_; | 330 Field& field_; |
330 Function& function_; | 331 Function& function_; |
331 }; | 332 }; |
| 333 |
| 334 HANDLESCOPE(T); |
332 StaticInitializerVisitor visitor(Z); | 335 StaticInitializerVisitor visitor(Z); |
333 VisitClasses(&visitor); | 336 VisitClasses(&visitor); |
334 } | 337 } |
335 | 338 |
336 | 339 |
337 void Precompiler::ClearAllCode() { | 340 void Precompiler::ClearAllCode() { |
338 class ClearCodeFunctionVisitor : public FunctionVisitor { | 341 class ClearCodeFunctionVisitor : public FunctionVisitor { |
339 void Visit(const Function& function) { | 342 void Visit(const Function& function) { |
340 function.ClearCode(); | 343 function.ClearCode(); |
341 function.ClearICDataArray(); | 344 function.ClearICDataArray(); |
(...skipping 2501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 CompilationPipeline::New(thread->zone(), function); | 2846 CompilationPipeline::New(thread->zone(), function); |
2844 | 2847 |
2845 ASSERT(FLAG_precompiled_mode); | 2848 ASSERT(FLAG_precompiled_mode); |
2846 const bool optimized = function.IsOptimizable(); // False for natives. | 2849 const bool optimized = function.IsOptimizable(); // False for natives. |
2847 return PrecompileFunctionHelper(pipeline, function, optimized); | 2850 return PrecompileFunctionHelper(pipeline, function, optimized); |
2848 } | 2851 } |
2849 | 2852 |
2850 #endif // DART_PRECOMPILER | 2853 #endif // DART_PRECOMPILER |
2851 | 2854 |
2852 } // namespace dart | 2855 } // namespace dart |
OLD | NEW |