| 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_allocator.h" | 5 #include "vm/flow_graph_allocator.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/il_printer.h" | 9 #include "vm/il_printer.h" |
| 10 #include "vm/flow_graph.h" | 10 #include "vm/flow_graph.h" |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // If this block is a join we need to add destinations of phi | 715 // If this block is a join we need to add destinations of phi |
| 716 // resolution moves to phi's live range so that register allocator will | 716 // resolution moves to phi's live range so that register allocator will |
| 717 // fill them with moves. | 717 // fill them with moves. |
| 718 JoinEntryInstr* join = block->AsJoinEntry(); | 718 JoinEntryInstr* join = block->AsJoinEntry(); |
| 719 if (join == NULL) return; | 719 if (join == NULL) return; |
| 720 | 720 |
| 721 // All uses are recorded at the start position in the block. | 721 // All uses are recorded at the start position in the block. |
| 722 const intptr_t pos = join->start_pos(); | 722 const intptr_t pos = join->start_pos(); |
| 723 | 723 |
| 724 ZoneGrowableArray<PhiInstr*>* phis = join->phis(); | 724 ZoneGrowableArray<PhiInstr*>* phis = join->phis(); |
| 725 if (phis != NULL) { | 725 if (phis == NULL) return; |
| 726 intptr_t move_idx = 0; | |
| 727 for (intptr_t phi_idx = 0; phi_idx < phis->length(); phi_idx++) { | |
| 728 PhiInstr* phi = (*phis)[phi_idx]; | |
| 729 if (phi == NULL) continue; | |
| 730 | 726 |
| 731 const intptr_t vreg = phi->ssa_temp_index(); | 727 const bool is_loop_header = BlockInfoAt(join->start_pos())->is_loop_header(); |
| 732 ASSERT(vreg != -1); | |
| 733 | 728 |
| 734 // Expected shape of live range: | 729 intptr_t move_idx = 0; |
| 735 // | 730 for (intptr_t phi_idx = 0; phi_idx < phis->length(); phi_idx++) { |
| 736 // B | 731 PhiInstr* phi = (*phis)[phi_idx]; |
| 737 // phi [-------- | 732 if (phi == NULL) continue; |
| 738 // | |
| 739 LiveRange* range = GetLiveRange(vreg); | |
| 740 range->DefineAt(pos); // Shorten live range. | |
| 741 | 733 |
| 742 if (join->loop_info() != NULL) range->mark_loop_phi(); | 734 const intptr_t vreg = phi->ssa_temp_index(); |
| 735 ASSERT(vreg != -1); |
| 743 | 736 |
| 744 for (intptr_t pred_idx = 0; pred_idx < phi->InputCount(); pred_idx++) { | 737 // Expected shape of live range: |
| 745 BlockEntryInstr* pred = block->PredecessorAt(pred_idx); | 738 // |
| 746 GotoInstr* goto_instr = pred->last_instruction()->AsGoto(); | 739 // B |
| 747 ASSERT((goto_instr != NULL) && (goto_instr->HasParallelMove())); | 740 // phi [-------- |
| 748 MoveOperands* move = | 741 // |
| 749 goto_instr->parallel_move()->MoveOperandsAt(move_idx); | 742 LiveRange* range = GetLiveRange(vreg); |
| 750 move->set_dest(Location::PrefersRegister()); | 743 range->DefineAt(pos); // Shorten live range. |
| 751 range->AddUse(pos, move->dest_slot()); | |
| 752 } | |
| 753 | 744 |
| 754 // All phi resolution moves are connected. Phi's live range is | 745 if (is_loop_header) range->mark_loop_phi(); |
| 755 // complete. | |
| 756 AssignSafepoints(range); | |
| 757 | 746 |
| 758 CompleteRange(range, RegisterKindForResult(phi)); | 747 for (intptr_t pred_idx = 0; pred_idx < phi->InputCount(); pred_idx++) { |
| 748 BlockEntryInstr* pred = block->PredecessorAt(pred_idx); |
| 749 GotoInstr* goto_instr = pred->last_instruction()->AsGoto(); |
| 750 ASSERT((goto_instr != NULL) && (goto_instr->HasParallelMove())); |
| 751 MoveOperands* move = |
| 752 goto_instr->parallel_move()->MoveOperandsAt(move_idx); |
| 753 move->set_dest(Location::PrefersRegister()); |
| 754 range->AddUse(pos, move->dest_slot()); |
| 755 } |
| 759 | 756 |
| 760 move_idx++; | 757 // All phi resolution moves are connected. Phi's live range is |
| 761 } | 758 // complete. |
| 759 AssignSafepoints(range); |
| 760 |
| 761 CompleteRange(range, RegisterKindForResult(phi)); |
| 762 |
| 763 move_idx++; |
| 762 } | 764 } |
| 763 } | 765 } |
| 764 | 766 |
| 765 | 767 |
| 766 void FlowGraphAllocator::ProcessEnvironmentUses(BlockEntryInstr* block, | 768 void FlowGraphAllocator::ProcessEnvironmentUses(BlockEntryInstr* block, |
| 767 Instruction* current) { | 769 Instruction* current) { |
| 768 ASSERT(current->env() != NULL); | 770 ASSERT(current->env() != NULL); |
| 769 Environment* env = current->env(); | 771 Environment* env = current->env(); |
| 770 while (env != NULL) { | 772 while (env != NULL) { |
| 771 // Any value mentioned in the deoptimization environment should survive | 773 // Any value mentioned in the deoptimization environment should survive |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", | 2348 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", |
| 2347 function.ToFullyQualifiedCString()); | 2349 function.ToFullyQualifiedCString()); |
| 2348 FlowGraphPrinter printer(flow_graph_, true); | 2350 FlowGraphPrinter printer(flow_graph_, true); |
| 2349 printer.PrintBlocks(); | 2351 printer.PrintBlocks(); |
| 2350 OS::Print("----------------------------------------------\n"); | 2352 OS::Print("----------------------------------------------\n"); |
| 2351 } | 2353 } |
| 2352 } | 2354 } |
| 2353 | 2355 |
| 2354 | 2356 |
| 2355 } // namespace dart | 2357 } // namespace dart |
| OLD | NEW |