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