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/block_scheduler.h" | 7 #include "vm/block_scheduler.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/flow_graph.h" | 10 #include "vm/flow_graph.h" |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 // Replace remaining constants with uses by constants in the caller's | 919 // Replace remaining constants with uses by constants in the caller's |
920 // initial definitions. | 920 // initial definitions. |
921 GrowableArray<Definition*>* defns = | 921 GrowableArray<Definition*>* defns = |
922 callee_graph->graph_entry()->initial_definitions(); | 922 callee_graph->graph_entry()->initial_definitions(); |
923 for (intptr_t i = 0; i < defns->length(); ++i) { | 923 for (intptr_t i = 0; i < defns->length(); ++i) { |
924 ConstantInstr* constant = (*defns)[i]->AsConstant(); | 924 ConstantInstr* constant = (*defns)[i]->AsConstant(); |
925 if ((constant != NULL) && constant->HasUses()) { | 925 if ((constant != NULL) && constant->HasUses()) { |
926 constant->ReplaceUsesWith( | 926 constant->ReplaceUsesWith( |
927 caller_graph_->GetConstant(constant->value())); | 927 caller_graph_->GetConstant(constant->value())); |
928 } | 928 } |
| 929 CurrentContextInstr* context = (*defns)[i]->AsCurrentContext(); |
| 930 if ((context != NULL) && context->HasUses()) { |
| 931 ASSERT(call->IsClosureCall()); |
| 932 LoadFieldInstr* context_load = new(isolate()) LoadFieldInstr( |
| 933 new Value((*arguments)[0]->definition()), |
| 934 Closure::context_offset(), |
| 935 AbstractType::ZoneHandle(isolate(), AbstractType::null()), |
| 936 call_data->call->token_pos()); |
| 937 context_load->set_is_immutable(true); |
| 938 context_load->set_ssa_temp_index( |
| 939 caller_graph_->alloc_ssa_temp_index()); |
| 940 context_load->InsertBefore(callee_entry->next()); |
| 941 context->ReplaceUsesWith(context_load); |
| 942 } |
929 } | 943 } |
930 | 944 |
931 // Check that inlining maintains use lists. | 945 // Check that inlining maintains use lists. |
932 DEBUG_ASSERT(!FLAG_verify_compiler || caller_graph_->VerifyUseLists()); | 946 DEBUG_ASSERT(!FLAG_verify_compiler || caller_graph_->VerifyUseLists()); |
933 } | 947 } |
934 | 948 |
935 static intptr_t CountConstants(const GrowableArray<Value*>& arguments) { | 949 static intptr_t CountConstants(const GrowableArray<Value*>& arguments) { |
936 intptr_t count = 0; | 950 intptr_t count = 0; |
937 for (intptr_t i = 0; i < arguments.length(); i++) { | 951 for (intptr_t i = 0; i < arguments.length(); i++) { |
938 if (arguments[i]->BindsToConstant()) count++; | 952 if (arguments[i]->BindsToConstant()) count++; |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 } | 1342 } |
1329 } | 1343 } |
1330 GrowableArray<Definition*>* defns = | 1344 GrowableArray<Definition*>* defns = |
1331 callee_graph->graph_entry()->initial_definitions(); | 1345 callee_graph->graph_entry()->initial_definitions(); |
1332 for (intptr_t i = 0; i < defns->length(); ++i) { | 1346 for (intptr_t i = 0; i < defns->length(); ++i) { |
1333 ConstantInstr* constant = (*defns)[i]->AsConstant(); | 1347 ConstantInstr* constant = (*defns)[i]->AsConstant(); |
1334 if ((constant != NULL) && constant->HasUses()) { | 1348 if ((constant != NULL) && constant->HasUses()) { |
1335 constant->ReplaceUsesWith( | 1349 constant->ReplaceUsesWith( |
1336 owner_->caller_graph()->GetConstant(constant->value())); | 1350 owner_->caller_graph()->GetConstant(constant->value())); |
1337 } | 1351 } |
| 1352 CurrentContextInstr* context = (*defns)[i]->AsCurrentContext(); |
| 1353 if ((context != NULL) && context->HasUses()) { |
| 1354 ASSERT(call_data.call->IsClosureCall()); |
| 1355 LoadFieldInstr* context_load = new(isolate()) LoadFieldInstr( |
| 1356 new Value(redefinition), |
| 1357 Closure::context_offset(), |
| 1358 AbstractType::ZoneHandle(isolate(), AbstractType::null()), |
| 1359 call_data.call->token_pos()); |
| 1360 context_load->set_is_immutable(true); |
| 1361 context_load->set_ssa_temp_index( |
| 1362 owner_->caller_graph()->alloc_ssa_temp_index()); |
| 1363 context_load->InsertAfter(redefinition); |
| 1364 context->ReplaceUsesWith(context_load); |
| 1365 } |
1338 } | 1366 } |
1339 return true; | 1367 return true; |
1340 } | 1368 } |
1341 | 1369 |
1342 | 1370 |
1343 static Instruction* AppendInstruction(Instruction* first, | 1371 static Instruction* AppendInstruction(Instruction* first, |
1344 Instruction* second) { | 1372 Instruction* second) { |
1345 for (intptr_t i = second->InputCount() - 1; i >= 0; --i) { | 1373 for (intptr_t i = second->InputCount() - 1; i >= 0; --i) { |
1346 Value* input = second->InputAt(i); | 1374 Value* input = second->InputAt(i); |
1347 input->definition()->AddInputUse(input); | 1375 input->definition()->AddInputUse(input); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 OS::Print("After Inlining of %s\n", flow_graph_-> | 1731 OS::Print("After Inlining of %s\n", flow_graph_-> |
1704 parsed_function().function().ToFullyQualifiedCString()); | 1732 parsed_function().function().ToFullyQualifiedCString()); |
1705 FlowGraphPrinter printer(*flow_graph_); | 1733 FlowGraphPrinter printer(*flow_graph_); |
1706 printer.PrintBlocks(); | 1734 printer.PrintBlocks(); |
1707 } | 1735 } |
1708 } | 1736 } |
1709 } | 1737 } |
1710 } | 1738 } |
1711 | 1739 |
1712 } // namespace dart | 1740 } // namespace dart |
OLD | NEW |