| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 GrowableArray<intptr_t> skip_static_call_deopt_ids_; | 255 GrowableArray<intptr_t> skip_static_call_deopt_ids_; |
| 256 | 256 |
| 257 DISALLOW_COPY_AND_ASSIGN(CallSites); | 257 DISALLOW_COPY_AND_ASSIGN(CallSites); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 | 260 |
| 261 class CallSiteInliner : public ValueObject { | 261 class CallSiteInliner : public ValueObject { |
| 262 public: | 262 public: |
| 263 explicit CallSiteInliner(FlowGraph* flow_graph) | 263 explicit CallSiteInliner(FlowGraph* flow_graph) |
| 264 : caller_graph_(flow_graph), | 264 : caller_graph_(flow_graph), |
| 265 next_ssa_temp_index_(flow_graph->max_virtual_register_number()), | |
| 266 inlined_(false), | 265 inlined_(false), |
| 267 initial_size_(flow_graph->InstructionCount()), | 266 initial_size_(flow_graph->InstructionCount()), |
| 268 inlined_size_(0), | 267 inlined_size_(0), |
| 269 inlining_depth_(1), | 268 inlining_depth_(1), |
| 270 collected_call_sites_(NULL), | 269 collected_call_sites_(NULL), |
| 271 inlining_call_sites_(NULL), | 270 inlining_call_sites_(NULL), |
| 272 function_cache_() { } | 271 function_cache_() { } |
| 273 | 272 |
| 274 // Inlining heuristics based on Cooper et al. 2008. | 273 // Inlining heuristics based on Cooper et al. 2008. |
| 275 bool ShouldWeInline(intptr_t loop_depth, | 274 bool ShouldWeInline(intptr_t loop_depth, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 443 |
| 445 // After treating optional parameters the actual/formal count must match. | 444 // After treating optional parameters the actual/formal count must match. |
| 446 ASSERT(arguments->length() == function.NumParameters()); | 445 ASSERT(arguments->length() == function.NumParameters()); |
| 447 ASSERT(param_stubs.length() == callee_graph->parameter_count()); | 446 ASSERT(param_stubs.length() == callee_graph->parameter_count()); |
| 448 | 447 |
| 449 { | 448 { |
| 450 TimerScope timer(FLAG_compiler_stats, | 449 TimerScope timer(FLAG_compiler_stats, |
| 451 &CompilerStats::graphinliner_ssa_timer, | 450 &CompilerStats::graphinliner_ssa_timer, |
| 452 isolate); | 451 isolate); |
| 453 // Compute SSA on the callee graph, catching bailouts. | 452 // Compute SSA on the callee graph, catching bailouts. |
| 454 callee_graph->ComputeSSA(next_ssa_temp_index_, ¶m_stubs); | 453 callee_graph->ComputeSSA(caller_graph_->max_virtual_register_number(), |
| 454 ¶m_stubs); |
| 455 callee_graph->ComputeUseLists(); | 455 callee_graph->ComputeUseLists(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 { | 458 { |
| 459 TimerScope timer(FLAG_compiler_stats, | 459 TimerScope timer(FLAG_compiler_stats, |
| 460 &CompilerStats::graphinliner_opt_timer, | 460 &CompilerStats::graphinliner_opt_timer, |
| 461 isolate); | 461 isolate); |
| 462 // TODO(zerny): Do more optimization passes on the callee graph. | 462 // TODO(zerny): Do more optimization passes on the callee graph. |
| 463 FlowGraphOptimizer optimizer(callee_graph); | 463 FlowGraphOptimizer optimizer(callee_graph); |
| 464 optimizer.ApplyICData(); | 464 optimizer.ApplyICData(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 collected_call_sites_->FindCallSites(callee_graph); | 513 collected_call_sites_->FindCallSites(callee_graph); |
| 514 } | 514 } |
| 515 | 515 |
| 516 { | 516 { |
| 517 TimerScope timer(FLAG_compiler_stats, | 517 TimerScope timer(FLAG_compiler_stats, |
| 518 &CompilerStats::graphinliner_subst_timer, | 518 &CompilerStats::graphinliner_subst_timer, |
| 519 isolate); | 519 isolate); |
| 520 | 520 |
| 521 // Plug result in the caller graph. | 521 // Plug result in the caller graph. |
| 522 caller_graph_->InlineCall(call, callee_graph); | 522 caller_graph_->InlineCall(call, callee_graph); |
| 523 next_ssa_temp_index_ = caller_graph_->max_virtual_register_number(); | |
| 524 | 523 |
| 525 // Remove push arguments of the call. | 524 // Remove push arguments of the call. |
| 526 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { | 525 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { |
| 527 PushArgumentInstr* push = call->ArgumentAt(i); | 526 PushArgumentInstr* push = call->ArgumentAt(i); |
| 528 push->ReplaceUsesWith(push->value()->definition()); | 527 push->ReplaceUsesWith(push->value()->definition()); |
| 529 push->RemoveFromGraph(); | 528 push->RemoveFromGraph(); |
| 530 } | 529 } |
| 531 | 530 |
| 532 // Replace each stub with the actual argument or the caller's constant. | 531 // Replace each stub with the actual argument or the caller's constant. |
| 533 // Nulls denote optional parameters for which no actual was given. | 532 // Nulls denote optional parameters for which no actual was given. |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 param_stubs->Add(CreateParameterStub(i, arg, callee_graph)); | 749 param_stubs->Add(CreateParameterStub(i, arg, callee_graph)); |
| 751 } else { | 750 } else { |
| 752 param_stubs->Add( | 751 param_stubs->Add( |
| 753 GetDefaultValue(i - fixed_param_count, parsed_function)); | 752 GetDefaultValue(i - fixed_param_count, parsed_function)); |
| 754 } | 753 } |
| 755 } | 754 } |
| 756 } | 755 } |
| 757 | 756 |
| 758 | 757 |
| 759 FlowGraph* caller_graph_; | 758 FlowGraph* caller_graph_; |
| 760 intptr_t next_ssa_temp_index_; | |
| 761 bool inlined_; | 759 bool inlined_; |
| 762 intptr_t initial_size_; | 760 intptr_t initial_size_; |
| 763 intptr_t inlined_size_; | 761 intptr_t inlined_size_; |
| 764 intptr_t inlining_depth_; | 762 intptr_t inlining_depth_; |
| 765 CallSites* collected_call_sites_; | 763 CallSites* collected_call_sites_; |
| 766 CallSites* inlining_call_sites_; | 764 CallSites* inlining_call_sites_; |
| 767 GrowableArray<ParsedFunction*> function_cache_; | 765 GrowableArray<ParsedFunction*> function_cache_; |
| 768 | 766 |
| 769 DISALLOW_COPY_AND_ASSIGN(CallSiteInliner); | 767 DISALLOW_COPY_AND_ASSIGN(CallSiteInliner); |
| 770 }; | 768 }; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 800 OS::Print("After Inlining of %s\n", flow_graph_-> | 798 OS::Print("After Inlining of %s\n", flow_graph_-> |
| 801 parsed_function().function().ToFullyQualifiedCString()); | 799 parsed_function().function().ToFullyQualifiedCString()); |
| 802 FlowGraphPrinter printer(*flow_graph_); | 800 FlowGraphPrinter printer(*flow_graph_); |
| 803 printer.PrintBlocks(); | 801 printer.PrintBlocks(); |
| 804 } | 802 } |
| 805 } | 803 } |
| 806 } | 804 } |
| 807 } | 805 } |
| 808 | 806 |
| 809 } // namespace dart | 807 } // namespace dart |
| OLD | NEW |