| 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.h" | 5 #include "vm/flow_graph.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 // Helper to link two instructions in the graph. | 746 // Helper to link two instructions in the graph. |
| 747 static void Link(Instruction* prev, Instruction* next) { | 747 static void Link(Instruction* prev, Instruction* next) { |
| 748 ASSERT(prev != next); | 748 ASSERT(prev != next); |
| 749 prev->set_next(next); | 749 prev->set_next(next); |
| 750 next->set_previous(prev); | 750 next->set_previous(prev); |
| 751 } | 751 } |
| 752 | 752 |
| 753 | 753 |
| 754 // Inline a flow graph at a call site. | 754 // Inline a flow graph at a call site. |
| 755 // | 755 // |
| 756 // Assumes the callee graph was computed with BuildGraphForInlining and | 756 // Assumes the callee graph was computed by BuildGraph with an inlining context |
| 757 // transformed to SSA with ComputeSSAForInlining, and that the use lists have | 757 // and transformed to SSA with ComputeSSA with a correct virtual register |
| 758 // been correctly computed. | 758 // number, and that the use lists have been correctly computed. |
| 759 // | 759 // |
| 760 // After inlining the caller graph will correctly have adjusted the pre/post | 760 // After inlining the caller graph will correctly have adjusted the pre/post |
| 761 // orders, the dominator tree and the use lists. | 761 // orders, the dominator tree and the use lists. |
| 762 void FlowGraph::InlineCall(StaticCallInstr* call, FlowGraph* callee_graph) { | 762 void FlowGraph::InlineCall(Definition* call, FlowGraph* callee_graph) { |
| 763 ASSERT(callee_graph->exits() != NULL); | 763 ASSERT(callee_graph->exits() != NULL); |
| 764 ASSERT(callee_graph->graph_entry()->SuccessorCount() == 1); | 764 ASSERT(callee_graph->graph_entry()->SuccessorCount() == 1); |
| 765 ASSERT(callee_graph->max_virtual_register_number() > | 765 ASSERT(callee_graph->max_virtual_register_number() > |
| 766 max_virtual_register_number()); | 766 max_virtual_register_number()); |
| 767 | 767 |
| 768 // TODO(zerny): Implement support for callee graphs with control flow. | 768 // TODO(zerny): Implement support for callee graphs with control flow. |
| 769 ASSERT(callee_graph->preorder().length() == 2); | 769 ASSERT(callee_graph->preorder().length() == 2); |
| 770 | 770 |
| 771 // Adjust the SSA temp index by the callee graph's index. | 771 // Adjust the SSA temp index by the callee graph's index. |
| 772 current_ssa_temp_index_ = callee_graph->max_virtual_register_number(); | 772 current_ssa_temp_index_ = callee_graph->max_virtual_register_number(); |
| 773 | 773 |
| 774 BlockEntryInstr* caller_entry = GetBlockEntry(call); |
| 774 TargetEntryInstr* callee_entry = callee_graph->graph_entry()->normal_entry(); | 775 TargetEntryInstr* callee_entry = callee_graph->graph_entry()->normal_entry(); |
| 775 ZoneGrowableArray<ReturnInstr*>* callee_exits = callee_graph->exits(); | 776 ZoneGrowableArray<ReturnInstr*>* callee_exits = callee_graph->exits(); |
| 776 | 777 |
| 777 // 1. Insert the callee graph into the caller graph. | 778 // 1. Insert the callee graph into the caller graph. |
| 778 if (callee_exits->length() == 1) { | 779 if (callee_exits->length() == 0) { |
| 780 // If no normal exits exist, inline and truncate the block after inlining. |
| 781 Link(call->previous(), callee_entry->next()); |
| 782 caller_entry->set_last_instruction(callee_entry->last_instruction()); |
| 783 } else if (callee_exits->length() == 1) { |
| 779 ReturnInstr* exit = (*callee_exits)[0]; | 784 ReturnInstr* exit = (*callee_exits)[0]; |
| 780 // TODO(zerny): Support one exit graph containing control flow. | 785 // TODO(zerny): Support one exit graph containing control flow. |
| 781 ASSERT(callee_entry == GetBlockEntry(exit)); | 786 ASSERT(callee_entry == GetBlockEntry(exit)); |
| 782 // For just one exit, replace the uses and remove the call from the graph. | 787 // For just one exit, replace the uses and remove the call from the graph. |
| 783 call->ReplaceUsesWith(exit->value()->definition()); | 788 call->ReplaceUsesWith(exit->value()->definition()); |
| 784 Link(call->previous(), callee_entry->next()); | 789 Link(call->previous(), callee_entry->next()); |
| 785 Link(exit->previous(), call->next()); | 790 Link(exit->previous(), call->next()); |
| 786 } else { | 791 } else { |
| 787 // TODO(zerny): Support multiple exits. | 792 // TODO(zerny): Support multiple exits. |
| 788 UNREACHABLE(); | 793 UNREACHABLE(); |
| 789 } | 794 } |
| 790 | 795 |
| 791 // TODO(zerny): Adjust pre/post orders. | 796 // TODO(zerny): Adjust pre/post orders. |
| 792 // TODO(zerny): Update dominator tree. | 797 // TODO(zerny): Update dominator tree. |
| 793 | |
| 794 // Remove original arguments to the call. | |
| 795 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { | |
| 796 PushArgumentInstr* push = call->ArgumentAt(i); | |
| 797 push->ReplaceUsesWith(push->value()->definition()); | |
| 798 push->RemoveFromGraph(); | |
| 799 } | |
| 800 } | 798 } |
| 801 | 799 |
| 802 | 800 |
| 803 } // namespace dart | 801 } // namespace dart |
| OLD | NEW |