Chromium Code Reviews| 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 #ifndef V8_REGISTER_ALLOCATOR_H_ | 5 #ifndef V8_REGISTER_ALLOCATOR_H_ |
| 6 #define V8_REGISTER_ALLOCATOR_H_ | 6 #define V8_REGISTER_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | |
| 9 #include "src/compiler/instruction.h" | 8 #include "src/compiler/instruction.h" |
| 10 #include "src/macro-assembler.h" | 9 #include "src/zone-containers.h" |
| 11 #include "src/zone.h" | |
| 12 | 10 |
| 13 namespace v8 { | 11 namespace v8 { |
| 14 namespace internal { | 12 namespace internal { |
| 15 namespace compiler { | 13 namespace compiler { |
| 16 | 14 |
| 17 class PipelineStatistics; | 15 class PipelineStatistics; |
| 18 | 16 |
| 19 enum RegisterKind { | 17 enum RegisterKind { |
| 20 UNALLOCATED_REGISTERS, | 18 UNALLOCATED_REGISTERS, |
| 21 GENERAL_REGISTERS, | 19 GENERAL_REGISTERS, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 int spill_start_index_; | 312 int spill_start_index_; |
| 315 | 313 |
| 316 friend class RegisterAllocator; // Assigns to kind_. | 314 friend class RegisterAllocator; // Assigns to kind_. |
| 317 | 315 |
| 318 DISALLOW_COPY_AND_ASSIGN(LiveRange); | 316 DISALLOW_COPY_AND_ASSIGN(LiveRange); |
| 319 }; | 317 }; |
| 320 | 318 |
| 321 | 319 |
| 322 class RegisterAllocator BASE_EMBEDDED { | 320 class RegisterAllocator BASE_EMBEDDED { |
| 323 public: | 321 public: |
| 324 explicit RegisterAllocator(Zone* local_zone, Frame* frame, | 322 class Config { |
| 325 InstructionSequence* code, | 323 public: |
| 324 int num_general_registers_; | |
| 325 int num_double_registers_; | |
| 326 int num_aliased_double_registers_; | |
| 327 const char* (*GeneralRegisterName)(int allocation_index); | |
| 328 const char* (*DoubleRegisterName)(int allocation_index); | |
|
Jarin
2014/10/29 17:37:43
Why can't these guys be virtual methods?
| |
| 329 }; | |
| 330 | |
| 331 static Config PlatformConfig(); | |
| 332 | |
| 333 explicit RegisterAllocator(const Config& config, Zone* local_zone, | |
| 334 Frame* frame, InstructionSequence* code, | |
| 326 const char* debug_name = nullptr); | 335 const char* debug_name = nullptr); |
| 327 | 336 |
| 328 bool Allocate(PipelineStatistics* stats = NULL); | 337 bool Allocate(PipelineStatistics* stats = NULL); |
| 329 bool AllocationOk() { return allocation_ok_; } | 338 bool AllocationOk() { return allocation_ok_; } |
| 330 BitVector* assigned_registers() { return assigned_registers_; } | 339 BitVector* assigned_registers() { return assigned_registers_; } |
| 331 BitVector* assigned_double_registers() { return assigned_double_registers_; } | 340 BitVector* assigned_double_registers() { return assigned_double_registers_; } |
| 332 | 341 |
| 333 const ZoneList<LiveRange*>* live_ranges() const { return &live_ranges_; } | 342 const ZoneList<LiveRange*>& live_ranges() const { return live_ranges_; } |
| 334 const Vector<LiveRange*>* fixed_live_ranges() const { | 343 const ZoneVector<LiveRange*>& fixed_live_ranges() const { |
| 335 return &fixed_live_ranges_; | 344 return fixed_live_ranges_; |
| 336 } | 345 } |
| 337 const Vector<LiveRange*>* fixed_double_live_ranges() const { | 346 const ZoneVector<LiveRange*>& fixed_double_live_ranges() const { |
| 338 return &fixed_double_live_ranges_; | 347 return fixed_double_live_ranges_; |
| 339 } | 348 } |
| 340 InstructionSequence* code() const { return code_; } | 349 InstructionSequence* code() const { return code_; } |
| 341 | 350 |
| 342 private: | 351 private: |
| 343 int GetVirtualRegister() { | 352 int GetVirtualRegister() { |
| 344 int vreg = code()->NextVirtualRegister(); | 353 int vreg = code()->NextVirtualRegister(); |
| 345 if (vreg >= UnallocatedOperand::kMaxVirtualRegisters) { | 354 if (vreg >= UnallocatedOperand::kMaxVirtualRegisters) { |
| 346 allocation_ok_ = false; | 355 allocation_ok_ = false; |
| 347 // Maintain the invariant that we return something below the maximum. | 356 // Maintain the invariant that we return something below the maximum. |
| 348 return 0; | 357 return 0; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 // Return parallel move that should be used to connect ranges split at the | 483 // Return parallel move that should be used to connect ranges split at the |
| 475 // given position. | 484 // given position. |
| 476 ParallelMove* GetConnectingParallelMove(LifetimePosition pos); | 485 ParallelMove* GetConnectingParallelMove(LifetimePosition pos); |
| 477 | 486 |
| 478 // Return the block which contains give lifetime position. | 487 // Return the block which contains give lifetime position. |
| 479 const InstructionBlock* GetInstructionBlock(LifetimePosition pos); | 488 const InstructionBlock* GetInstructionBlock(LifetimePosition pos); |
| 480 | 489 |
| 481 // Helper methods for the fixed registers. | 490 // Helper methods for the fixed registers. |
| 482 int RegisterCount() const; | 491 int RegisterCount() const; |
| 483 static int FixedLiveRangeID(int index) { return -index - 1; } | 492 static int FixedLiveRangeID(int index) { return -index - 1; } |
| 484 static int FixedDoubleLiveRangeID(int index); | 493 int FixedDoubleLiveRangeID(int index); |
| 485 LiveRange* FixedLiveRangeFor(int index); | 494 LiveRange* FixedLiveRangeFor(int index); |
| 486 LiveRange* FixedDoubleLiveRangeFor(int index); | 495 LiveRange* FixedDoubleLiveRangeFor(int index); |
| 487 LiveRange* LiveRangeFor(int index); | 496 LiveRange* LiveRangeFor(int index); |
| 488 GapInstruction* GetLastGap(const InstructionBlock* block); | 497 GapInstruction* GetLastGap(const InstructionBlock* block); |
| 489 | 498 |
| 490 const char* RegisterName(int allocation_index); | 499 const char* RegisterName(int allocation_index); |
| 491 | 500 |
| 492 Instruction* InstructionAt(int index) { return code()->InstructionAt(index); } | 501 Instruction* InstructionAt(int index) { return code()->InstructionAt(index); } |
| 493 | 502 |
| 494 Frame* frame() const { return frame_; } | 503 Frame* frame() const { return frame_; } |
| 495 const char* debug_name() const { return debug_name_; } | 504 const char* debug_name() const { return debug_name_; } |
| 505 const Config& config() const { return config_; } | |
| 496 | 506 |
| 497 Zone* const zone_; | 507 Zone* const zone_; |
| 498 Frame* const frame_; | 508 Frame* const frame_; |
| 499 InstructionSequence* const code_; | 509 InstructionSequence* const code_; |
| 500 const char* const debug_name_; | 510 const char* const debug_name_; |
| 501 | 511 |
| 512 const Config config_; | |
| 513 | |
| 502 // During liveness analysis keep a mapping from block id to live_in sets | 514 // During liveness analysis keep a mapping from block id to live_in sets |
| 503 // for blocks already analyzed. | 515 // for blocks already analyzed. |
| 504 ZoneList<BitVector*> live_in_sets_; | 516 ZoneList<BitVector*> live_in_sets_; |
| 505 | 517 |
| 506 // Liveness analysis results. | 518 // Liveness analysis results. |
| 507 ZoneList<LiveRange*> live_ranges_; | 519 ZoneList<LiveRange*> live_ranges_; |
| 508 | 520 |
| 509 // Lists of live ranges | 521 // Lists of live ranges |
| 510 EmbeddedVector<LiveRange*, Register::kMaxNumAllocatableRegisters> | 522 ZoneVector<LiveRange*> fixed_live_ranges_; |
| 511 fixed_live_ranges_; | 523 ZoneVector<LiveRange*> fixed_double_live_ranges_; |
| 512 EmbeddedVector<LiveRange*, DoubleRegister::kMaxNumAllocatableRegisters> | |
| 513 fixed_double_live_ranges_; | |
| 514 ZoneList<LiveRange*> unhandled_live_ranges_; | 524 ZoneList<LiveRange*> unhandled_live_ranges_; |
| 515 ZoneList<LiveRange*> active_live_ranges_; | 525 ZoneList<LiveRange*> active_live_ranges_; |
| 516 ZoneList<LiveRange*> inactive_live_ranges_; | 526 ZoneList<LiveRange*> inactive_live_ranges_; |
| 517 ZoneList<LiveRange*> reusable_slots_; | 527 ZoneList<LiveRange*> reusable_slots_; |
| 518 | 528 |
| 519 RegisterKind mode_; | 529 RegisterKind mode_; |
| 520 int num_registers_; | 530 int num_registers_; |
| 521 | 531 |
| 522 BitVector* assigned_registers_; | 532 BitVector* assigned_registers_; |
| 523 BitVector* assigned_double_registers_; | 533 BitVector* assigned_double_registers_; |
| 524 | 534 |
| 525 // Indicates success or failure during register allocation. | 535 // Indicates success or failure during register allocation. |
| 526 bool allocation_ok_; | 536 bool allocation_ok_; |
| 527 | 537 |
| 528 #ifdef DEBUG | 538 #ifdef DEBUG |
| 529 LifetimePosition allocation_finger_; | 539 LifetimePosition allocation_finger_; |
| 530 #endif | 540 #endif |
| 531 | 541 |
| 532 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 542 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
| 533 }; | 543 }; |
| 534 | 544 |
| 535 } | 545 } |
| 536 } | 546 } |
| 537 } // namespace v8::internal::compiler | 547 } // namespace v8::internal::compiler |
| 538 | 548 |
| 539 #endif // V8_REGISTER_ALLOCATOR_H_ | 549 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |