| 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/compiler.h" | 7 #include "vm/compiler.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/flow_graph.h" | 9 #include "vm/flow_graph.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 error = isolate->object_store()->sticky_error(); | 595 error = isolate->object_store()->sticky_error(); |
| 596 isolate->object_store()->clear_sticky_error(); | 596 isolate->object_store()->clear_sticky_error(); |
| 597 isolate->set_long_jump_base(base); | 597 isolate->set_long_jump_base(base); |
| 598 isolate->set_deopt_id(prev_deopt_id); | 598 isolate->set_deopt_id(prev_deopt_id); |
| 599 isolate->set_ic_data_array(prev_ic_data.raw()); | 599 isolate->set_ic_data_array(prev_ic_data.raw()); |
| 600 TRACE_INLINING(OS::Print(" Bailout: %s\n", error.ToErrorCString())); | 600 TRACE_INLINING(OS::Print(" Bailout: %s\n", error.ToErrorCString())); |
| 601 return false; | 601 return false; |
| 602 } | 602 } |
| 603 } | 603 } |
| 604 | 604 |
| 605 void InlineCall(InlinedCallData* call_data) { | 605 void InlineCall(const InlinedCallData& call_data) { |
| 606 TimerScope timer(FLAG_compiler_stats, | 606 TimerScope timer(FLAG_compiler_stats, |
| 607 &CompilerStats::graphinliner_subst_timer, | 607 &CompilerStats::graphinliner_subst_timer, |
| 608 Isolate::Current()); | 608 Isolate::Current()); |
| 609 | 609 |
| 610 // Plug result in the caller graph. | 610 // Plug result in the caller graph. |
| 611 FlowGraph* callee_graph = call_data->callee_graph; | 611 FlowGraph* callee_graph = call_data.callee_graph; |
| 612 InlineExitCollector* exit_collector = call_data->exit_collector; | 612 InlineExitCollector* exit_collector = call_data.exit_collector; |
| 613 exit_collector->PrepareGraphs(callee_graph); | 613 exit_collector->PrepareGraphs(callee_graph); |
| 614 exit_collector->ReplaceCall(callee_graph->graph_entry()->normal_entry()); | 614 exit_collector->ReplaceCall(callee_graph->graph_entry()->normal_entry()); |
| 615 | 615 |
| 616 // Replace each stub with the actual argument or the caller's constant. | 616 // Replace each stub with the actual argument or the caller's constant. |
| 617 // Nulls denote optional parameters for which no actual was given. | 617 // Nulls denote optional parameters for which no actual was given. |
| 618 GrowableArray<Value*>* arguments = call_data->arguments; | 618 GrowableArray<Value*>* arguments = call_data.arguments; |
| 619 for (intptr_t i = 0; i < arguments->length(); ++i) { | 619 for (intptr_t i = 0; i < arguments->length(); ++i) { |
| 620 Definition* stub = (*call_data->parameter_stubs)[i]; | 620 Definition* stub = (*call_data.parameter_stubs)[i]; |
| 621 Value* actual = (*arguments)[i]; | 621 Value* actual = (*arguments)[i]; |
| 622 if (actual != NULL) stub->ReplaceUsesWith(actual->definition()); | 622 if (actual != NULL) stub->ReplaceUsesWith(actual->definition()); |
| 623 } | 623 } |
| 624 | 624 |
| 625 // Remove push arguments of the call. | 625 // Remove push arguments of the call. |
| 626 Definition* call = call_data->call; | 626 Definition* call = call_data.call; |
| 627 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { | 627 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { |
| 628 PushArgumentInstr* push = call->PushArgumentAt(i); | 628 PushArgumentInstr* push = call->PushArgumentAt(i); |
| 629 push->ReplaceUsesWith(push->value()->definition()); | 629 push->ReplaceUsesWith(push->value()->definition()); |
| 630 push->RemoveFromGraph(); | 630 push->RemoveFromGraph(); |
| 631 } | 631 } |
| 632 | 632 |
| 633 // Replace remaining constants with uses by constants in the caller's | 633 // Replace remaining constants with uses by constants in the caller's |
| 634 // initial definitions. | 634 // initial definitions. |
| 635 GrowableArray<Definition*>* defns = | 635 GrowableArray<Definition*>* defns = |
| 636 callee_graph->graph_entry()->initial_definitions(); | 636 callee_graph->graph_entry()->initial_definitions(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 // Do not inline since a non-constant argument was passed. | 694 // Do not inline since a non-constant argument was passed. |
| 695 continue; | 695 continue; |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 GrowableArray<Value*> arguments(call->ArgumentCount()); | 698 GrowableArray<Value*> arguments(call->ArgumentCount()); |
| 699 for (int i = 0; i < call->ArgumentCount(); ++i) { | 699 for (int i = 0; i < call->ArgumentCount(); ++i) { |
| 700 arguments.Add(call->PushArgumentAt(i)->value()); | 700 arguments.Add(call->PushArgumentAt(i)->value()); |
| 701 } | 701 } |
| 702 InlinedCallData call_data(call, &arguments); | 702 InlinedCallData call_data(call, &arguments); |
| 703 if (TryInlining(call->function(), call->argument_names(), &call_data)) { | 703 if (TryInlining(call->function(), call->argument_names(), &call_data)) { |
| 704 InlineCall(&call_data); | 704 InlineCall(call_data); |
| 705 } | 705 } |
| 706 } | 706 } |
| 707 } | 707 } |
| 708 | 708 |
| 709 void InlineClosureCalls() { | 709 void InlineClosureCalls() { |
| 710 const GrowableArray<ClosureCallInstr*>& calls = | 710 const GrowableArray<ClosureCallInstr*>& calls = |
| 711 inlining_call_sites_->closure_calls(); | 711 inlining_call_sites_->closure_calls(); |
| 712 TRACE_INLINING(OS::Print(" Closure Calls (%d)\n", calls.length())); | 712 TRACE_INLINING(OS::Print(" Closure Calls (%d)\n", calls.length())); |
| 713 for (intptr_t i = 0; i < calls.length(); ++i) { | 713 for (intptr_t i = 0; i < calls.length(); ++i) { |
| 714 ClosureCallInstr* call = calls[i]; | 714 ClosureCallInstr* call = calls[i]; |
| 715 // Find the closure of the callee. | 715 // Find the closure of the callee. |
| 716 ASSERT(call->ArgumentCount() > 0); | 716 ASSERT(call->ArgumentCount() > 0); |
| 717 const CreateClosureInstr* closure = | 717 const CreateClosureInstr* closure = |
| 718 call->ArgumentAt(0)->AsCreateClosure(); | 718 call->ArgumentAt(0)->AsCreateClosure(); |
| 719 if (closure == NULL) { | 719 if (closure == NULL) { |
| 720 TRACE_INLINING(OS::Print(" Bailout: non-closure operator\n")); | 720 TRACE_INLINING(OS::Print(" Bailout: non-closure operator\n")); |
| 721 continue; | 721 continue; |
| 722 } | 722 } |
| 723 GrowableArray<Value*> arguments(call->ArgumentCount()); | 723 GrowableArray<Value*> arguments(call->ArgumentCount()); |
| 724 for (int i = 0; i < call->ArgumentCount(); ++i) { | 724 for (int i = 0; i < call->ArgumentCount(); ++i) { |
| 725 arguments.Add(call->PushArgumentAt(i)->value()); | 725 arguments.Add(call->PushArgumentAt(i)->value()); |
| 726 } | 726 } |
| 727 InlinedCallData call_data(call, &arguments); | 727 InlinedCallData call_data(call, &arguments); |
| 728 if (TryInlining(closure->function(), | 728 if (TryInlining(closure->function(), |
| 729 call->argument_names(), | 729 call->argument_names(), |
| 730 &call_data)) { | 730 &call_data)) { |
| 731 InlineCall(&call_data); | 731 InlineCall(call_data); |
| 732 } | 732 } |
| 733 } | 733 } |
| 734 } | 734 } |
| 735 | 735 |
| 736 void InlineInstanceCalls() { | 736 void InlineInstanceCalls() { |
| 737 const GrowableArray<CallSites::InstanceCallInfo>& call_info = | 737 const GrowableArray<CallSites::InstanceCallInfo>& call_info = |
| 738 inlining_call_sites_->instance_calls(); | 738 inlining_call_sites_->instance_calls(); |
| 739 TRACE_INLINING(OS::Print(" Polymorphic Instance Calls (%d)\n", | 739 TRACE_INLINING(OS::Print(" Polymorphic Instance Calls (%d)\n", |
| 740 call_info.length())); | 740 call_info.length())); |
| 741 for (intptr_t i = 0; i < call_info.length(); ++i) { | 741 for (intptr_t i = 0; i < call_info.length(); ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 759 continue; | 759 continue; |
| 760 } | 760 } |
| 761 GrowableArray<Value*> arguments(call->ArgumentCount()); | 761 GrowableArray<Value*> arguments(call->ArgumentCount()); |
| 762 for (int arg_i = 0; arg_i < call->ArgumentCount(); ++arg_i) { | 762 for (int arg_i = 0; arg_i < call->ArgumentCount(); ++arg_i) { |
| 763 arguments.Add(call->PushArgumentAt(arg_i)->value()); | 763 arguments.Add(call->PushArgumentAt(arg_i)->value()); |
| 764 } | 764 } |
| 765 InlinedCallData call_data(call, &arguments); | 765 InlinedCallData call_data(call, &arguments); |
| 766 if (TryInlining(target, | 766 if (TryInlining(target, |
| 767 call->instance_call()->argument_names(), | 767 call->instance_call()->argument_names(), |
| 768 &call_data)) { | 768 &call_data)) { |
| 769 InlineCall(&call_data); | 769 InlineCall(call_data); |
| 770 } | 770 } |
| 771 } | 771 } |
| 772 } | 772 } |
| 773 | 773 |
| 774 void AdjustForOptionalParameters(const ParsedFunction& parsed_function, | 774 void AdjustForOptionalParameters(const ParsedFunction& parsed_function, |
| 775 const Array& argument_names, | 775 const Array& argument_names, |
| 776 GrowableArray<Value*>* arguments, | 776 GrowableArray<Value*>* arguments, |
| 777 ZoneGrowableArray<Definition*>* param_stubs, | 777 ZoneGrowableArray<Definition*>* param_stubs, |
| 778 FlowGraph* callee_graph) { | 778 FlowGraph* callee_graph) { |
| 779 const Function& function = parsed_function.function(); | 779 const Function& function = parsed_function.function(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 OS::Print("After Inlining of %s\n", flow_graph_-> | 921 OS::Print("After Inlining of %s\n", flow_graph_-> |
| 922 parsed_function().function().ToFullyQualifiedCString()); | 922 parsed_function().function().ToFullyQualifiedCString()); |
| 923 FlowGraphPrinter printer(*flow_graph_); | 923 FlowGraphPrinter printer(*flow_graph_); |
| 924 printer.PrintBlocks(); | 924 printer.PrintBlocks(); |
| 925 } | 925 } |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 | 929 |
| 930 } // namespace dart | 930 } // namespace dart |
| OLD | NEW |