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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 I->object_store()->set_compiletime_error_class(null_class); | 488 I->object_store()->set_compiletime_error_class(null_class); |
489 } | 489 } |
490 DropClasses(); | 490 DropClasses(); |
491 DropLibraries(); | 491 DropLibraries(); |
492 | 492 |
493 BindStaticCalls(); | 493 BindStaticCalls(); |
494 SwitchICCalls(); | 494 SwitchICCalls(); |
495 | 495 |
496 ShareMegamorphicBuckets(); | 496 ShareMegamorphicBuckets(); |
497 DedupStackMaps(); | 497 DedupStackMaps(); |
| 498 DedupCodeSourceMaps(); |
498 DedupLists(); | 499 DedupLists(); |
499 | 500 |
500 if (FLAG_dedup_instructions) { | 501 if (FLAG_dedup_instructions) { |
501 // Reduces binary size but obfuscates profiler results. | 502 // Reduces binary size but obfuscates profiler results. |
502 DedupInstructions(); | 503 DedupInstructions(); |
503 } | 504 } |
504 | 505 |
505 zone_ = NULL; | 506 zone_ = NULL; |
506 } | 507 } |
507 | 508 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 target_code ^= entry.raw(); | 978 target_code ^= entry.raw(); |
978 if (target_code.IsAllocationStubCode()) { | 979 if (target_code.IsAllocationStubCode()) { |
979 cls ^= target_code.owner(); | 980 cls ^= target_code.owner(); |
980 AddInstantiatedClass(cls); | 981 AddInstantiatedClass(cls); |
981 } | 982 } |
982 } else if (entry.IsTypeArguments()) { | 983 } else if (entry.IsTypeArguments()) { |
983 AddTypeArguments(TypeArguments::Cast(entry)); | 984 AddTypeArguments(TypeArguments::Cast(entry)); |
984 } | 985 } |
985 } | 986 } |
986 } | 987 } |
| 988 |
| 989 const Array& inlined_functions = |
| 990 Array::Handle(Z, code.inlined_id_to_function()); |
| 991 for (intptr_t i = 0; i < inlined_functions.Length(); i++) { |
| 992 target ^= inlined_functions.At(i); |
| 993 AddTypesOf(target); |
| 994 } |
987 } | 995 } |
988 | 996 |
989 | 997 |
990 void Precompiler::AddTypesOf(const Class& cls) { | 998 void Precompiler::AddTypesOf(const Class& cls) { |
991 if (cls.IsNull()) return; | 999 if (cls.IsNull()) return; |
992 if (classes_to_retain_.Lookup(&cls) != NULL) return; | 1000 if (classes_to_retain_.Lookup(&cls) != NULL) return; |
993 classes_to_retain_.Insert(&Class::ZoneHandle(Z, cls.raw())); | 1001 classes_to_retain_.Insert(&Class::ZoneHandle(Z, cls.raw())); |
994 | 1002 |
995 Array& interfaces = Array::Handle(Z, cls.interfaces()); | 1003 Array& interfaces = Array::Handle(Z, cls.interfaces()); |
996 AbstractType& type = AbstractType::Handle(Z); | 1004 AbstractType& type = AbstractType::Handle(Z); |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 Code& code_; | 2342 Code& code_; |
2335 Array& stackmaps_; | 2343 Array& stackmaps_; |
2336 StackMap& stackmap_; | 2344 StackMap& stackmap_; |
2337 }; | 2345 }; |
2338 | 2346 |
2339 DedupStackMapsVisitor visitor(Z); | 2347 DedupStackMapsVisitor visitor(Z); |
2340 ProgramVisitor::VisitFunctions(&visitor); | 2348 ProgramVisitor::VisitFunctions(&visitor); |
2341 } | 2349 } |
2342 | 2350 |
2343 | 2351 |
| 2352 void Precompiler::DedupCodeSourceMaps() { |
| 2353 class DedupCodeSourceMapsVisitor : public FunctionVisitor { |
| 2354 public: |
| 2355 explicit DedupCodeSourceMapsVisitor(Zone* zone) |
| 2356 : zone_(zone), |
| 2357 canonical_code_source_maps_(), |
| 2358 code_(Code::Handle(zone)), |
| 2359 code_source_map_(CodeSourceMap::Handle(zone)) {} |
| 2360 |
| 2361 void Visit(const Function& function) { |
| 2362 if (!function.HasCode()) { |
| 2363 return; |
| 2364 } |
| 2365 code_ = function.CurrentCode(); |
| 2366 code_source_map_ = code_.code_source_map(); |
| 2367 ASSERT(!code_source_map_.IsNull()); |
| 2368 code_source_map_ = DedupCodeSourceMap(code_source_map_); |
| 2369 code_.set_code_source_map(code_source_map_); |
| 2370 } |
| 2371 |
| 2372 RawCodeSourceMap* DedupCodeSourceMap(const CodeSourceMap& code_source_map) { |
| 2373 const CodeSourceMap* canonical_code_source_map = |
| 2374 canonical_code_source_maps_.LookupValue(&code_source_map); |
| 2375 if (canonical_code_source_map == NULL) { |
| 2376 canonical_code_source_maps_.Insert( |
| 2377 &CodeSourceMap::ZoneHandle(zone_, code_source_map.raw())); |
| 2378 return code_source_map.raw(); |
| 2379 } else { |
| 2380 return canonical_code_source_map->raw(); |
| 2381 } |
| 2382 } |
| 2383 |
| 2384 private: |
| 2385 Zone* zone_; |
| 2386 CodeSourceMapSet canonical_code_source_maps_; |
| 2387 Code& code_; |
| 2388 CodeSourceMap& code_source_map_; |
| 2389 }; |
| 2390 |
| 2391 DedupCodeSourceMapsVisitor visitor(Z); |
| 2392 ProgramVisitor::VisitFunctions(&visitor); |
| 2393 } |
| 2394 |
| 2395 |
2344 void Precompiler::DedupLists() { | 2396 void Precompiler::DedupLists() { |
2345 class DedupListsVisitor : public FunctionVisitor { | 2397 class DedupListsVisitor : public FunctionVisitor { |
2346 public: | 2398 public: |
2347 explicit DedupListsVisitor(Zone* zone) | 2399 explicit DedupListsVisitor(Zone* zone) |
2348 : zone_(zone), | 2400 : zone_(zone), |
2349 canonical_lists_(), | 2401 canonical_lists_(), |
2350 code_(Code::Handle(zone)), | 2402 code_(Code::Handle(zone)), |
2351 list_(Array::Handle(zone)) {} | 2403 list_(Array::Handle(zone)) {} |
2352 | 2404 |
2353 void Visit(const Function& function) { | 2405 void Visit(const Function& function) { |
2354 code_ = function.CurrentCode(); | 2406 code_ = function.CurrentCode(); |
2355 if (!code_.IsNull()) { | 2407 if (!code_.IsNull()) { |
2356 list_ = code_.stackmaps(); | 2408 list_ = code_.stackmaps(); |
2357 if (!list_.IsNull()) { | 2409 if (!list_.IsNull()) { |
2358 list_ = DedupList(list_); | 2410 list_ = DedupList(list_); |
2359 code_.set_stackmaps(list_); | 2411 code_.set_stackmaps(list_); |
2360 } | 2412 } |
| 2413 list_ = code_.inlined_id_to_function(); |
| 2414 if (!list_.IsNull()) { |
| 2415 list_ = DedupList(list_); |
| 2416 code_.set_inlined_id_to_function(list_); |
| 2417 } |
2361 } | 2418 } |
2362 | 2419 |
2363 list_ = function.parameter_types(); | 2420 list_ = function.parameter_types(); |
2364 if (!list_.IsNull()) { | 2421 if (!list_.IsNull()) { |
2365 if (!function.IsSignatureFunction() && !function.IsClosureFunction() && | 2422 if (!function.IsSignatureFunction() && !function.IsClosureFunction() && |
2366 (function.name() != Symbols::Call().raw()) && !list_.InVMHeap()) { | 2423 (function.name() != Symbols::Call().raw()) && !list_.InVMHeap()) { |
2367 // Parameter types not needed for function type tests. | 2424 // Parameter types not needed for function type tests. |
2368 for (intptr_t i = 0; i < list_.Length(); i++) { | 2425 for (intptr_t i = 0; i < list_.Length(); i++) { |
2369 list_.SetAt(i, Object::dynamic_type()); | 2426 list_.SetAt(i, Object::dynamic_type()); |
2370 } | 2427 } |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3748 | 3805 |
3749 ASSERT(FLAG_precompiled_mode); | 3806 ASSERT(FLAG_precompiled_mode); |
3750 const bool optimized = function.IsOptimizable(); // False for natives. | 3807 const bool optimized = function.IsOptimizable(); // False for natives. |
3751 DartPrecompilationPipeline pipeline(zone, field_type_map); | 3808 DartPrecompilationPipeline pipeline(zone, field_type_map); |
3752 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); | 3809 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); |
3753 } | 3810 } |
3754 | 3811 |
3755 #endif // DART_PRECOMPILER | 3812 #endif // DART_PRECOMPILER |
3756 | 3813 |
3757 } // namespace dart | 3814 } // namespace dart |
OLD | NEW |