| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int count(Register reg) const { return count(reg.code()); } | 142 int count(Register reg) const { return count(reg.code()); } |
| 143 | 143 |
| 144 // Record a use of a register by incrementing its reference count. | 144 // Record a use of a register by incrementing its reference count. |
| 145 void Use(Register reg) { | 145 void Use(Register reg) { |
| 146 ref_counts_[reg.code()]++; | 146 ref_counts_[reg.code()]++; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Record that a register will no longer be used by decrementing its | 149 // Record that a register will no longer be used by decrementing its |
| 150 // reference count. | 150 // reference count. |
| 151 void Unuse(Register reg) { | 151 void Unuse(Register reg) { |
| 152 ASSERT(!reg.is(no_reg)); |
| 152 ASSERT(is_used(reg.code())); | 153 ASSERT(is_used(reg.code())); |
| 153 if (is_used(reg.code())) { | 154 ref_counts_[reg.code()]--; |
| 154 ref_counts_[reg.code()]--; | |
| 155 } | |
| 156 } | 155 } |
| 157 | 156 |
| 158 // Copy the reference counts from this register file to the other. | 157 // Copy the reference counts from this register file to the other. |
| 159 void CopyTo(RegisterFile* other); | 158 void CopyTo(RegisterFile* other); |
| 160 | 159 |
| 161 private: | 160 private: |
| 162 int ref_counts_[kNumRegisters]; | 161 int ref_counts_[kNumRegisters]; |
| 163 | 162 |
| 163 // Very fast inlined loop to find a free register. |
| 164 // Used in RegisterAllocator::AllocateWithoutSpilling. |
| 165 // Returns kNumRegisters if no free register found. |
| 166 inline int ScanForFreeRegister() { |
| 167 int i = 0; |
| 168 for (; i < kNumRegisters ; ++i ) { |
| 169 if (ref_counts_[i] == 0) break; |
| 170 } |
| 171 return i; |
| 172 } |
| 173 |
| 164 friend class RegisterAllocator; | 174 friend class RegisterAllocator; |
| 165 }; | 175 }; |
| 166 | 176 |
| 167 | 177 |
| 168 // ------------------------------------------------------------------------- | 178 // ------------------------------------------------------------------------- |
| 169 // Register allocator | 179 // Register allocator |
| 170 // | 180 // |
| 171 | 181 |
| 172 class RegisterAllocator BASE_EMBEDDED { | 182 class RegisterAllocator BASE_EMBEDDED { |
| 173 public: | 183 public: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 238 } |
| 229 | 239 |
| 230 private: | 240 private: |
| 231 CodeGenerator* cgen_; | 241 CodeGenerator* cgen_; |
| 232 RegisterFile registers_; | 242 RegisterFile registers_; |
| 233 }; | 243 }; |
| 234 | 244 |
| 235 } } // namespace v8::internal | 245 } } // namespace v8::internal |
| 236 | 246 |
| 237 #endif // V8_REGISTER_ALLOCATOR_H_ | 247 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |