| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/register-allocator.h" | 5 #include "src/compiler/register-allocator.h" |
| 6 | 6 |
| 7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
| 8 #include "src/hydrogen.h" | 8 #include "src/hydrogen.h" |
| 9 #include "src/string-stream.h" | 9 #include "src/string-stream.h" |
| 10 | 10 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (a == NULL || a->start().Value() > other->End().Value()) break; | 492 if (a == NULL || a->start().Value() > other->End().Value()) break; |
| 493 AdvanceLastProcessedMarker(a, advance_last_processed_up_to); | 493 AdvanceLastProcessedMarker(a, advance_last_processed_up_to); |
| 494 } else { | 494 } else { |
| 495 b = b->next(); | 495 b = b->next(); |
| 496 } | 496 } |
| 497 } | 497 } |
| 498 return LifetimePosition::Invalid(); | 498 return LifetimePosition::Invalid(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 | 501 |
| 502 RegisterAllocator::RegisterAllocator(Frame* frame, CompilationInfo* info, | 502 RegisterAllocator::RegisterAllocator(Zone* local_zone, Frame* frame, |
| 503 CompilationInfo* info, |
| 503 InstructionSequence* code) | 504 InstructionSequence* code) |
| 504 : zone_(code->isolate()), | 505 : zone_(local_zone), |
| 506 zone_pool_(NULL), |
| 505 frame_(frame), | 507 frame_(frame), |
| 506 info_(info), | 508 info_(info), |
| 507 code_(code), | 509 code_(code), |
| 508 live_in_sets_(code->InstructionBlockCount(), zone()), | 510 live_in_sets_(code->InstructionBlockCount(), zone()), |
| 509 live_ranges_(code->VirtualRegisterCount() * 2, zone()), | 511 live_ranges_(code->VirtualRegisterCount() * 2, zone()), |
| 510 fixed_live_ranges_(NULL), | 512 fixed_live_ranges_(NULL), |
| 511 fixed_double_live_ranges_(NULL), | 513 fixed_double_live_ranges_(NULL), |
| 512 unhandled_live_ranges_(code->VirtualRegisterCount() * 2, zone()), | 514 unhandled_live_ranges_(code->VirtualRegisterCount() * 2, zone()), |
| 513 active_live_ranges_(8, zone()), | 515 active_live_ranges_(8, zone()), |
| 514 inactive_live_ranges_(8, zone()), | 516 inactive_live_ranges_(8, zone()), |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 | 1089 |
| 1088 // We use the phi-ness of some nodes in some later heuristics. | 1090 // We use the phi-ness of some nodes in some later heuristics. |
| 1089 live_range->set_is_phi(true); | 1091 live_range->set_is_phi(true); |
| 1090 if (!block->IsLoopHeader()) { | 1092 if (!block->IsLoopHeader()) { |
| 1091 live_range->set_is_non_loop_phi(true); | 1093 live_range->set_is_non_loop_phi(true); |
| 1092 } | 1094 } |
| 1093 } | 1095 } |
| 1094 } | 1096 } |
| 1095 | 1097 |
| 1096 | 1098 |
| 1097 bool RegisterAllocator::Allocate() { | 1099 bool RegisterAllocator::Allocate(ZonePool* zone_pool) { |
| 1100 DCHECK_EQ(NULL, zone_pool_); |
| 1101 zone_pool_ = zone_pool; |
| 1098 assigned_registers_ = new (code_zone()) | 1102 assigned_registers_ = new (code_zone()) |
| 1099 BitVector(Register::NumAllocatableRegisters(), code_zone()); | 1103 BitVector(Register::NumAllocatableRegisters(), code_zone()); |
| 1100 assigned_double_registers_ = new (code_zone()) | 1104 assigned_double_registers_ = new (code_zone()) |
| 1101 BitVector(DoubleRegister::NumAllocatableAliasedRegisters(), code_zone()); | 1105 BitVector(DoubleRegister::NumAllocatableAliasedRegisters(), code_zone()); |
| 1102 MeetRegisterConstraints(); | 1106 MeetRegisterConstraints(); |
| 1103 if (!AllocationOk()) return false; | 1107 if (!AllocationOk()) return false; |
| 1104 ResolvePhis(); | 1108 ResolvePhis(); |
| 1105 BuildLiveRanges(); | 1109 BuildLiveRanges(); |
| 1106 AllocateGeneralRegisters(); | 1110 AllocateGeneralRegisters(); |
| 1107 if (!AllocationOk()) return false; | 1111 if (!AllocationOk()) return false; |
| 1108 AllocateDoubleRegisters(); | 1112 AllocateDoubleRegisters(); |
| 1109 if (!AllocationOk()) return false; | 1113 if (!AllocationOk()) return false; |
| 1110 PopulatePointerMaps(); | 1114 PopulatePointerMaps(); |
| 1111 ConnectRanges(); | 1115 ConnectRanges(); |
| 1112 ResolveControlFlow(); | 1116 ResolveControlFlow(); |
| 1113 frame()->SetAllocatedRegisters(assigned_registers_); | 1117 frame()->SetAllocatedRegisters(assigned_registers_); |
| 1114 frame()->SetAllocatedDoubleRegisters(assigned_double_registers_); | 1118 frame()->SetAllocatedDoubleRegisters(assigned_double_registers_); |
| 1115 return true; | 1119 return true; |
| 1116 } | 1120 } |
| 1117 | 1121 |
| 1118 | 1122 |
| 1123 class RegisterAllocatorPhase : public CompilationPhase { |
| 1124 public: |
| 1125 RegisterAllocatorPhase(const char* name, RegisterAllocator* allocator) |
| 1126 : CompilationPhase(name, allocator->info()), |
| 1127 allocator_(allocator), |
| 1128 allocator_zone_start_allocation_size_(0), |
| 1129 stats_(NULL) { |
| 1130 if (FLAG_turbo_stats) { |
| 1131 allocator_zone_start_allocation_size_ = |
| 1132 allocator->info()->zone()->allocation_size(); |
| 1133 if (allocator->zone_pool() != NULL) { |
| 1134 stats_ = new ZonePool::StatsScope(allocator->zone_pool()); |
| 1135 } |
| 1136 } |
| 1137 } |
| 1138 |
| 1139 ~RegisterAllocatorPhase() { |
| 1140 if (FLAG_turbo_stats) { |
| 1141 unsigned size = allocator_->info()->zone()->allocation_size() - |
| 1142 allocator_zone_start_allocation_size_; |
| 1143 if (stats_ != NULL) { |
| 1144 size += static_cast<unsigned>(stats_->GetMaxAllocatedBytes()); |
| 1145 } |
| 1146 isolate()->GetTStatistics()->SaveTiming(name(), base::TimeDelta(), size); |
| 1147 } |
| 1148 delete stats_; |
| 1149 #ifdef DEBUG |
| 1150 if (allocator_ != NULL) allocator_->Verify(); |
| 1151 #endif |
| 1152 } |
| 1153 |
| 1154 private: |
| 1155 RegisterAllocator* allocator_; |
| 1156 unsigned allocator_zone_start_allocation_size_; |
| 1157 ZonePool::StatsScope* stats_; |
| 1158 |
| 1159 DISALLOW_COPY_AND_ASSIGN(RegisterAllocatorPhase); |
| 1160 }; |
| 1161 |
| 1162 |
| 1119 void RegisterAllocator::MeetRegisterConstraints() { | 1163 void RegisterAllocator::MeetRegisterConstraints() { |
| 1120 RegisterAllocatorPhase phase("L_Register constraints", this); | 1164 RegisterAllocatorPhase phase("L_Register constraints", this); |
| 1121 for (int i = 0; i < code()->InstructionBlockCount(); ++i) { | 1165 for (int i = 0; i < code()->InstructionBlockCount(); ++i) { |
| 1122 MeetRegisterConstraints( | 1166 MeetRegisterConstraints( |
| 1123 code()->InstructionBlockAt(BasicBlock::RpoNumber::FromInt(i))); | 1167 code()->InstructionBlockAt(BasicBlock::RpoNumber::FromInt(i))); |
| 1124 if (!AllocationOk()) return; | 1168 if (!AllocationOk()) return; |
| 1125 } | 1169 } |
| 1126 } | 1170 } |
| 1127 | 1171 |
| 1128 | 1172 |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 int reg) { | 2244 int reg) { |
| 2201 if (range->Kind() == DOUBLE_REGISTERS) { | 2245 if (range->Kind() == DOUBLE_REGISTERS) { |
| 2202 assigned_double_registers_->Add(reg); | 2246 assigned_double_registers_->Add(reg); |
| 2203 } else { | 2247 } else { |
| 2204 DCHECK(range->Kind() == GENERAL_REGISTERS); | 2248 DCHECK(range->Kind() == GENERAL_REGISTERS); |
| 2205 assigned_registers_->Add(reg); | 2249 assigned_registers_->Add(reg); |
| 2206 } | 2250 } |
| 2207 range->set_assigned_register(reg, code_zone()); | 2251 range->set_assigned_register(reg, code_zone()); |
| 2208 } | 2252 } |
| 2209 | 2253 |
| 2210 | |
| 2211 RegisterAllocatorPhase::RegisterAllocatorPhase(const char* name, | |
| 2212 RegisterAllocator* allocator) | |
| 2213 : CompilationPhase(name, allocator->info()), allocator_(allocator) { | |
| 2214 if (FLAG_turbo_stats) { | |
| 2215 allocator_zone_start_allocation_size_ = | |
| 2216 allocator->zone()->allocation_size(); | |
| 2217 } | |
| 2218 } | |
| 2219 | |
| 2220 | |
| 2221 RegisterAllocatorPhase::~RegisterAllocatorPhase() { | |
| 2222 if (FLAG_turbo_stats) { | |
| 2223 unsigned size = allocator_->zone()->allocation_size() - | |
| 2224 allocator_zone_start_allocation_size_; | |
| 2225 isolate()->GetTStatistics()->SaveTiming(name(), base::TimeDelta(), size); | |
| 2226 } | |
| 2227 #ifdef DEBUG | |
| 2228 if (allocator_ != NULL) allocator_->Verify(); | |
| 2229 #endif | |
| 2230 } | |
| 2231 } | 2254 } |
| 2232 } | 2255 } |
| 2233 } // namespace v8::internal::compiler | 2256 } // namespace v8::internal::compiler |
| OLD | NEW |