| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. | 507 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. |
| 508 start_env.Add(param); | 508 start_env.Add(param); |
| 509 } | 509 } |
| 510 | 510 |
| 511 // All locals are initialized with #null. Use the global definition, uses | 511 // All locals are initialized with #null. Use the global definition, uses |
| 512 // will be created in the Environment constructor. | 512 // will be created in the Environment constructor. |
| 513 while (start_env.length() < variable_count()) { | 513 while (start_env.length() < variable_count()) { |
| 514 start_env.Add(graph_entry_->constant_null()); | 514 start_env.Add(graph_entry_->constant_null()); |
| 515 } | 515 } |
| 516 graph_entry_->set_start_env( | 516 graph_entry_->set_start_env( |
| 517 Environment::From(start_env, | 517 Environment::From(start_env, num_non_copied_params_, NULL)); |
| 518 num_non_copied_params_, | |
| 519 parsed_function_.function())); | |
| 520 | 518 |
| 521 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); | 519 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); |
| 522 ASSERT(normal_entry != NULL); // Must have entry. | 520 ASSERT(normal_entry != NULL); // Must have entry. |
| 523 GrowableArray<Definition*> env(variable_count()); | 521 GrowableArray<Definition*> env(variable_count()); |
| 524 env.AddArray(start_env); | 522 env.AddArray(start_env); |
| 525 RenameRecursive(normal_entry, &env, live_phis); | 523 RenameRecursive(normal_entry, &env, live_phis); |
| 526 } | 524 } |
| 527 | 525 |
| 528 | 526 |
| 529 void FlowGraph::RenameRecursive(BlockEntryInstr* block_entry, | 527 void FlowGraph::RenameRecursive(BlockEntryInstr* block_entry, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 542 } | 540 } |
| 543 } | 541 } |
| 544 } | 542 } |
| 545 | 543 |
| 546 // 2. Process normal instructions. | 544 // 2. Process normal instructions. |
| 547 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) { | 545 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) { |
| 548 Instruction* current = it.Current(); | 546 Instruction* current = it.Current(); |
| 549 // Attach current environment to the instruction. First, each instruction | 547 // Attach current environment to the instruction. First, each instruction |
| 550 // gets a full copy of the environment. Later we optimize this by | 548 // gets a full copy of the environment. Later we optimize this by |
| 551 // eliminating unnecessary environments. | 549 // eliminating unnecessary environments. |
| 552 current->set_env(Environment::From(*env, | 550 current->set_env( |
| 553 num_non_copied_params_, | 551 Environment::From(*env, num_non_copied_params_, NULL)); |
| 554 parsed_function_.function())); | |
| 555 if (current->CanDeoptimize()) { | |
| 556 current->env()->set_deopt_id(current->deopt_id()); | |
| 557 } | |
| 558 | 552 |
| 559 // 2a. Handle uses: | 553 // 2a. Handle uses: |
| 560 // Update expression stack environment for each use. | 554 // Update expression stack environment for each use. |
| 561 // For each use of a LoadLocal or StoreLocal: Replace it with the value | 555 // For each use of a LoadLocal or StoreLocal: Replace it with the value |
| 562 // from the environment. | 556 // from the environment. |
| 563 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) { | 557 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) { |
| 564 Value* v = current->InputAt(i); | 558 Value* v = current->InputAt(i); |
| 565 // Update expression stack. | 559 // Update expression stack. |
| 566 ASSERT(env->length() > variable_count()); | 560 ASSERT(env->length() > variable_count()); |
| 567 | 561 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 // TODO(zerny): Implement support for callee graphs with control flow. | 771 // TODO(zerny): Implement support for callee graphs with control flow. |
| 778 ASSERT(callee_graph->preorder().length() == 2); | 772 ASSERT(callee_graph->preorder().length() == 2); |
| 779 | 773 |
| 780 // Adjust the SSA temp index by the callee graph's index. | 774 // Adjust the SSA temp index by the callee graph's index. |
| 781 current_ssa_temp_index_ = callee_graph->max_virtual_register_number(); | 775 current_ssa_temp_index_ = callee_graph->max_virtual_register_number(); |
| 782 | 776 |
| 783 BlockEntryInstr* caller_entry = GetBlockEntry(call); | 777 BlockEntryInstr* caller_entry = GetBlockEntry(call); |
| 784 TargetEntryInstr* callee_entry = callee_graph->graph_entry()->normal_entry(); | 778 TargetEntryInstr* callee_entry = callee_graph->graph_entry()->normal_entry(); |
| 785 ZoneGrowableArray<ReturnInstr*>* callee_exits = callee_graph->exits(); | 779 ZoneGrowableArray<ReturnInstr*>* callee_exits = callee_graph->exits(); |
| 786 | 780 |
| 787 // 0. Attach the outer environment on each instruction in the callee graph. | |
| 788 for (ForwardInstructionIterator it(callee_entry); !it.Done(); it.Advance()) { | |
| 789 Instruction* instr = it.Current(); | |
| 790 if (instr->CanDeoptimize()) call->env()->DeepCopyToOuter(instr); | |
| 791 } | |
| 792 | |
| 793 // 1. Insert the callee graph into the caller graph. | 781 // 1. Insert the callee graph into the caller graph. |
| 794 if (callee_exits->is_empty()) { | 782 if (callee_exits->is_empty()) { |
| 795 // If no normal exits exist, inline and truncate the block after inlining. | 783 // If no normal exits exist, inline and truncate the block after inlining. |
| 796 Link(call->previous(), callee_entry->next()); | 784 Link(call->previous(), callee_entry->next()); |
| 797 caller_entry->set_last_instruction(callee_entry->last_instruction()); | 785 caller_entry->set_last_instruction(callee_entry->last_instruction()); |
| 798 } else if (callee_exits->length() == 1) { | 786 } else if (callee_exits->length() == 1) { |
| 799 ReturnInstr* exit = (*callee_exits)[0]; | 787 ReturnInstr* exit = (*callee_exits)[0]; |
| 800 // TODO(zerny): Support one exit graph containing control flow. | 788 // TODO(zerny): Support one exit graph containing control flow. |
| 801 ASSERT(callee_entry == GetBlockEntry(exit)); | 789 ASSERT(callee_entry == GetBlockEntry(exit)); |
| 802 // For just one exit, replace the uses and remove the call from the graph. | 790 // For just one exit, replace the uses and remove the call from the graph. |
| 803 call->ReplaceUsesWith(exit->value()->definition()); | 791 call->ReplaceUsesWith(exit->value()->definition()); |
| 804 Link(call->previous(), callee_entry->next()); | 792 Link(call->previous(), callee_entry->next()); |
| 805 Link(exit->previous(), call->next()); | 793 Link(exit->previous(), call->next()); |
| 806 } else { | 794 } else { |
| 807 // TODO(zerny): Support multiple exits. | 795 // TODO(zerny): Support multiple exits. |
| 808 UNREACHABLE(); | 796 UNREACHABLE(); |
| 809 } | 797 } |
| 810 | 798 |
| 811 // TODO(zerny): Adjust pre/post orders. | 799 // TODO(zerny): Adjust pre/post orders. |
| 812 // TODO(zerny): Update dominator tree. | 800 // TODO(zerny): Update dominator tree. |
| 813 } | 801 } |
| 814 | 802 |
| 815 | 803 |
| 816 } // namespace dart | 804 } // namespace dart |
| OLD | NEW |