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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 // Save and clear deopt id. | 674 // Save and clear deopt id. |
675 const intptr_t prev_deopt_id = isolate()->deopt_id(); | 675 const intptr_t prev_deopt_id = isolate()->deopt_id(); |
676 isolate()->set_deopt_id(0); | 676 isolate()->set_deopt_id(0); |
677 // Install bailout jump. | 677 // Install bailout jump. |
678 LongJumpScope jump; | 678 LongJumpScope jump; |
679 if (setjmp(*jump.Set()) == 0) { | 679 if (setjmp(*jump.Set()) == 0) { |
680 // Parse the callee function. | 680 // Parse the callee function. |
681 bool in_cache; | 681 bool in_cache; |
682 ParsedFunction* parsed_function; | 682 ParsedFunction* parsed_function; |
683 { | 683 { |
684 TimerScope timer(FLAG_compiler_stats, | 684 CSTAT_TIMER_SCOPE(isolate(), graphinliner_parse_timer); |
685 &CompilerStats::graphinliner_parse_timer, | |
686 isolate()); | |
687 const Error& error = Error::Handle(Z, | 685 const Error& error = Error::Handle(Z, |
688 Compiler::EnsureUnoptimizedCode(Thread::Current(), function)); | 686 Compiler::EnsureUnoptimizedCode(Thread::Current(), function)); |
689 if (!error.IsNull()) { | 687 if (!error.IsNull()) { |
690 Exceptions::PropagateError(error); | 688 Exceptions::PropagateError(error); |
691 } | 689 } |
692 parsed_function = GetParsedFunction(function, &in_cache); | 690 parsed_function = GetParsedFunction(function, &in_cache); |
693 } | 691 } |
694 | 692 |
695 // Load IC data for the callee. | 693 // Load IC data for the callee. |
696 ZoneGrowableArray<const ICData*>* ic_data_array = | 694 ZoneGrowableArray<const ICData*>* ic_data_array = |
697 new(Z) ZoneGrowableArray<const ICData*>(); | 695 new(Z) ZoneGrowableArray<const ICData*>(); |
698 function.RestoreICDataMap(ic_data_array); | 696 function.RestoreICDataMap(ic_data_array); |
699 | 697 |
700 // Build the callee graph. | 698 // Build the callee graph. |
701 InlineExitCollector* exit_collector = | 699 InlineExitCollector* exit_collector = |
702 new(Z) InlineExitCollector(caller_graph_, call); | 700 new(Z) InlineExitCollector(caller_graph_, call); |
703 FlowGraphBuilder builder(*parsed_function, | 701 FlowGraphBuilder builder(*parsed_function, |
704 *ic_data_array, | 702 *ic_data_array, |
705 exit_collector, | 703 exit_collector, |
706 Isolate::kNoDeoptId); | 704 Isolate::kNoDeoptId); |
707 builder.SetInitialBlockId(caller_graph_->max_block_id()); | 705 builder.SetInitialBlockId(caller_graph_->max_block_id()); |
708 FlowGraph* callee_graph; | 706 FlowGraph* callee_graph; |
709 { | 707 { |
710 TimerScope timer(FLAG_compiler_stats, | 708 CSTAT_TIMER_SCOPE(isolate(), graphinliner_build_timer); |
711 &CompilerStats::graphinliner_build_timer, | |
712 isolate()); | |
713 callee_graph = builder.BuildGraph(); | 709 callee_graph = builder.BuildGraph(); |
714 } | 710 } |
715 | 711 |
716 // The parameter stubs are a copy of the actual arguments providing | 712 // The parameter stubs are a copy of the actual arguments providing |
717 // concrete information about the values, for example constant values, | 713 // concrete information about the values, for example constant values, |
718 // without linking between the caller and callee graphs. | 714 // without linking between the caller and callee graphs. |
719 // TODO(zerny): Put more information in the stubs, eg, type information. | 715 // TODO(zerny): Put more information in the stubs, eg, type information. |
720 ZoneGrowableArray<Definition*>* param_stubs = | 716 ZoneGrowableArray<Definition*>* param_stubs = |
721 new(Z) ZoneGrowableArray<Definition*>( | 717 new(Z) ZoneGrowableArray<Definition*>( |
722 function.NumParameters()); | 718 function.NumParameters()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 !it.Done(); it.Advance()) { | 752 !it.Done(); it.Advance()) { |
757 BlockEntryInstr* block = it.Current(); | 753 BlockEntryInstr* block = it.Current(); |
758 block->set_try_index(try_index); | 754 block->set_try_index(try_index); |
759 } | 755 } |
760 } | 756 } |
761 | 757 |
762 BlockScheduler block_scheduler(callee_graph); | 758 BlockScheduler block_scheduler(callee_graph); |
763 block_scheduler.AssignEdgeWeights(); | 759 block_scheduler.AssignEdgeWeights(); |
764 | 760 |
765 { | 761 { |
766 TimerScope timer(FLAG_compiler_stats, | 762 CSTAT_TIMER_SCOPE(isolate(), graphinliner_ssa_timer); |
767 &CompilerStats::graphinliner_ssa_timer, | |
768 isolate()); | |
769 // Compute SSA on the callee graph, catching bailouts. | 763 // Compute SSA on the callee graph, catching bailouts. |
770 callee_graph->ComputeSSA(caller_graph_->max_virtual_register_number(), | 764 callee_graph->ComputeSSA(caller_graph_->max_virtual_register_number(), |
771 param_stubs); | 765 param_stubs); |
772 DEBUG_ASSERT(callee_graph->VerifyUseLists()); | 766 DEBUG_ASSERT(callee_graph->VerifyUseLists()); |
773 } | 767 } |
774 | 768 |
775 { | 769 { |
776 TimerScope timer(FLAG_compiler_stats, | 770 CSTAT_TIMER_SCOPE(isolate(), graphinliner_opt_timer); |
777 &CompilerStats::graphinliner_opt_timer, | |
778 isolate()); | |
779 // TODO(zerny): Do more optimization passes on the callee graph. | 771 // TODO(zerny): Do more optimization passes on the callee graph. |
780 FlowGraphOptimizer optimizer(callee_graph); | 772 FlowGraphOptimizer optimizer(callee_graph); |
781 optimizer.ApplyICData(); | 773 optimizer.ApplyICData(); |
782 DEBUG_ASSERT(callee_graph->VerifyUseLists()); | 774 DEBUG_ASSERT(callee_graph->VerifyUseLists()); |
783 | 775 |
784 // Optimize (a << b) & c patterns, merge instructions. Must occur before | 776 // Optimize (a << b) & c patterns, merge instructions. Must occur before |
785 // 'SelectRepresentations' which inserts conversion nodes. | 777 // 'SelectRepresentations' which inserts conversion nodes. |
786 optimizer.TryOptimizePatterns(); | 778 optimizer.TryOptimizePatterns(); |
787 DEBUG_ASSERT(callee_graph->VerifyUseLists()); | 779 DEBUG_ASSERT(callee_graph->VerifyUseLists()); |
788 } | 780 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 ISL_Print("NO %" Pd " %s - %s\n", | 938 ISL_Print("NO %" Pd " %s - %s\n", |
947 info.call_instr->GetDeoptId(), | 939 info.call_instr->GetDeoptId(), |
948 info.inlined->ToQualifiedCString(), | 940 info.inlined->ToQualifiedCString(), |
949 info.bailout_reason); | 941 info.bailout_reason); |
950 call_instructions_printed.Add(info.call_instr->GetDeoptId()); | 942 call_instructions_printed.Add(info.call_instr->GetDeoptId()); |
951 } | 943 } |
952 } | 944 } |
953 } | 945 } |
954 | 946 |
955 void InlineCall(InlinedCallData* call_data) { | 947 void InlineCall(InlinedCallData* call_data) { |
956 TimerScope timer(FLAG_compiler_stats, | 948 CSTAT_TIMER_SCOPE(Isolate::Current(), graphinliner_subst_timer); |
957 &CompilerStats::graphinliner_subst_timer, | |
958 Isolate::Current()); | |
959 FlowGraph* callee_graph = call_data->callee_graph; | 949 FlowGraph* callee_graph = call_data->callee_graph; |
960 TargetEntryInstr* callee_entry = | 950 TargetEntryInstr* callee_entry = |
961 callee_graph->graph_entry()->normal_entry(); | 951 callee_graph->graph_entry()->normal_entry(); |
962 // Plug result in the caller graph. | 952 // Plug result in the caller graph. |
963 InlineExitCollector* exit_collector = call_data->exit_collector; | 953 InlineExitCollector* exit_collector = call_data->exit_collector; |
964 exit_collector->PrepareGraphs(callee_graph); | 954 exit_collector->PrepareGraphs(callee_graph); |
965 exit_collector->ReplaceCall(callee_entry); | 955 exit_collector->ReplaceCall(callee_entry); |
966 | 956 |
967 // Replace each stub with the actual argument or the caller's constant. | 957 // Replace each stub with the actual argument or the caller's constant. |
968 // Nulls denote optional parameters for which no actual was given. | 958 // Nulls denote optional parameters for which no actual was given. |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 intptr_t FlowGraphInliner::NextInlineId(const Function& function, | 1870 intptr_t FlowGraphInliner::NextInlineId(const Function& function, |
1881 intptr_t parent_id) { | 1871 intptr_t parent_id) { |
1882 const intptr_t id = inline_id_to_function_->length(); | 1872 const intptr_t id = inline_id_to_function_->length(); |
1883 inline_id_to_function_->Add(&function); | 1873 inline_id_to_function_->Add(&function); |
1884 caller_inline_id_->Add(parent_id); | 1874 caller_inline_id_->Add(parent_id); |
1885 return id; | 1875 return id; |
1886 } | 1876 } |
1887 | 1877 |
1888 | 1878 |
1889 } // namespace dart | 1879 } // namespace dart |
OLD | NEW |