OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/flow_graph_inliner.h" | 5 #include "vm/flow_graph_inliner.h" |
6 | 6 |
7 #include "vm/block_scheduler.h" | 7 #include "vm/block_scheduler.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/flow_graph.h" | 10 #include "vm/flow_graph.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 DEFINE_FLAG(int, inlining_constant_arguments_size_threshold, 60, | 44 DEFINE_FLAG(int, inlining_constant_arguments_size_threshold, 60, |
45 "Inline function calls with sufficient constant arguments " | 45 "Inline function calls with sufficient constant arguments " |
46 "and up to the increased threshold on instructions"); | 46 "and up to the increased threshold on instructions"); |
47 DEFINE_FLAG(int, inlining_hotness, 10, | 47 DEFINE_FLAG(int, inlining_hotness, 10, |
48 "Inline only hotter calls, in percents (0 .. 100); " | 48 "Inline only hotter calls, in percents (0 .. 100); " |
49 "default 10%: calls above-equal 10% of max-count are inlined."); | 49 "default 10%: calls above-equal 10% of max-count are inlined."); |
50 DEFINE_FLAG(bool, inline_recursive, false, "Inline recursive calls."); | 50 DEFINE_FLAG(bool, inline_recursive, false, "Inline recursive calls."); |
51 DEFINE_FLAG(int, max_inlined_per_depth, 500, | 51 DEFINE_FLAG(int, max_inlined_per_depth, 500, |
52 "Max. number of inlined calls per depth"); | 52 "Max. number of inlined calls per depth"); |
53 DEFINE_FLAG(bool, print_inlining_tree, false, "Print inlining tree"); | 53 DEFINE_FLAG(bool, print_inlining_tree, false, "Print inlining tree"); |
| 54 DEFINE_FLAG(bool, enable_inlining_annotations, false, |
| 55 "Enable inlining annotations"); |
54 | 56 |
55 DECLARE_FLAG(bool, compiler_stats); | 57 DECLARE_FLAG(bool, compiler_stats); |
56 DECLARE_FLAG(bool, enable_type_checks); | 58 DECLARE_FLAG(bool, enable_type_checks); |
57 DECLARE_FLAG(int, deoptimization_counter_threshold); | 59 DECLARE_FLAG(int, deoptimization_counter_threshold); |
58 DECLARE_FLAG(bool, print_flow_graph); | 60 DECLARE_FLAG(bool, print_flow_graph); |
59 DECLARE_FLAG(bool, print_flow_graph_optimized); | 61 DECLARE_FLAG(bool, print_flow_graph_optimized); |
60 DECLARE_FLAG(bool, verify_compiler); | 62 DECLARE_FLAG(bool, verify_compiler); |
61 | 63 |
62 #define TRACE_INLINING(statement) \ | 64 #define TRACE_INLINING(statement) \ |
63 do { \ | 65 do { \ |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 443 |
442 GrowableArray<CidTarget> inlined_variants_; | 444 GrowableArray<CidTarget> inlined_variants_; |
443 GrowableArray<CidTarget> non_inlined_variants_; | 445 GrowableArray<CidTarget> non_inlined_variants_; |
444 GrowableArray<BlockEntryInstr*> inlined_entries_; | 446 GrowableArray<BlockEntryInstr*> inlined_entries_; |
445 InlineExitCollector* exit_collector_; | 447 InlineExitCollector* exit_collector_; |
446 | 448 |
447 const Function& caller_function_; | 449 const Function& caller_function_; |
448 }; | 450 }; |
449 | 451 |
450 | 452 |
| 453 static bool HasAnnotation(const Function& function, const char* annotation) { |
| 454 const Class& owner = Class::Handle(function.Owner()); |
| 455 const Library& library = Library::Handle(owner.library()); |
| 456 const Array& metadata = |
| 457 Array::Cast(Object::Handle(library.GetMetadata(function))); |
| 458 |
| 459 if (metadata.Length() > 0) { |
| 460 Object& val = Object::Handle(); |
| 461 for (intptr_t i = 0; i < metadata.Length(); i++) { |
| 462 val = metadata.At(i); |
| 463 if (val.IsString() && String::Cast(val).Equals(annotation)) { |
| 464 return true; |
| 465 } |
| 466 } |
| 467 } |
| 468 return false; |
| 469 } |
| 470 |
| 471 |
451 class CallSiteInliner : public ValueObject { | 472 class CallSiteInliner : public ValueObject { |
452 public: | 473 public: |
453 explicit CallSiteInliner(FlowGraph* flow_graph) | 474 explicit CallSiteInliner(FlowGraph* flow_graph) |
454 : caller_graph_(flow_graph), | 475 : caller_graph_(flow_graph), |
455 inlined_(false), | 476 inlined_(false), |
456 initial_size_(flow_graph->InstructionCount()), | 477 initial_size_(flow_graph->InstructionCount()), |
457 inlined_size_(0), | 478 inlined_size_(0), |
458 inlining_depth_(1), | 479 inlining_depth_(1), |
459 collected_call_sites_(NULL), | 480 collected_call_sites_(NULL), |
460 inlining_call_sites_(NULL), | 481 inlining_call_sites_(NULL), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 // Abort if this function has deoptimized too much. | 607 // Abort if this function has deoptimized too much. |
587 if (function.deoptimization_counter() >= | 608 if (function.deoptimization_counter() >= |
588 FLAG_deoptimization_counter_threshold) { | 609 FLAG_deoptimization_counter_threshold) { |
589 function.set_is_inlinable(false); | 610 function.set_is_inlinable(false); |
590 TRACE_INLINING(OS::Print(" Bailout: deoptimization threshold\n")); | 611 TRACE_INLINING(OS::Print(" Bailout: deoptimization threshold\n")); |
591 PRINT_INLINING_TREE("Deoptimization threshold exceeded", | 612 PRINT_INLINING_TREE("Deoptimization threshold exceeded", |
592 &call_data->caller, &function, call_data->call); | 613 &call_data->caller, &function, call_data->call); |
593 return false; | 614 return false; |
594 } | 615 } |
595 | 616 |
| 617 const char* kNeverInlineAnnotation = "NeverInline"; |
| 618 if (FLAG_enable_inlining_annotations && |
| 619 HasAnnotation(function, kNeverInlineAnnotation)) { |
| 620 TRACE_INLINING(OS::Print(" Bailout: NeverInline annotation\n")); |
| 621 return false; |
| 622 } |
| 623 |
596 GrowableArray<Value*>* arguments = call_data->arguments; | 624 GrowableArray<Value*>* arguments = call_data->arguments; |
597 const intptr_t constant_arguments = CountConstants(*arguments); | 625 const intptr_t constant_arguments = CountConstants(*arguments); |
598 if (!ShouldWeInline(function, | 626 if (!ShouldWeInline(function, |
599 function.optimized_instruction_count(), | 627 function.optimized_instruction_count(), |
600 function.optimized_call_site_count(), | 628 function.optimized_call_site_count(), |
601 constant_arguments)) { | 629 constant_arguments)) { |
602 TRACE_INLINING(OS::Print(" Bailout: early heuristics with " | 630 TRACE_INLINING(OS::Print(" Bailout: early heuristics with " |
603 "code size: %" Pd ", " | 631 "code size: %" Pd ", " |
604 "call sites: %" Pd ", " | 632 "call sites: %" Pd ", " |
605 "const args: %" Pd "\n", | 633 "const args: %" Pd "\n", |
606 function.optimized_instruction_count(), | 634 function.optimized_instruction_count(), |
607 function.optimized_call_site_count(), | 635 function.optimized_call_site_count(), |
608 constant_arguments)); | 636 constant_arguments)); |
609 PRINT_INLINING_TREE("Early heuristic", | 637 PRINT_INLINING_TREE("Early heuristic", |
610 &call_data->caller, &function, call_data->call); | 638 &call_data->caller, &function, call_data->call); |
611 return false; | 639 return false; |
612 } | 640 } |
613 | 641 |
614 // Abort if this is a recursive occurrence. | 642 // Abort if this is a recursive occurrence. |
615 Definition* call = call_data->call; | 643 Definition* call = call_data->call; |
616 if (!FLAG_inline_recursive && IsCallRecursive(unoptimized_code, call)) { | 644 if (!FLAG_inline_recursive && IsCallRecursive(unoptimized_code, call)) { |
617 function.set_is_inlinable(false); | |
618 TRACE_INLINING(OS::Print(" Bailout: recursive function\n")); | 645 TRACE_INLINING(OS::Print(" Bailout: recursive function\n")); |
619 PRINT_INLINING_TREE("Recursive function", | 646 PRINT_INLINING_TREE("Recursive function", |
620 &call_data->caller, &function, call_data->call); | 647 &call_data->caller, &function, call_data->call); |
621 return false; | 648 return false; |
622 } | 649 } |
623 | 650 |
624 // Save and clear deopt id. | 651 // Save and clear deopt id. |
625 const intptr_t prev_deopt_id = isolate()->deopt_id(); | 652 const intptr_t prev_deopt_id = isolate()->deopt_id(); |
626 isolate()->set_deopt_id(0); | 653 isolate()->set_deopt_id(0); |
627 // Install bailout jump. | 654 // Install bailout jump. |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 info.Collect(*flow_graph); | 1705 info.Collect(*flow_graph); |
1679 | 1706 |
1680 function.set_optimized_instruction_count( | 1707 function.set_optimized_instruction_count( |
1681 ClampUint16(info.instruction_count())); | 1708 ClampUint16(info.instruction_count())); |
1682 function.set_optimized_call_site_count(ClampUint16(info.call_site_count())); | 1709 function.set_optimized_call_site_count(ClampUint16(info.call_site_count())); |
1683 } | 1710 } |
1684 } | 1711 } |
1685 | 1712 |
1686 | 1713 |
1687 bool FlowGraphInliner::AlwaysInline(const Function& function) { | 1714 bool FlowGraphInliner::AlwaysInline(const Function& function) { |
| 1715 const char* kAlwaysInlineAnnotation = "AlwaysInline"; |
| 1716 if (FLAG_enable_inlining_annotations && |
| 1717 HasAnnotation(function, kAlwaysInlineAnnotation)) { |
| 1718 TRACE_INLINING(OS::Print("AlwaysInline annotation for %s\n", |
| 1719 function.ToCString())); |
| 1720 return true; |
| 1721 } |
| 1722 |
1688 if (function.IsImplicitGetterFunction() || function.IsGetterFunction() || | 1723 if (function.IsImplicitGetterFunction() || function.IsGetterFunction() || |
1689 function.IsImplicitSetterFunction() || function.IsSetterFunction()) { | 1724 function.IsImplicitSetterFunction() || function.IsSetterFunction()) { |
1690 const intptr_t count = function.optimized_instruction_count(); | 1725 const intptr_t count = function.optimized_instruction_count(); |
1691 if ((count != 0) && (count < FLAG_inline_getters_setters_smaller_than)) { | 1726 if ((count != 0) && (count < FLAG_inline_getters_setters_smaller_than)) { |
1692 return true; | 1727 return true; |
1693 } | 1728 } |
1694 } | 1729 } |
1695 return MethodRecognizer::AlwaysInline(function); | 1730 return MethodRecognizer::AlwaysInline(function); |
1696 } | 1731 } |
1697 | 1732 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 OS::Print("After Inlining of %s\n", flow_graph_-> | 1766 OS::Print("After Inlining of %s\n", flow_graph_-> |
1732 parsed_function().function().ToFullyQualifiedCString()); | 1767 parsed_function().function().ToFullyQualifiedCString()); |
1733 FlowGraphPrinter printer(*flow_graph_); | 1768 FlowGraphPrinter printer(*flow_graph_); |
1734 printer.PrintBlocks(); | 1769 printer.PrintBlocks(); |
1735 } | 1770 } |
1736 } | 1771 } |
1737 } | 1772 } |
1738 } | 1773 } |
1739 | 1774 |
1740 } // namespace dart | 1775 } // namespace dart |
OLD | NEW |