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/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/flow_graph.h" | 8 #include "vm/flow_graph.h" |
9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class CallSiteInliner : public FlowGraphVisitor { | 21 class CallSiteInliner : public FlowGraphVisitor { |
22 public: | 22 public: |
23 explicit CallSiteInliner(FlowGraph* flow_graph) | 23 explicit CallSiteInliner(FlowGraph* flow_graph) |
24 : FlowGraphVisitor(flow_graph->postorder()), | 24 : FlowGraphVisitor(flow_graph->postorder()), |
25 caller_graph_(flow_graph), | 25 caller_graph_(flow_graph), |
26 next_ssa_temp_index_(flow_graph->max_virtual_register_number()), | 26 next_ssa_temp_index_(flow_graph->max_virtual_register_number()), |
27 inlined_(false) { } | 27 inlined_(false) { } |
28 | 28 |
29 void TryInlining(const Function& function, | 29 void TryInlining(const Function& function, |
30 GrowableArray<Value*>* arguments, | 30 GrowableArray<Value*>* arguments, |
31 StaticCallComp* comp, // TODO(zerny): Generalize to calls. | 31 StaticCallInstr* call) { |
32 BindInstr* instr) { | 32 // TODO(zerny): Generalize to all calls. |
| 33 |
33 // Abort if the callee has named parameters. | 34 // Abort if the callee has named parameters. |
34 if (function.num_optional_parameters() > 0) { | 35 if (function.num_optional_parameters() > 0) { |
35 if (FLAG_trace_inlining) { | 36 if (FLAG_trace_inlining) { |
36 OS::Print("Inline aborted %s\nReason: optional parameters\n", | 37 OS::Print("Inline aborted %s\nReason: optional parameters\n", |
37 function.ToFullyQualifiedCString()); | 38 function.ToFullyQualifiedCString()); |
38 } | 39 } |
39 return; | 40 return; |
40 } | 41 } |
41 | 42 |
42 // Assuming no optional parameters the actual/formal count should match. | 43 // Assuming no optional parameters the actual/formal count should match. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 callee_graph->ComputeUseLists(); | 92 callee_graph->ComputeUseLists(); |
92 | 93 |
93 // TODO(zerny): Do optimization passes on the callee graph. | 94 // TODO(zerny): Do optimization passes on the callee graph. |
94 | 95 |
95 // TODO(zerny): If result is more than size threshold then abort. | 96 // TODO(zerny): If result is more than size threshold then abort. |
96 | 97 |
97 // TODO(zerny): If effort is less than threshold then inline recursively. | 98 // TODO(zerny): If effort is less than threshold then inline recursively. |
98 | 99 |
99 // Plug result in the caller graph. | 100 // Plug result in the caller graph. |
100 caller_graph_->InlineCall(instr, comp, callee_graph); | 101 caller_graph_->InlineCall(call, callee_graph); |
101 next_ssa_temp_index_ = caller_graph_->max_virtual_register_number(); | 102 next_ssa_temp_index_ = caller_graph_->max_virtual_register_number(); |
102 | 103 |
103 // Replace all the formal parameters with the actuals. | 104 // Replace all the formal parameters with the actuals. |
104 for (intptr_t i = 0; i < arguments->length(); ++i) { | 105 for (intptr_t i = 0; i < arguments->length(); ++i) { |
105 Value* val = callee_graph->graph_entry()->start_env()->values()[i]; | 106 Value* val = callee_graph->graph_entry()->start_env()->values()[i]; |
106 ParameterInstr* param = val->definition()->AsParameter(); | 107 ParameterInstr* param = val->definition()->AsParameter(); |
107 ASSERT(param != NULL); | 108 ASSERT(param != NULL); |
108 param->ReplaceUsesWith((*arguments)[i]->definition()); | 109 param->ReplaceUsesWith((*arguments)[i]->definition()); |
109 } | 110 } |
110 | 111 |
(...skipping 12 matching lines...) Expand all Loading... |
123 isolate->set_long_jump_base(base); | 124 isolate->set_long_jump_base(base); |
124 isolate->set_ic_data_array(old_ic_data.raw()); | 125 isolate->set_ic_data_array(old_ic_data.raw()); |
125 if (FLAG_trace_inlining) { | 126 if (FLAG_trace_inlining) { |
126 OS::Print("Inline aborted for %s\nReason: %s\n", | 127 OS::Print("Inline aborted for %s\nReason: %s\n", |
127 function.ToFullyQualifiedCString(), | 128 function.ToFullyQualifiedCString(), |
128 error.ToErrorCString()); | 129 error.ToErrorCString()); |
129 } | 130 } |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 void VisitBind(BindInstr* instr) { | 134 void VisitStaticCall(StaticCallInstr* instr) { |
134 instr->computation()->Accept(this, instr); | |
135 } | |
136 | |
137 void VisitStaticCall(StaticCallComp* comp, BindInstr* instr) { | |
138 if (FLAG_trace_inlining) OS::Print("Static call\n"); | 135 if (FLAG_trace_inlining) OS::Print("Static call\n"); |
139 GrowableArray<Value*> arguments(comp->ArgumentCount()); | 136 GrowableArray<Value*> arguments(instr->ArgumentCount()); |
140 for (int i = 0; i < comp->ArgumentCount(); ++i) { | 137 for (int i = 0; i < instr->ArgumentCount(); ++i) { |
141 arguments.Add(comp->ArgumentAt(i)->value()); | 138 arguments.Add(instr->ArgumentAt(i)->value()); |
142 } | 139 } |
143 TryInlining(comp->function(), &arguments, comp, instr); | 140 TryInlining(instr->function(), &arguments, instr); |
144 } | 141 } |
145 | 142 |
146 bool preformed_inlining() const { return inlined_; } | 143 bool preformed_inlining() const { return inlined_; } |
147 | 144 |
148 private: | 145 private: |
149 FlowGraph* caller_graph_; | 146 FlowGraph* caller_graph_; |
150 intptr_t next_ssa_temp_index_; | 147 intptr_t next_ssa_temp_index_; |
151 bool inlined_; | 148 bool inlined_; |
152 }; | 149 }; |
153 | 150 |
(...skipping 20 matching lines...) Expand all Loading... |
174 if (FLAG_trace_inlining && FLAG_print_flow_graph) { | 171 if (FLAG_trace_inlining && FLAG_print_flow_graph) { |
175 OS::Print("After Inlining of %s\n", flow_graph_-> | 172 OS::Print("After Inlining of %s\n", flow_graph_-> |
176 parsed_function().function().ToFullyQualifiedCString()); | 173 parsed_function().function().ToFullyQualifiedCString()); |
177 FlowGraphPrinter printer(*flow_graph_); | 174 FlowGraphPrinter printer(*flow_graph_); |
178 printer.PrintBlocks(); | 175 printer.PrintBlocks(); |
179 } | 176 } |
180 } | 177 } |
181 } | 178 } |
182 | 179 |
183 } // namespace dart | 180 } // namespace dart |
OLD | NEW |