| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #ifndef V8_REGISTER_ALLOCATOR_IA32_H_ |
| 29 #define V8_REGISTER_ALLOCATOR_IA32_H_ |
| 30 |
| 31 #include "macro-assembler.h" |
| 32 |
| 33 namespace v8 { namespace internal { |
| 34 |
| 35 // ------------------------------------------------------------------------- |
| 36 // Register file |
| 37 // |
| 38 // The register file tracks reference counts for the processor registers. |
| 39 // It is used by both the register allocator and the virtual frame. |
| 40 |
| 41 class RegisterFile BASE_EMBEDDED { |
| 42 public: |
| 43 RegisterFile() { Reset(); } |
| 44 |
| 45 void Reset() { |
| 46 for (int i = 0; i < kNumRegisters; i++) { |
| 47 ref_counts_[i] = 0; |
| 48 } |
| 49 } |
| 50 |
| 51 // Predicates and accessors for the reference counts. They take a |
| 52 // register code rather than a register because they are frequently used |
| 53 // in a loop over the register codes. |
| 54 bool is_used(int reg_code) const { return ref_counts_[reg_code] > 0; } |
| 55 int count(int reg_code) const { return ref_counts_[reg_code]; } |
| 56 |
| 57 // Record a use of a register by incrementing its reference count. |
| 58 void Use(Register reg) { |
| 59 ref_counts_[reg.code()]++; |
| 60 } |
| 61 |
| 62 // Record that a register will no longer be used by decrementing its |
| 63 // reference count. |
| 64 void Unuse(Register reg) { |
| 65 ASSERT(is_used(reg.code())); |
| 66 if (is_used(reg.code())) { |
| 67 ref_counts_[reg.code()]--; |
| 68 } |
| 69 } |
| 70 |
| 71 static const int kNumRegisters = 8; |
| 72 |
| 73 private: |
| 74 int ref_counts_[kNumRegisters]; |
| 75 }; |
| 76 |
| 77 |
| 78 // ------------------------------------------------------------------------- |
| 79 // Register allocator |
| 80 // |
| 81 |
| 82 class RegisterAllocator BASE_EMBEDDED { |
| 83 public: |
| 84 RegisterAllocator(CodeGenerator* cgen) : code_generator_(cgen) {} |
| 85 |
| 86 int num_registers() const { return RegisterFile::kNumRegisters; } |
| 87 |
| 88 int count(int reg_code) { return registers_.count(reg_code); } |
| 89 |
| 90 // Explicitly record a reference to a register. |
| 91 void Use(Register reg) { registers_.Use(reg); } |
| 92 |
| 93 // Explicitly record that a register will no lonber be used. |
| 94 void Unuse(Register reg) { registers_.Unuse(reg); } |
| 95 |
| 96 // Initialize the register allocator for entry to a JS function. On |
| 97 // entry, esp, ebp, esi, and edi are externally referenced (ie, outside |
| 98 // the virtual frame); and the other registers are free. |
| 99 void Initialize(); |
| 100 |
| 101 // Allocate a free register if possible or fail by returning no_reg. |
| 102 Register Allocate(); |
| 103 |
| 104 private: |
| 105 CodeGenerator* code_generator_; |
| 106 RegisterFile registers_; |
| 107 }; |
| 108 |
| 109 } } // namespace v8::internal |
| 110 |
| 111 #endif // V8_REGISTER_ALLOCATOR_IA32_H_ |
| OLD | NEW |