| 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_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 blocked_cpu_regs_[CTX] = true; | 74 blocked_cpu_regs_[CTX] = true; |
| 75 if (TMP != kNoRegister) { | 75 if (TMP != kNoRegister) { |
| 76 blocked_cpu_regs_[TMP] = true; | 76 blocked_cpu_regs_[TMP] = true; |
| 77 } | 77 } |
| 78 blocked_cpu_regs_[SPREG] = true; | 78 blocked_cpu_regs_[SPREG] = true; |
| 79 blocked_cpu_regs_[FPREG] = true; | 79 blocked_cpu_regs_[FPREG] = true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 // Remove environments from the instructions which can't deoptimize. |
| 84 // Replace dead phis uses with null values in environments. |
| 83 void FlowGraphAllocator::EliminateEnvironmentUses() { | 85 void FlowGraphAllocator::EliminateEnvironmentUses() { |
| 86 ConstantVal* null_value = new ConstantVal(Object::ZoneHandle()); |
| 87 |
| 84 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 88 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 85 BlockEntryInstr* block = block_order_[i]; | 89 BlockEntryInstr* block = block_order_[i]; |
| 90 |
| 91 if (block->IsJoinEntry()) block->AsJoinEntry()->RemoveDeadPhis(); |
| 92 |
| 86 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 93 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 87 Instruction* current = it.Current(); | 94 Instruction* current = it.Current(); |
| 88 if (!current->CanDeoptimize()) current->set_env(NULL); | 95 if (current->CanDeoptimize()) { |
| 96 ASSERT(current->env() != NULL); |
| 97 GrowableArray<Value*>* values = current->env()->values_ptr(); |
| 98 |
| 99 for (intptr_t i = 0; i < values->length(); i++) { |
| 100 UseVal* use = (*values)[i]->AsUse(); |
| 101 if (use == NULL) continue; |
| 102 |
| 103 PhiInstr* phi = use->definition()->AsPhi(); |
| 104 if (phi == NULL) continue; |
| 105 |
| 106 if (!phi->is_alive()) (*values)[i] = null_value; |
| 107 } |
| 108 } else { |
| 109 current->set_env(NULL); |
| 110 } |
| 89 } | 111 } |
| 90 } | 112 } |
| 91 } | 113 } |
| 92 | 114 |
| 93 | 115 |
| 94 void FlowGraphAllocator::ComputeInitialSets() { | 116 void FlowGraphAllocator::ComputeInitialSets() { |
| 95 const intptr_t block_count = postorder_.length(); | 117 const intptr_t block_count = postorder_.length(); |
| 96 for (intptr_t i = 0; i < block_count; i++) { | 118 for (intptr_t i = 0; i < block_count; i++) { |
| 97 BlockEntryInstr* block = postorder_[i]; | 119 BlockEntryInstr* block = postorder_[i]; |
| 98 | 120 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 154 } |
| 133 } | 155 } |
| 134 | 156 |
| 135 // Handle phis. | 157 // Handle phis. |
| 136 if (block->IsJoinEntry()) { | 158 if (block->IsJoinEntry()) { |
| 137 JoinEntryInstr* join = block->AsJoinEntry(); | 159 JoinEntryInstr* join = block->AsJoinEntry(); |
| 138 if (join->phis() != NULL) { | 160 if (join->phis() != NULL) { |
| 139 for (intptr_t j = 0; j < join->phis()->length(); j++) { | 161 for (intptr_t j = 0; j < join->phis()->length(); j++) { |
| 140 PhiInstr* phi = (*join->phis())[j]; | 162 PhiInstr* phi = (*join->phis())[j]; |
| 141 if (phi == NULL) continue; | 163 if (phi == NULL) continue; |
| 164 |
| 142 kill->Add(phi->ssa_temp_index()); | 165 kill->Add(phi->ssa_temp_index()); |
| 143 live_in->Remove(phi->ssa_temp_index()); | 166 live_in->Remove(phi->ssa_temp_index()); |
| 144 | 167 |
| 145 // If phi-operand is not defined by a predecessor it must be marked | 168 // If phi-operand is not defined by a predecessor it must be marked |
| 146 // live-in for a predecessor. | 169 // live-in for a predecessor. |
| 147 for (intptr_t k = 0; k < phi->InputCount(); k++) { | 170 for (intptr_t k = 0; k < phi->InputCount(); k++) { |
| 148 Value* val = phi->InputAt(k); | 171 Value* val = phi->InputAt(k); |
| 149 if (val->IsUse()) { | 172 if (val->IsUse()) { |
| 150 BlockEntryInstr* pred = block->PredecessorAt(k); | 173 BlockEntryInstr* pred = block->PredecessorAt(k); |
| 151 const intptr_t use = val->AsUse()->definition()->ssa_temp_index(); | 174 const intptr_t use = val->AsUse()->definition()->ssa_temp_index(); |
| (...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", | 1911 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", |
| 1889 function.ToFullyQualifiedCString()); | 1912 function.ToFullyQualifiedCString()); |
| 1890 FlowGraphPrinter printer(Function::Handle(), block_order_, true); | 1913 FlowGraphPrinter printer(Function::Handle(), block_order_, true); |
| 1891 printer.PrintBlocks(); | 1914 printer.PrintBlocks(); |
| 1892 OS::Print("----------------------------------------------\n"); | 1915 OS::Print("----------------------------------------------\n"); |
| 1893 } | 1916 } |
| 1894 } | 1917 } |
| 1895 | 1918 |
| 1896 | 1919 |
| 1897 } // namespace dart | 1920 } // namespace dart |
| OLD | NEW |