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