Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 void FlowGraphAllocator::EliminateEnvironmentUses() { | 88 void FlowGraphAllocator::EliminateEnvironmentUses() { |
| 89 ConstantInstr* constant_null = | 89 ConstantInstr* constant_null = |
| 90 postorder_.Last()->AsGraphEntry()->constant_null(); | 90 postorder_.Last()->AsGraphEntry()->constant_null(); |
| 91 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 91 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 92 BlockEntryInstr* block = block_order_[i]; | 92 BlockEntryInstr* block = block_order_[i]; |
| 93 if (block->IsJoinEntry()) block->AsJoinEntry()->RemoveDeadPhis(); | 93 if (block->IsJoinEntry()) block->AsJoinEntry()->RemoveDeadPhis(); |
| 94 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 94 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 95 Instruction* current = it.Current(); | 95 Instruction* current = it.Current(); |
| 96 if (current->CanDeoptimize()) { | 96 if (current->CanDeoptimize()) { |
| 97 ASSERT(current->env() != NULL); | 97 ASSERT(current->env() != NULL); |
| 98 GrowableArray<Value*>* values = current->env()->values_ptr(); | 98 for (EnvironmentIterator it(current->env()); !it.Done(); it.Advance()) { |
| 99 for (intptr_t i = 0; i < values->length(); i++) { | 99 Value* use = it.CurrentValue(); |
| 100 Value* use = (*values)[i]; | |
| 101 Definition* def = use->definition(); | 100 Definition* def = use->definition(); |
| 102 PushArgumentInstr* push_argument = def->AsPushArgument(); | 101 PushArgumentInstr* push_argument = def->AsPushArgument(); |
| 103 if ((push_argument != NULL) && push_argument->WasEliminated()) { | 102 if ((push_argument != NULL) && push_argument->WasEliminated()) { |
| 104 (*values)[i] = push_argument->value()->Copy(); | 103 it.ReplaceValue(push_argument->value()->Copy()); |
| 105 continue; | 104 continue; |
| 106 } | 105 } |
| 107 | 106 |
| 108 PhiInstr* phi = def->AsPhi(); | 107 PhiInstr* phi = def->AsPhi(); |
| 109 if ((phi != NULL) && !phi->is_alive()) { | 108 if ((phi != NULL) && !phi->is_alive()) { |
| 110 (*values)[i] = new Value(constant_null); | 109 it.ReplaceValue(new Value(constant_null)); |
| 111 continue; | 110 continue; |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 } else { | 113 } else { |
| 115 current->set_env(NULL); | 114 current->set_env(NULL); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 | 119 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 140 | 139 |
| 141 // Handle uses. | 140 // Handle uses. |
| 142 for (intptr_t j = 0; j < current->InputCount(); j++) { | 141 for (intptr_t j = 0; j < current->InputCount(); j++) { |
| 143 Value* input = current->InputAt(j); | 142 Value* input = current->InputAt(j); |
| 144 const intptr_t use = input->definition()->ssa_temp_index(); | 143 const intptr_t use = input->definition()->ssa_temp_index(); |
| 145 live_in->Add(use); | 144 live_in->Add(use); |
| 146 } | 145 } |
| 147 | 146 |
| 148 // Add uses from the deoptimization environment. | 147 // Add uses from the deoptimization environment. |
| 149 if (current->env() != NULL) { | 148 if (current->env() != NULL) { |
| 150 const GrowableArray<Value*>& values = current->env()->values(); | 149 for (intptr_t i = 0; i < current->env()->Length(); ++i) { |
|
Kevin Millikin (Google)
2012/09/07 12:51:52
This seems wrong. Why are values in outer environ
zerny-google
2012/09/07 13:51:37
I think this one is safe, but I have tried only to
| |
| 151 for (intptr_t j = 0; j < values.length(); j++) { | 150 Value* value = current->env()->ValueAt(i); |
| 152 Value* value = values[j]; | |
| 153 if (!value->definition()->IsPushArgument()) { | 151 if (!value->definition()->IsPushArgument()) { |
| 154 live_in->Add(value->definition()->ssa_temp_index()); | 152 live_in->Add(value->definition()->ssa_temp_index()); |
| 155 } | 153 } |
| 156 } | 154 } |
| 157 } | 155 } |
| 158 } | 156 } |
| 159 | 157 |
| 160 // Handle phis. | 158 // Handle phis. |
| 161 if (block->IsJoinEntry()) { | 159 if (block->IsJoinEntry()) { |
| 162 JoinEntryInstr* join = block->AsJoinEntry(); | 160 JoinEntryInstr* join = block->AsJoinEntry(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 178 live_in_[pred->postorder_number()]->Add(use); | 176 live_in_[pred->postorder_number()]->Add(use); |
| 179 } | 177 } |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 } | 180 } |
| 183 } | 181 } |
| 184 } | 182 } |
| 185 | 183 |
| 186 // Process incoming parameters. | 184 // Process incoming parameters. |
| 187 GraphEntryInstr* graph_entry = postorder_.Last()->AsGraphEntry(); | 185 GraphEntryInstr* graph_entry = postorder_.Last()->AsGraphEntry(); |
| 188 for (intptr_t i = 0; i < graph_entry->start_env()->values().length(); i++) { | 186 for (intptr_t i = 0; i < graph_entry->start_env()->Length(); i++) { |
| 189 Value* val = graph_entry->start_env()->values()[i]; | 187 Value* val = graph_entry->start_env()->ValueAt(i); |
| 190 intptr_t vreg = val->definition()->ssa_temp_index(); | 188 intptr_t vreg = val->definition()->ssa_temp_index(); |
| 191 kill_[graph_entry->postorder_number()]->Add(vreg); | 189 kill_[graph_entry->postorder_number()]->Add(vreg); |
| 192 live_in_[graph_entry->postorder_number()]->Remove(vreg); | 190 live_in_[graph_entry->postorder_number()]->Remove(vreg); |
| 193 } | 191 } |
| 194 | 192 |
| 195 // Process global constants. | 193 // Process global constants. |
| 196 intptr_t vreg = graph_entry->constant_null()->ssa_temp_index(); | 194 intptr_t vreg = graph_entry->constant_null()->ssa_temp_index(); |
| 197 kill_[graph_entry->postorder_number()]->Add(vreg); | 195 kill_[graph_entry->postorder_number()]->Add(vreg); |
| 198 live_in_[graph_entry->postorder_number()]->Remove(vreg); | 196 live_in_[graph_entry->postorder_number()]->Remove(vreg); |
| 199 | 197 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 } | 510 } |
| 513 current = current->previous(); | 511 current = current->previous(); |
| 514 } | 512 } |
| 515 | 513 |
| 516 ConnectIncomingPhiMoves(block); | 514 ConnectIncomingPhiMoves(block); |
| 517 } | 515 } |
| 518 | 516 |
| 519 // Process incoming parameters. Do this after all other instructions so | 517 // Process incoming parameters. Do this after all other instructions so |
| 520 // that safepoints for all calls have already been found. | 518 // that safepoints for all calls have already been found. |
| 521 GraphEntryInstr* graph_entry = postorder_.Last()->AsGraphEntry(); | 519 GraphEntryInstr* graph_entry = postorder_.Last()->AsGraphEntry(); |
| 522 for (intptr_t i = 0; i < graph_entry->start_env()->values().length(); i++) { | 520 for (intptr_t i = 0; i < graph_entry->start_env()->Length(); i++) { |
| 523 Value* val = graph_entry->start_env()->values()[i]; | 521 Value* val = graph_entry->start_env()->ValueAt(i); |
| 524 ParameterInstr* param = val->definition()->AsParameter(); | 522 ParameterInstr* param = val->definition()->AsParameter(); |
| 525 if (param == NULL) continue; | 523 if (param == NULL) continue; |
| 526 | 524 |
| 527 // Handle the parameters specially. They are spilled on entry. | 525 // Handle the parameters specially. They are spilled on entry. |
| 528 LiveRange* range = GetLiveRange(param->ssa_temp_index()); | 526 LiveRange* range = GetLiveRange(param->ssa_temp_index()); |
| 529 range->AddUseInterval(graph_entry->start_pos(), graph_entry->end_pos()); | 527 range->AddUseInterval(graph_entry->start_pos(), graph_entry->end_pos()); |
| 530 range->DefineAt(graph_entry->start_pos()); | 528 range->DefineAt(graph_entry->start_pos()); |
| 531 | 529 |
| 532 // Assert that copied and non-copied parameters are mutually exclusive. | 530 // Assert that copied and non-copied parameters are mutually exclusive. |
| 533 // This might change in the future and, if so, the index will be wrong. | 531 // This might change in the future and, if so, the index will be wrong. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 Environment* env = current->env(); | 739 Environment* env = current->env(); |
| 742 | 740 |
| 743 // Any value mentioned in the deoptimization environment should survive | 741 // Any value mentioned in the deoptimization environment should survive |
| 744 // until the end of instruction but it does not need to be in the register. | 742 // until the end of instruction but it does not need to be in the register. |
| 745 // Expected shape of live range: | 743 // Expected shape of live range: |
| 746 // | 744 // |
| 747 // i i' | 745 // i i' |
| 748 // value -----* | 746 // value -----* |
| 749 // | 747 // |
| 750 | 748 |
| 751 const GrowableArray<Value*>& values = env->values(); | 749 if (env->Length() == 0) return; |
|
Kevin Millikin (Google)
2012/09/07 12:51:52
This also seems wrong. What if there are values i
zerny-google
2012/09/07 13:51:37
This needs to be defined recursively on the nested
| |
| 752 if (values.length() == 0) return; | |
| 753 | 750 |
| 754 const intptr_t block_start_pos = block->start_pos(); | 751 const intptr_t block_start_pos = block->start_pos(); |
| 755 const intptr_t use_pos = current->lifetime_position() + 1; | 752 const intptr_t use_pos = current->lifetime_position() + 1; |
| 756 | 753 |
| 757 Location* locations = | 754 Location* locations = |
| 758 Isolate::Current()->current_zone()->Alloc<Location>(values.length()); | 755 Isolate::Current()->current_zone()->Alloc<Location>(env->Length()); |
| 759 | 756 |
| 760 for (intptr_t i = 0; i < values.length(); ++i) { | 757 for (intptr_t i = 0; i < env->Length(); ++i) { |
| 761 Value* value = values[i]; | 758 Value* value = env->ValueAt(i); |
| 762 locations[i] = Location::Any(); | 759 locations[i] = Location::Any(); |
| 763 Definition* def = value->definition(); | 760 Definition* def = value->definition(); |
| 764 | 761 |
| 765 if (def->IsPushArgument()) { | 762 if (def->IsPushArgument()) { |
| 766 // Frame size is unknown until after allocation. | 763 // Frame size is unknown until after allocation. |
| 767 locations[i] = Location::NoLocation(); | 764 locations[i] = Location::NoLocation(); |
| 768 continue; | 765 continue; |
| 769 } | 766 } |
| 770 | 767 |
| 771 ConstantInstr* constant = def->AsConstant(); | 768 ConstantInstr* constant = def->AsConstant(); |
| (...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2183 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", | 2180 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", |
| 2184 function.ToFullyQualifiedCString()); | 2181 function.ToFullyQualifiedCString()); |
| 2185 FlowGraphPrinter printer(flow_graph_, true); | 2182 FlowGraphPrinter printer(flow_graph_, true); |
| 2186 printer.PrintBlocks(); | 2183 printer.PrintBlocks(); |
| 2187 OS::Print("----------------------------------------------\n"); | 2184 OS::Print("----------------------------------------------\n"); |
| 2188 } | 2185 } |
| 2189 } | 2186 } |
| 2190 | 2187 |
| 2191 | 2188 |
| 2192 } // namespace dart | 2189 } // namespace dart |
| OLD | NEW |